Annotation of researchv9/jtools/src/pi/hostmaster.c, revision 1.1.1.1

1.1       root        1: #include "hostcore.h"
                      2: #include "master.pri"
                      3: #include "process.pri"
                      4: #include <CC/stdio.h>
                      5: #include "symtab.pri"
                      6: SRCFILE("hostmaster.c")
                      7: 
                      8: Process        *HostMaster::domakeproc(char *p, char *s, char* c)
                      9: {
                     10:        return (Process*) new HostProcess(child, p, s, c);
                     11: }
                     12: 
                     13: extern char *UNIX;
                     14: 
                     15: HostMaster::HostMaster()
                     16: {
                     17:        static char *ps[] = {
                     18:                "/bin/ps  ",
                     19:                "/bin/ps a",
                     20:                "/bin/ps x",
                     21:        0 };
                     22:        Menu m;
                     23:        int i;
                     24: 
                     25:        pad = new Pad( (PadRcv*) this );                /* this code cannot */
                     26:        pad->options(TRUNCATE|SORTED);                  /* be in base ctor */
                     27:        pad->name( "pi" );
                     28:        pad->banner( "pi = 3.141592653" ); // 3.141592653 589793
                     29:        for( i = 0; ps[i]; ++i )
                     30:                m.last( ps[i], (Action)&HostMaster::refresh, (long)ps[i] );
                     31:        m.last("kernel pi", (Action)&HostMaster::kpi);
                     32:        m.last("quit?", (Action)&HostMaster::exit, 0);
                     33:        pad->menu(m);
                     34:        pad->makecurrent();
                     35:        if( UNIX ){
                     36:                Process *p = (Process*) new HostProcess(0, 0, UNIX);
                     37:                core = new HostCore(p, this);
                     38:                pad->insert(1, FLUSHLINE, "Checking %s symbols ...", UNIX );
                     39:                char *error = core->open();
                     40:                if( error )
                     41:                        pad->insert(1, "%s: %s", UNIX, error);
                     42:                else {
                     43:                        error = core->symtab()->warn();
                     44:                        pad->insert(1, "%s", error ? error : "" );
                     45:                }
                     46:        }
                     47:        refresh(0);
                     48: }
                     49: 
                     50: void HostMaster::exit() { ::exit(0); }
                     51: 
                     52: void HostMaster::kpi()
                     53: {
                     54:        if( !kernmaster ) kernmaster = new KernMaster(core->_symtab);
                     55:        kernmaster->pad->makecurrent();
                     56: }
                     57: 
                     58: #define PSOUT 100
                     59: #define PROCS 100
                     60: char *HostMaster::dopscmd(char *ps)
                     61: {
                     62:        char psout[PROCS][PSOUT];
                     63:        FILE *f, *Popen(char*,char*);
                     64:        int Pclose(FILE *);
                     65:        void qsort(char*,int,int,int(*)(char*,char*));
                     66:        int pid, i, j, e;
                     67: 
                     68:        if( !ps ) return 0;
                     69:        if( !(f = Popen( ps, "r")) )
                     70:                return SysErr( "cannot read from popen(): " );
                     71:        for( i = 0; i<PROCS && fgets(psout[i],PSOUT,f); ++i ) {}
                     72:        if( e = Pclose(f) )
                     73:                return sf( "exit(%d): %s", e, ps );
                     74:        qsort( &psout[0][0], i, PSOUT, strcmp );
                     75:        for( j = 0; j <= i; ++j )
                     76:                if( 2 == sscanf( psout[j], " %d %[^\n]", &pid, psout[0] ) )
                     77:                        makeproc( sf("%d",pid), 0, psout[0] );
                     78:        return 0;
                     79: }
                     80: 
                     81: void HostMaster::refresh(char *ps)
                     82: {
                     83:        char *error;
                     84:        Process *p;
                     85: 
                     86:        pad->clear();
                     87:        makeproc( "core", "a.out", "" );
                     88:        makeproc( "!", "a.out", "" );
                     89:        if( error = dopscmd(ps) ) pad->error(error);
                     90:        for( p = child; p; p = p->sibling )
                     91:                if( p->core || (p->stabpath && !strcmp(p->stabpath,"!")))
                     92:                        insert(p);
                     93: }
                     94: 
                     95: char *HostMaster::kbd(char *s)
                     96: {
                     97:        char *corep, core[64], syms[64], star = 0;
                     98:        HostProcess *p;
                     99:        void StartAudit();
                    100: 
                    101:        while( *s == ' ' ) ++s;
                    102:        if( !strcmp(s, "new Audit") ){
                    103:                StartAudit();
                    104:                return 0;
                    105:        }
                    106:        while( *s==' ' ) ++s;
                    107:        switch( *s ){
                    108:        case '!':
                    109:                for( ++s; *s==' '; ++s ) {}
                    110:                makeproc("!", s, "");
                    111:                break;
                    112:        case '*':
                    113:                star = 1;
                    114:                for( ++s; *s==' '; ++s ) {}
                    115:        default:
                    116:                switch( sscanf(s, "%s %s \n", corep = core, syms) ){
                    117:                case 2: if( alldigits(corep) )
                    118:                                corep = sf( "%s", core );
                    119:                        p = (HostProcess*) makeproc(corep, syms[0]?syms:0, 0);
                    120:                        if( star && p ) p->open();
                    121:                        break;
                    122:                default:
                    123:                return help();
                    124:                }
                    125:        }
                    126:        return 0;
                    127: }
                    128: 
                    129: char *HostMaster::help()
                    130: {
                    131:        return "[*] <corepath | pid> <tables> {[open] process/dump} | !<cmd> {program}";
                    132: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.