Annotation of researchv9/jtools/src/pi/sigmask.c, revision 1.1

1.1     ! root        1: #include "hostcore.h"
        !             2: #include "process.pri"
        !             3: #include "srctext.pub"
        !             4: #include "sigmask.h"
        !             5: SRCFILE("sigmask.c")
        !             6: 
        !             7: char *SignalName(int sig)
        !             8: {
        !             9:        switch( sig ){
        !            10:                case 0:         return "0 (no signal)";
        !            11:                case SIGHUP:    return "hangup";
        !            12:                case SIGINT:    return "interrupt";
        !            13:                case SIGQUIT:   return "quit";
        !            14:                case SIGILL:    return "illegal instruction";
        !            15:                case SIGTRAP:   return "trace/BPT";
        !            16:                case SIGIOT:    return "IOT instruction";
        !            17:                case SIGEMT:    return "EMT instruction";
        !            18:                case SIGFPE:    return "floating exception";
        !            19:                case SIGKILL:   return "kill";
        !            20:                case SIGBUS:    return "bus error";
        !            21:                case SIGSEGV:   return "memory fault";
        !            22:                case SIGSYS:    return "bad system call";
        !            23:                case SIGPIPE:   return "broken pipe";
        !            24:                case SIGALRM:   return "alarm call";
        !            25:                case SIGTERM:   return "terminated";
        !            26:                case SIGSTOP:   return "stop";
        !            27:                case SIGCONT:   return "continue";
        !            28:                case SIGTSTP:   return "stop tty";
        !            29:                case SIGCHLD:   return "child termination";
        !            30:                case SIGTTIN:   return "stop tty input";
        !            31:                case SIGTTOU:   return "stop tty output";
        !            32:                case SIGXCPU:   return "cpu timelimit";
        !            33:                case SIGXFSZ:   return "file sizelimit";
        !            34: #ifdef V9
        !            35:                case SIGTINT:   return "input available";
        !            36: #else
        !            37:                case SIGIO:     return "i/o possible";
        !            38:                case SIGURG:    return "urgent condition";
        !            39:                case SIGVTALRM: return "virtual alarm";
        !            40:                case SIGPROF:   return "profiling alarm";
        !            41:                case SIGWINCH:  return "window changed";
        !            42: #endif
        !            43:        }
        !            44:        return Name( "signal %d", sig );
        !            45: }
        !            46: 
        !            47: void SigMask::banner()
        !            48: {
        !            49:        trace( "%d.banner()", this );   VOK;
        !            50:        if( pad ){
        !            51:                pad->banner( "Signals: %s", core->procpath() );
        !            52:                pad->name( "Signals" );
        !            53:        }
        !            54: }
        !            55: 
        !            56: SigMask::SigMask(HostCore *c)
        !            57: {
        !            58:        trace( "%d.SigMask(%d)", this, c );     VOK;
        !            59:        core = c;
        !            60:        pad = 0;
        !            61:        mask =   bit(SIGILL)
        !            62:                |bit(SIGINT)
        !            63:                |bit(SIGTRAP)
        !            64:                |bit(SIGIOT)
        !            65:                |bit(SIGEMT)
        !            66:                |bit(SIGFPE)
        !            67:                |bit(SIGBUS)
        !            68:                |bit(SIGSEGV)
        !            69:                |bit(SIGSYS)
        !            70:                |bit(SIGPIPE)
        !            71:                |bit(SIGSTOP);
        !            72: #ifdef V9
        !            73:        exechang = 0;
        !            74: #else
        !            75:        exechang = 1;
        !            76: #endif
        !            77:        updatecore();
        !            78: }
        !            79: 
        !            80: const long EXECKEY = 33;
        !            81: 
        !            82: void SigMask::open()
        !            83: {
        !            84:        Menu m;
        !            85:        int i;
        !            86:        trace( "%d.open()", this );     VOK;
        !            87:        if( !pad ){
        !            88:                pad = new Pad( (PadRcv*) this );
        !            89: #ifdef V9
        !            90:                pad->lines(EXECKEY);
        !            91: #endif
        !            92:                banner();
        !            93:                m.last( "clear pending signal", (Action)&SigMask::clrcurrsig, 0 );
        !            94:                m.last( "clear pending and go", (Action)&SigMask::clrcurrsig, 1 );
        !            95:                pad->menu(m);
        !            96:                pad->options(TRUNCATE);
        !            97: #ifdef V9
        !            98:                for( i = 1; i <= EXECKEY; ++i ) linereq( i, 0 );
        !            99: #else
        !           100:                for( i = 1; i <= EXECKEY-1; ++i ) linereq( i, 0 );
        !           101: #endif
        !           102:        }
        !           103:        pad->makecurrent();
        !           104: }
        !           105: 
        !           106: void SigMask::updatecore(char *error)
        !           107: {
        !           108:        if( !error ) error = core->exechang(exechang);
        !           109:        if( !error ) error = core->signalmask(mask);
        !           110:        core->process()->pad->error(error);
        !           111: }
        !           112: 
        !           113: void SigMask::execline(long e)
        !           114: {
        !           115:        static char *i[] = { "clear", "hang" };
        !           116:        static char *l[] = { "", ">>> " };
        !           117:        Menu m;
        !           118:        trace( "%d.execline(%d,ox%X)", this, e, a );            VOK;
        !           119:        exechang = e &= 1;
        !           120:        updatecore();
        !           121:        long comp = e^1;
        !           122:        m.last( i[comp], (Action) &SigMask::execline, comp );
        !           123:        Attrib a = 0;
        !           124:        pad->insert( EXECKEY, a, (PadRcv*)this, m, "%sexec()", l[e] );
        !           125: }
        !           126: 
        !           127: void SigBit::set(SigMask *s)           { s->setsig(bit); }
        !           128: void SigBit::clr(SigMask *s)           { s->clrsig(bit); }
        !           129: void SigBit::send(SigMask *s)          { s->sendsig(bit); }
        !           130: 
        !           131: void SigMask::linereq(long sig, Attrib a )
        !           132: {
        !           133:        Menu m;
        !           134:        static SigBit *sigbit;
        !           135:        if( !sigbit )
        !           136:                sigbit = new SigBit[33];
        !           137:        trace( "%d.linereq(%d,0x%X)", this, sig, a );   VOK;
        !           138:        if( sig == EXECKEY ){
        !           139:                execline(exechang);
        !           140:                return;
        !           141:        }
        !           142:        char *on = mask&bit(sig) ? ">>> " : "";
        !           143:        m.last( "send signal", (Action)&SigBit::send, (long)this );
        !           144:        if( on[0] == '>' )
        !           145:                m.first("trace off", (Action)&SigBit::clr, (long)this);
        !           146:        else
        !           147:                m.first("trace on",  (Action)&SigBit::set, (long)this);
        !           148:        sigbit[sig].bit = sig;
        !           149:        pad->insert(sig, a, (PadRcv*)(sigbit+sig), m, "%s%s", on, SignalName(sig));
        !           150: }
        !           151: 
        !           152: void SigMask::signalmask(long sig)
        !           153: {
        !           154:        trace( "%d.signalmask(%d)", this, sig );        VOK;
        !           155:        linereq(sig, SELECTLINE);
        !           156:        updatecore();
        !           157: }
        !           158: 
        !           159: void SigMask::sendsig(long sig)
        !           160: {
        !           161:        trace( "%d.sendsig(%d)", this, sig );   VOK;
        !           162:        updatecore(core->sendsig(sig));
        !           163: }
        !           164: 
        !           165: void SigMask::setsig(long sig)
        !           166: {
        !           167:        trace( "%d.setsig(%d)", this, sig );    VOK;
        !           168:        mask |= bit(sig);
        !           169:        signalmask( sig );
        !           170: }
        !           171: 
        !           172: void SigMask::clrsig(long sig)
        !           173: {
        !           174:        trace( "%d.clrsig(%d)", this, sig );    VOK;
        !           175:        mask &= ~bit(sig);
        !           176:        if( sig==SIGSTOP || sig==SIGTRAP )
        !           177:                updatecore( "warning: debugging signal disabled" );
        !           178:        signalmask( sig );
        !           179: }
        !           180: 
        !           181: void SigMask::hostclose()
        !           182: {
        !           183:        trace( "%d.hostclose()", this );        VOK;
        !           184:        if( pad ){
        !           185:                delete pad;
        !           186:                pad = 0;
        !           187:        }
        !           188: }
        !           189: 
        !           190: void SigMask::clrcurrsig(long andgo)
        !           191: {
        !           192:        trace( "%d.clrcurrsig()", this );       VOK;
        !           193:        updatecore(core->clrcurrsig());
        !           194:        if( andgo ) core->process()->go();
        !           195:        else core->process()->cycle();
        !           196: }

unix.superglobalmegacorp.com

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