Annotation of MiNT/src/dossig.c, revision 1.1.1.2

1.1       root        1: /*
                      2: 
                      3: Copyright 1990,1991,1992 Eric R. Smith. All rights reserved.
                      4: 
                      5: */
                      6: 
                      7: 
                      8: 
                      9: /* dossig.c:: dos signal handling routines */
                     10: 
                     11: 
                     12: 
                     13: #include "mint.h"
                     14: 
                     15: 
                     16: 
                     17: /*
                     18: 
                     19:  * send a signal to another process. If pid > 0, send the signal just to
                     20: 
                     21:  * that process. If pid < 0, send the signal to all processes whose process
                     22: 
                     23:  * group is -pid. If pid == 0, send the signal to all processes with the
                     24: 
                     25:  * same process group id.
                     26: 
                     27:  *
                     28: 
                     29:  * note: post_sig just posts the signal to the process.
                     30: 
                     31:  */
                     32: 
                     33: 
                     34: 
1.1.1.2 ! root       35: long ARGS_ON_STACK
1.1       root       36: 
                     37: p_kill(pid, sig)
                     38: 
                     39:        int pid, sig;
                     40: 
                     41: {
                     42: 
                     43:        PROC *p;
                     44: 
                     45: 
                     46: 
1.1.1.2 ! root       47:        TRACE(("Pkill(%d, %d)", pid, sig));
1.1       root       48: 
                     49:        if (sig < 0 || sig >= NSIG) {
                     50: 
1.1.1.2 ! root       51:                DEBUG(("Pkill: signal out of range"));
1.1       root       52: 
                     53:                return ERANGE;
                     54: 
                     55:        }
                     56: 
                     57: 
                     58: 
                     59:        if (pid < 0)
                     60: 
                     61:                return killgroup(-pid, sig);
                     62: 
                     63:        else if (pid == 0)
                     64: 
                     65:                return killgroup(curproc->pgrp, sig);
                     66: 
                     67:        else {
                     68: 
                     69:                p = pid2proc(pid);
                     70: 
                     71:                if (p == 0 || p->wait_q == ZOMBIE_Q || p->wait_q == TSR_Q) {
                     72: 
1.1.1.2 ! root       73:                        DEBUG(("Pkill: pid %d not found", pid));
1.1       root       74: 
                     75:                        return EFILNF;
                     76: 
                     77:                }
                     78: 
                     79:                if (curproc->euid && curproc->ruid != p->ruid) {
                     80: 
1.1.1.2 ! root       81:                        DEBUG(("Pkill: wrong user"));
1.1       root       82: 
                     83:                        return EACCDN;
                     84: 
                     85:                }
                     86: 
                     87: 
                     88: 
                     89: /* if the user sends signal 0, don't deliver it -- for users, signal
                     90: 
                     91:  * 0 is a null signal used to test the existence of a process
                     92: 
                     93:  */
                     94: 
                     95:                if (sig != 0)
                     96: 
                     97:                        post_sig(p, sig);
                     98: 
                     99:        }
                    100: 
                    101: 
                    102: 
                    103:        check_sigs();
                    104: 
1.1.1.2 ! root      105:        TRACE(("Pkill: returning OK"));
1.1       root      106: 
                    107:        return 0;
                    108: 
                    109: }
                    110: 
                    111: 
                    112: 
                    113: /*
                    114: 
                    115:  * set a user-specified signal handler, POSIX.1 style
                    116: 
                    117:  * "oact", if non-null, gets the old signal handling
                    118: 
                    119:  * behaviour; "act", if non-null, specifies new
                    120: 
                    121:  * behaviour
                    122: 
                    123:  */
                    124: 
                    125: 
                    126: 
