VirtualBox

Changeset 1208 in kBuild for trunk/src/kash


Ignore:
Timestamp:
Oct 7, 2007 5:33:41 PM (17 years ago)
Author:
bird
Message:

trap.c ++.

Location:
trunk/src/kash
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/Makefile.kmk

    r1207 r1208  
    5252        bltin/test.c \
    5353        \
     54        trap.c \
    5455        parser.c \
    5556        redir.c \
    56         trap.c \
    5757        var.c \
    5858        bltin/kill.c \
  • trunk/src/kash/error.c

    r1207 r1208  
    119119                exraise(psh, EXINT);
    120120        else {
    121                 sh_signal(psh, SIGINT, SIG_DFL);
     121                sh_signal(psh, SIGINT, SH_SIG_DFL);
    122122                sh_raise_sigint(psh);/*raise(psh, SIGINT);*/
    123123        }
  • trunk/src/kash/generated/init.c

    r1203 r1208  
    302302
    303303              clear_traps(psh, 0);
    304               for (sm = sigmode ; sm < sigmode + NSIG ; sm++) {
     304              for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) {
    305305                      if (*sm == S_IGN)
    306306                              *sm = S_HARD_IGN;
  • trunk/src/kash/parser.c

    r1201 r1208  
    13861386                        ckfree(str);
    13871387                parsebackquote = 0;
    1388                 handler = savehandler;
    1389                 longjmp(handler->loc, 1);
     1388                psh->handler = savehandler;
     1389                longjmp(psh->handler->loc, 1);
    13901390        }
    13911391        INTOFF;
     
    13961396                memcpy(str, stackblock(psh), savelen);
    13971397        }
    1398         savehandler = handler;
    1399         handler = &jmploc;
     1398        savehandler = psh->handler;
     1399        psh->handler = &jmploc;
    14001400        INTON;
    14011401        if (oldstyle) {
     
    15041504        }
    15051505        parsebackquote = savepbq;
    1506         handler = savehandler;
     1506        psh->handler = savehandler;
    15071507        if (arinest || ISDBLQUOTE())
    15081508                USTPUTC(psh, CTLBACKQ | CTLQUOTE, out);
  • trunk/src/kash/redir.c

    r1207 r1208  
    6767#include "memalloc.h"
    6868#include "error.h"
     69#include "shinstance.h"
    6970
    7071
     
    273274        if (forkshell(psh, (struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) {
    274275                shfile_close(&psh->fdtab, pip[0]);
    275                 signal(SIGINT, SIG_IGN);
    276                 signal(SIGQUIT, SIG_IGN);
    277                 signal(SIGHUP, SIG_IGN);
     276                sh_signal(psh, SIGINT, SH_SIG_IGN);
     277                sh_signal(psh, SIGQUIT, SH_SIG_IGN);
     278                sh_signal(psh, SIGHUP, SH_SIG_IGN);
    278279#ifdef SIGTSTP
    279                 signal(SIGTSTP, SIG_IGN);
    280 #endif
    281                 signal(SIGPIPE, SIG_DFL);
     280                sh_signal(psh, SIGTSTP, SH_SIG_IGN);
     281#endif
     282                sh_signal(psh, SIGPIPE, SH_SIG_DFL);
    282283                if (redir->type == NHERE)
    283284                        xwrite(psh, pip[1], redir->nhere.doc->narg.text, len);
    284285                else
    285286                        expandhere(psh, redir->nhere.doc, pip[1]);
    286                 _exit(0);
     287                sh__exit(psh, 0);
    287288        }
    288289out:
  • trunk/src/kash/shinstance.h

    r1207 r1208  
    127127
    128128    /* trap.h */
    129     int                 pendingsigs;
     129    int                 pendingsigs;    /**< indicates some signal received */
     130
     131    /* trap.c */
     132    char                gotsig[NSIG];   /**< indicates specified signal received */
     133    char               *trap[NSIG+1];   /**< trap handler commands */
     134    char                sigmode[NSIG];  /**< current value of signal */
    130135
    131136    /* parse.h */
     
    277282    struct t_op const  *t_wp_op;
    278283
    279     /* trap.c */
    280     char                gotsig[NSIG];   /**< indicates specified signal received */
    281 
    282284} shinstance;
    283285
    284286
    285 extern shinstance *sh_create_root_shell(shinstance *inherit, int argc, char **argv);
     287extern shinstance *sh_create_root_shell(shinstance *, int, char **);
    286288char *sh_getenv(shinstance *, const char *);
    287289
    288290/* signals */
    289 #include <signal.h>
     291typedef void (*sh_sig_t)(shinstance *, int);
    290292#ifdef _MSC_VER
    291     typedef uint32_t sh_sigset_t;
     293 typedef uint32_t sh_sigset_t;
    292294#else
    293     typedef sigset_t sh_sigset_t;
    294 #endif
    295 
    296 typedef void (*sh_handler)(int);
    297 sh_handler sh_signal(shinstance *, int, sh_handler handler);
     295 typedef sigset_t sh_sigset_t;
     296#endif
     297struct sh_sigaction
     298{
     299    sh_sig_t    sh_handler;
     300    sh_sigset_t sh_mask;
     301    int         sh_flags;
     302};
     303#define SH_SIG_DFL ((sh_sig_t)SIG_DFL)
     304#define SH_SIG_IGN ((sh_sig_t)SIG_IGN)
     305
     306int sh_sigaction(int, const struct sh_sigaction *, struct sh_sigaction *);
     307sh_sig_t sh_signal(shinstance *, int, sh_sig_t);
    298308void sh_raise_sigint(shinstance *);
    299 void sh_sigemptyset(sh_sigset_t *set);
    300 int sh_sigprocmask(shinstance *, int op, sh_sigset_t const *new, sh_sigset_t *old);
     309void sh_sigemptyset(sh_sigset_t *);
     310int sh_sigprocmask(shinstance *, int, sh_sigset_t const *, sh_sigset_t *);
    301311void sh_abort(shinstance *);
    302312
  • trunk/src/kash/trap.c

    r1207 r1208  
    6262#include "mystring.h"
    6363#include "var.h"
     64#include "shinstance.h"
    6465
    6566#ifndef HAVE_SYS_SIGNAME
     
    8182
    8283
    83 char *trap[NSIG+1];             /* trap handler commands */
    84 MKINIT char sigmode[NSIG];      /* current value of signal */
    85 char gotsig[NSIG];              /* indicates specified signal received */
    86 int pendingsigs;                /* indicates some signal received */
    87 
    88 #ifdef __sun__
    89 typedef void (*sig_t) (int);
    90 #endif
    91 static int getsigaction(int, sig_t *);
     84//char *trap[NSIG+1];           /* trap handler commands */
     85//MKINIT char sigmode[NSIG];    /* current value of signal */
     86//char gotsig[NSIG];            /* indicates specified signal received */
     87//int pendingsigs;              /* indicates some signal received */
     88
     89static int getsigaction(shinstance *, int, sh_sig_t *);
    9290
    9391/*
     
    9795
    9896static int
    99 signame_to_signum(const char *p)
     97signame_to_signum(shinstance *psh, const char *p)
    10098{
    10199        int i;
     
    123121 */
    124122static void
    125 printsignals(void)
     123printsignals(shinstance *psh)
    126124{
    127125        int n;
     
    146144
    147145int
    148 trapcmd(int argc, char **argv)
     146trapcmd(shinstance *psh, int argc, char **argv)
    149147{
    150148        char *action;
     
    157155        if (argc <= 1) {
    158156                for (signo = 0 ; signo <= NSIG ; signo++)
    159                         if (trap[signo] != NULL) {
     157                        if (psh->trap[signo] != NULL) {
    160158                                out1fmt(psh, "trap -- ");
    161                                 print_quoted(psh, trap[signo]);
     159                                print_quoted(psh, psh->trap[signo]);
    162160                                out1fmt(psh, " %s\n",
    163161                                    (signo) ? sys_signame[signo] : "EXIT");
     
    173171                        return 0;
    174172
    175         if (signame_to_signum(*ap) == -1) {
     173        if (signame_to_signum(psh, *ap) == -1) {
    176174                if ((*ap)[0] == '-') {
    177175                        if ((*ap)[1] == '\0')
    178176                                ap++;
    179177                        else if ((*ap)[1] == 'l' && (*ap)[2] == '\0') {
    180                                 printsignals();
     178                                printsignals(psh);
    181179                                return 0;
    182180                        }
     
    192190                        signo = number(psh, *ap);
    193191                else
    194                         signo = signame_to_signum(*ap);
     192                        signo = signame_to_signum(psh, *ap);
    195193
    196194                if (signo < 0 || signo > NSIG)
     
    201199                        action = savestr(action);
    202200
    203                 if (trap[signo])
    204                         ckfree(trap[signo]);
    205 
    206                 trap[signo] = action;
     201                if (psh->trap[signo])
     202                        ckfree(psh->trap[signo]);
     203
     204                psh->trap[signo] = action;
    207205
    208206                if (signo != 0)
     
    223221
    224222void
    225 clear_traps(int vforked)
     223clear_traps(shinstance *psh, int vforked)
    226224{
    227225        char **tp;
    228226
    229         for (tp = trap ; tp <= &trap[NSIG] ; tp++) {
     227        for (tp = psh->trap ; tp <= &psh->trap[NSIG] ; tp++) {
    230228                if (*tp && **tp) {      /* trap not NULL or SIG_IGN */
    231229                        INTOFF;
     
    234232                                *tp = NULL;
    235233                        }
    236                         if (tp != &trap[0])
    237                                 setsignal(psh, tp - trap, vforked);
     234                        if (tp != &psh->trap[0])
     235                                setsignal(psh, (int)(tp - psh->trap), vforked);
    238236                        INTON;
    239237                }
     
    249247
    250248long
    251 setsignal(int signo, int vforked)
     249setsignal(shinstance *psh, int signo, int vforked)
    252250{
    253251        int action;
    254         sig_t sigact = SIG_DFL;
     252        sh_sig_t sigact = SH_SIG_DFL;
    255253        char *t, tsig;
    256254
    257         if ((t = trap[signo]) == NULL)
     255        if ((t = psh->trap[signo]) == NULL)
    258256                action = S_DFL;
    259257        else if (*t != '\0')
     
    264262                switch (signo) {
    265263                case SIGINT:
    266                         if (iflag(psh) || minusc || sflag(psh) == 0)
     264                        if (iflag(psh) || psh->minusc || sflag(psh) == 0)
    267265                                action = S_CATCH;
    268266                        break;
     
    287285        }
    288286
    289         t = &sigmode[signo - 1];
     287        t = &psh->sigmode[signo - 1];
    290288        tsig = *t;
    291289        if (tsig == 0) {
     
    293291                 * current setting unknown
    294292                 */
    295                 if (!getsigaction(signo, &sigact)) {
     293                if (!getsigaction(psh, signo, &sigact)) {
    296294                        /*
    297295                         * Pretend it worked; maybe we should give a warning
     
    301299                        return 0;
    302300                }
    303                 if (sigact == SIG_IGN) {
     301                if (sigact == SH_SIG_IGN) {
    304302                        if (mflag(psh) && (signo == SIGTSTP ||
    305303                             signo == SIGTTIN || signo == SIGTTOU)) {
     
    314312                return 0;
    315313        switch (action) {
    316                 case S_DFL:     sigact = SIG_DFL;       break;
     314                case S_DFL:     sigact = SH_SIG_DFL;    break;
    317315                case S_CATCH:   sigact = onsig;         break;
    318                 case S_IGN:     sigact = SIG_IGN;       break;
     316                case S_IGN:     sigact = SH_SIG_IGN;    break;
    319317        }
    320318        if (!vforked)
    321319                *t = action;
    322320        siginterrupt(signo, 1);
    323         return (long)signal(signo, sigact);
     321        return (long)sh_signal(psh, signo, sigact);
    324322}
    325323
     
    328326 */
    329327static int
    330 getsigaction(int signo, sig_t *sigact)
    331 {
    332         struct sigaction sa;
    333 
    334         if (sigaction(signo, (struct sigaction *)0, &sa) == -1)
     328getsigaction(shinstance *psh, int signo, sh_sig_t *sigact)
     329{
     330        struct sh_sigaction sa;
     331
     332        if (sh_sigaction(signo, NULL, &sa) == -1)
    335333                return 0;
    336         *sigact = (sig_t) sa.sa_handler;
     334        *sigact = (sh_sig_t)sa.sh_handler;
    337335        return 1;
    338336}
     
    343341
    344342void
    345 ignoresig(int signo, int vforked)
    346 {
    347         if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
    348                 signal(signo, SIG_IGN);
     343ignoresig(shinstance *psh, int signo, int vforked)
     344{
     345        if (psh->sigmode[signo - 1] != S_IGN && psh->sigmode[signo - 1] != S_HARD_IGN) {
     346                sh_signal(psh, signo, SH_SIG_IGN);
    349347        }
    350348        if (!vforked)
    351                 sigmode[signo - 1] = S_HARD_IGN;
     349                psh->sigmode[signo - 1] = S_HARD_IGN;
    352350}
    353351
     
    361359
    362360        clear_traps(psh, s0);
    363         for (sm = sigmode ; sm < sigmode + NSIG ; sm++) {
     361        for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) {
    364362                if (*sm == S_IGN)
    365363                        *sm = S_HARD_IGN;
     
    377375onsig(shinstance *psh, int signo)
    378376{
    379         signal(signo, onsig);
    380         if (signo == SIGINT && trap[SIGINT] == NULL) {
     377        sh_signal(psh, signo, onsig);
     378        if (signo == SIGINT && psh->trap[SIGINT] == NULL) {
    381379                onint(psh);
    382380                return;
    383381        }
    384         gotsig[signo - 1] = 1;
    385         pendingsigs++;
     382        psh->gotsig[signo - 1] = 1;
     383        psh->pendingsigs++;
    386384}
    387385
     
    394392
    395393void
    396 dotrap(void)
     394dotrap(shinstance *psh)
    397395{
    398396        int i;
     
    408406                psh->gotsig[i - 1] = 0;
    409407                savestatus=psh->exitstatus;
    410                 evalstring(psh, trap[i], 0);
     408                evalstring(psh, psh->trap[i], 0);
    411409                psh->exitstatus=savestatus;
    412410        }
     
    423421
    424422void
    425 setinteractive(int on)
     423setinteractive(shinstance *psh, int on)
    426424{
    427425        static int is_interactive;
     
    442440
    443441void
    444 exitshell(int status)
     442exitshell(shinstance *psh, int status)
    445443{
    446444        struct jmploc loc1, loc2;
     
    454452                goto l2;
    455453        }
    456         handler = &loc1;
    457         if ((p = trap[0]) != NULL && *p != '\0') {
    458                 trap[0] = NULL;
     454        psh->handler = &loc1;
     455        if ((p = psh->trap[0]) != NULL && *p != '\0') {
     456                psh->trap[0] = NULL;
    459457                evalstring(psh, p, 0);
    460458        }
    461 l1:   handler = &loc2;                  /* probably unnecessary */
     459l1:   psh->handler = &loc2;                     /* probably unnecessary */
    462460        output_flushall(psh);
    463461#if JOBS
    464462        setjobctl(psh, 0);
    465463#endif
    466 l2:   _exit(status);
     464l2: sh__exit(psh, status);
    467465        /* NOTREACHED */
    468466}
  • trunk/src/kash/var.c

    r1207 r1208  
    285285{
    286286        struct jmploc jmploc;
    287         struct jmploc *volatile savehandler = handler;
     287        struct jmploc *volatile savehandler = psh->handler;
    288288        int err = 0;
    289289#ifdef __GNUC__
     
    294294                err = 1;
    295295        else {
    296                 handler = &jmploc;
     296                psh->handler = &jmploc;
    297297                setvar(psh, name, val, flags);
    298298        }
    299         handler = savehandler;
     299        psh->handler = savehandler;
    300300        return err;
    301301}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette