Annotation of researchv9/jtools/src/pi/v9master.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 pid, i, j, e;
                     65: 
                     66:        if( !ps ) return 0;
                     67:        if( !(f = Popen( ps, "r")) )
                     68:                return SysErr( "cannot read from popen(): " );
                     69:        for( i = 0; i<PROCS && fgets(psout[i],PSOUT,f); ++i ) {}
                     70:        if( e = Pclose(f) )
                     71:                return sf( "exit(%d): %s", e, ps );
                     72:        qsort( psout, i, PSOUT, strcmp );
                     73:        for( j = 0; j <= i; ++j )
                     74:                if( 2 == sscanf( psout[j], " %d %[^\n]", &pid, psout[0] ) )
                     75:                        makeproc( sf("/proc/%d",pid), 0, psout[0] );
                     76:        return 0;
                     77: }
                     78: 
                     79: void HostMaster::refresh(char *ps)
                     80: {
                     81:        char *error;
                     82:        Process *p;
                     83: 
                     84:        pad->clear();
                     85:        makeproc( "core", "a.out", "" );
                     86:        makeproc( "!", "a.out", "" );
                     87:        if( error = dopscmd(ps) ) pad->error(error);
                     88:        for( p = child; p; p = p->sibling )
                     89:                if( p->core || (p->stabpath && !strcmp(p->stabpath,"!")))
                     90:                        insert(p);
                     91: }
                     92: 
                     93: char *HostMaster::kbd(char *s)
                     94: {
                     95:        char *corep, core[64], syms[64], star = 0;
                     96:        HostProcess *p;
                     97: 
                     98:        while( *s == ' ' ) ++s;
                     99:        if( !strcmp(s, "new Audit") ){
                    100:                StartAudit();
                    101:                return 0;
                    102:        }
                    103:        while( *s==' ' ) ++s;
                    104:        switch( *s ){
                    105:        case '!':
                    106:                for( ++s; *s==' '; ++s ) {}
                    107:                makeproc("!", s, "");
                    108:                break;
                    109:        case '*':
                    110:                star = 1;
                    111:                for( ++s; *s==' '; ++s ) {}
                    112:        default:
                    113:                switch( sscanf(s, "%s %s \n", corep = core, syms) ){
                    114:                case 1: syms[0] = '\0';
                    115:                case 2: if( alldigits(corep) )
                    116:                                corep = sf( "/proc/%s", core );
                    117:                        p = (HostProcess*) makeproc(corep, syms[0]?syms:0, 0);
                    118:                        if( star && p ) p->open();
                    119:                        break;
                    120:                default:
                    121:                return help();
                    122:                }
                    123:        }
                    124:        return 0;
                    125: }
                    126: 
                    127: char *HostMaster::help()
                    128: {
                    129:        return "[*] <path> [<tables>] {[open] process/dump} | !<cmd> {program}";
                    130: }

unix.superglobalmegacorp.com

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