1.1.1.2 ! root      127: long ARGS_ON_STACK
1.1       root      128: 
                    129: p_sigaction(sig, act, oact)
                    130: 
                    131:        int sig;
                    132: 
                    133:        const struct sigaction *act;
                    134: 
                    135:        struct sigaction *oact;
                    136: 
                    137: {
                    138: 
1.1.1.2 ! root      139:        TRACE(("Psigaction(%d)", sig));
1.1       root      140: 
                    141:        if (sig < 1 || sig >= NSIG)
                    142: 
                    143:                return ERANGE;
                    144: 
                    145:        if (act && (sig == SIGKILL || sig == SIGSTOP))
                    146: 
                    147:                return EACCDN;
                    148: 
                    149:        if (oact) {
                    150: 
                    151:                oact->sa_handler = curproc->sighandle[sig];
                    152: 
                    153:                oact->sa_mask = curproc->sigextra[sig];
                    154: 
1.1.1.2 ! root      155:                oact->sa_flags = curproc->sigflags[sig] & SAUSER;
1.1       root      156: 
                    157:        }
                    158: 
                    159:        if (act) {
                    160: 
1.1.1.2 ! root      161:                ushort flags;
        !           162: 
        !           163: 
        !           164: 
1.1       root      165:                curproc->sighandle[sig] = act->sa_handler;
                    166: 
                    167:                curproc->sigextra[sig] = act->sa_mask & ~UNMASKABLE;
                    168: 
1.1.1.2 ! root      169: 
        !           170: 
        !           171: /* only the flags in SAUSER can be changed by the user */
        !           172: 
        !           173:                flags = curproc->sigflags[sig] & ~SAUSER;
        !           174: 
        !           175:                flags |= act->sa_flags & SAUSER;
        !           176: 
        !           177:                curproc->sigflags[sig] = flags;
1.1       root      178: 
                    179:  
                    180: 
                    181: /* various special things that should happen */
                    182: 
                    183:                if (act->sa_handler == SIG_IGN) {
                    184: 
                    185:                        /* discard pending signals */
                    186: 
                    187:                        curproc->sigpending &= ~(1L<<sig);
                    188: 
                    189:                }
                    190: 
                    191: 
                    192: 
                    193: /* I dunno if this is right, but bash seems to expect it */
                    194: 
                    195:                curproc->sigmask &= ~(1L<<sig);
                    196: 
                    197:        }
                    198: 
                    199:        return 0;
                    200: 
                    201: }
                    202: 
                    203: 
                    204: 
                    205: /*
                    206: 
                    207:  * set a user-specified signal handler
                    208: 
                    209:  */
                    210: 
                    211: 
                    212: 
1.1.1.2 ! root      213: long ARGS_ON_STACK
1.1       root      214: 
                    215: p_signal(sig, handler)
                    216: 
                    217:        int sig;
                    218: 
                    219:        long handler;
                    220: 
                    221: {
                    222: 
                    223:        long oldhandle;
                    224: 
                    225: 
                    226: 
1.1.1.2 ! root      227:        TRACE(("Psignal(%d, %lx)", sig, handler));
1.1       root      228: 
                    229:        if (sig < 1 || sig >= NSIG)
                    230: 
                    231:                return ERANGE;
                    232: 
                    233:        if (sig == SIGKILL || sig == SIGSTOP)
                    234: 
                    235:                return EACCDN;
                    236: 
                    237:        oldhandle = curproc->sighandle[sig];
                    238: 
                    239:        curproc->sighandle[sig] = handler;
                    240: 
                    241:        curproc->sigextra[sig] = 0;
                    242: 
                    243:        curproc->sigflags[sig] = 0;
                    244: 
                    245: 
                    246: 
                    247: /* various special things that should happen */
                    248: 
                    249:        if (handler == SIG_IGN) {
                    250: 
                    251:                /* discard pending signals */
                    252: 
                    253:                curproc->sigpending &= ~(1L<<sig);
                    254: 
                    255:        }
                    256: 
                    257: 
                    258: 
                    259: /* I dunno if this is right, but bash seems to expect it */
                    260: 
                    261:        curproc->sigmask &= ~(1L<<sig);
                    262: 
                    263: 
                    264: 
                    265:        return oldhandle;
                    266: 
                    267: }
                    268: 
                    269: 
                    270: 
                    271: /*
                    272: 
                    273:  * block some signals. Returns the old signal mask.
                    274: 
                    275:  */
                    276: 
                    277: 
                    278: 
1.1.1.2 ! root      279: long ARGS_ON_STACK
1.1       root      280: 
                    281: p_sigblock(mask)
                    282: 
                    283:        ulong mask;
                    284: 
                    285: {
                    286: 
                    287:        ulong oldmask;
                    288: 
                    289: 
                    290: 
1.1.1.2 ! root      291:        TRACE(("Psigblock(%lx)",mask));
1.1       root      292: 
                    293: /* some signals (e.g. SIGKILL) can't be masked */
                    294: 
                    295:        mask &= ~(UNMASKABLE);
                    296: 
                    297:        oldmask = curproc->sigmask;
                    298: 
                    299:        curproc->sigmask |= mask;
                    300: 
                    301:        return oldmask;
                    302: 
                    303: }
                    304: 
                    305: 
                    306: 
                    307: /*
                    308: 
                    309:  * set the signals that we're blocking. Some signals (e.g. SIGKILL)
                    310: 
                    311:  * can't be masked.
                    312: 
                    313:  * Returns the old mask.
                    314: 
                    315:  */
                    316: 
                    317: 
                    318: 
1.1.1.2 ! root      319: long ARGS_ON_STACK
1.1       root      320: 
                    321: p_sigsetmask(mask)
                    322: 
                    323:        ulong mask;
                    324: 
                    325: {
                    326: 
                    327:        ulong oldmask;
                    328: 
                    329: 
                    330: 
1.1.1.2 ! root      331:        TRACE(("Psigsetmask(%lx)",mask));
1.1       root      332: 
                    333:        oldmask = curproc->sigmask;
                    334: 
                    335:        curproc->sigmask = mask & ~(UNMASKABLE);
                    336: 
                    337:        check_sigs();   /* maybe we unmasked something */
                    338: 
                    339:        return oldmask;
                    340: 
                    341: }
                    342: 
                    343: 
                    344: 
                    345: /*
                    346: 
                    347:  * p_sigpending: return which signals are pending delivery
                    348: 
                    349:  */
                    350: 
                    351: 
                    352: 
1.1.1.2 ! root      353: long ARGS_ON_STACK
1.1       root      354: 
                    355: p_sigpending()
                    356: 
                    357: {
                    358: 
1.1.1.2 ! root      359:        TRACE(("Psigpending()"));
1.1       root      360: 
                    361:        check_sigs();   /* clear out any that are going to be delivered soon */
                    362: 
1.1.1.2 ! root      363: 
        !           364: 
        !           365: /* note that signal #0 is used internally, so we don't tell the process
        !           366: 
        !           367:  * about it
        !           368: 
        !           369:  */
        !           370: 
        !           371:        return curproc->sigpending & ~1L;
1.1       root      372: 
                    373: }
                    374: 
                    375: 
                    376: 
                    377: /*
                    378: 
                    379:  * p_sigpause: atomically set the signals that we're blocking, then pause.
                    380: 
                    381:  * Some signals (e.g. SIGKILL) can't be masked.
                    382: 
                    383:  */
                    384: 
                    385: 
                    386: 
1.1.1.2 ! root      387: long ARGS_ON_STACK
1.1       root      388: 
                    389: p_sigpause(mask)
                    390: 
                    391:        ulong mask;
                    392: 
                    393: {
                    394: 
                    395:        ulong oldmask;
                    396: 
                    397: 
                    398: 
1.1.1.2 ! root      399:        TRACE(("Psigpause(%lx)", mask));
1.1       root      400: 
                    401:        oldmask = curproc->sigmask;
                    402: 
                    403:        curproc->sigmask = mask & ~(UNMASKABLE);
                    404: 
                    405:        if (curproc->sigpending & ~(curproc->sigmask))
                    406: 
                    407:                check_sigs();   /* a signal is immediately pending */
                    408: 
                    409:        else
                    410: 
                    411:                sleep(IO_Q, -1L);
                    412: 
                    413:        curproc->sigmask = oldmask;
                    414: 
                    415:        check_sigs();   /* maybe we unmasked something */
                    416: 
1.1.1.2 ! root      417:        TRACE(("Psigpause: returning OK"));
1.1       root      418: 
                    419:        return 0;
                    420: 
                    421: }
                    422: 

unix.superglobalmegacorp.com

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