VirtualBox

Changeset 3435 in kBuild


Ignore:
Timestamp:
Sep 2, 2020 8:30:54 PM (4 years ago)
Author:
bird
Message:

kash: Remove vfork code, we've never used it and we wont need it if we replace fork() with pthreads.

Location:
trunk/src/kash
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/eval.c

    r3434 r3435  
    773773 *      evalcommand_out, evalcommand_parent, evalcommand_doit, evalcommand_child
    774774 */
    775 /*int vforked = 0;*/
     775/*int vforked = 0; - obsolete */
    776776
    777777/* Both child and parent exits thru here. */
     
    983983                        trputs(psh, "normal command:  ");  trargs(psh, args->argv);
    984984#endif
    985                         clearredir(psh, psh->vforked);
    986                         redirect(psh, cmd->ncmd.redirect, psh->vforked ? REDIR_VFORK : 0);
    987                         if (!psh->vforked)
    988                                 for (sp = args->varlist.list ; sp ; sp = sp->next)
    989                                         setvareq(psh, sp->text, VEXPORT|VSTACK);
     985                        clearredir(psh);
     986                        redirect(psh, cmd->ncmd.redirect, 0);
     987                        for (sp = args->varlist.list ; sp ; sp = sp->next)
     988                                setvareq(psh, sp->text, VEXPORT|VSTACK);
    990989                        envp = environment(psh);
    991                         shellexec(psh, args->argv, envp, args->path, args->cmdentry.u.index, psh->vforked);
     990                        shellexec(psh, args->argv, envp, args->path, args->cmdentry.u.index);
    992991                        break;
    993992                }
     
    10141013        const char *path = pathval(psh);
    10151014
    1016         psh->vforked = 0;
    10171015        /* First expand the arguments. */
    10181016        TRACE((psh, "evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
     
    11531151
    11541152                if (flags & EV_BACKCMD) {
    1155                         if (!psh->vforked) {
    1156                                 FORCEINTON;
    1157                         }
     1153                        FORCEINTON;
    11581154                        shfile_close(&psh->fdtab, pip[0]);
    11591155                        if (pip[1] != 1) {
     
    13041300                for (sp = psh->cmdenviron; sp; sp = sp->next)
    13051301                        setvareq(psh, sp->text, VEXPORT|VSTACK);
    1306                 shellexec(psh, argv + 1, environment(psh), pathval(psh), 0, 0);
     1302                shellexec(psh, argv + 1, environment(psh), pathval(psh), 0);
    13071303        }
    13081304        return 0;
  • trunk/src/kash/exec.c

    r3057 r3435  
    9999
    100100
    101 STATIC void tryexec(shinstance *, char *, char **, char **, int, int);
     101STATIC void tryexec(shinstance *, char *, char **, char **, int);
    102102STATIC void execinterp(shinstance *, char **, char **);
    103103STATIC void printentry(shinstance *, struct tblentry *, int);
     
    118118
    119119SH_NORETURN_1 void
    120 shellexec(shinstance *psh, char **argv, char **envp, const char *path, int idx, int vforked)
     120shellexec(shinstance *psh, char **argv, char **envp, const char *path, int idx)
    121121{
    122122        char *cmdname;
     
    144144                cmdname = stalloc(psh, argv0len + 5);
    145145                strcpy(cmdname, argv0);
    146                 tryexec(psh, cmdname, argv, envp, vforked, has_ext);
     146                tryexec(psh, cmdname, argv, envp, has_ext);
    147147                TRACE((psh, "shellexec: cmdname=%s\n", cmdname));
    148148                stunalloc(psh, cmdname);
     
    165165                while ((cmdname = padvance(psh, &path, argv0)) != NULL) {
    166166                        if (--idx < 0 && psh->pathopt == NULL) {
    167                                 tryexec(psh, cmdname, argv, envp, vforked, has_ext);
     167                                tryexec(psh, cmdname, argv, envp, has_ext);
    168168                                if (errno != ENOENT && errno != ENOTDIR)
    169169                                        e = errno;
     
    185185                break;
    186186        }
    187         TRACE((psh, "shellexec failed for '%s', errno %d, vforked %d, suppressint %d\n",
    188                 argv[0], e, vforked, psh->suppressint ));
     187        TRACE((psh, "shellexec failed for '%s', errno %d, suppressint %d\n",
     188                argv[0], e, psh->suppressint ));
    189189        exerror(psh, EXEXEC, "%s: %s", argv[0], errmsg(psh, e, E_EXEC));
    190190        /* NOTREACHED */
     
    193193
    194194STATIC void
    195 tryexec(shinstance *psh, char *cmd, char **argv, char **envp, int vforked, int has_ext)
     195tryexec(shinstance *psh, char *cmd, char **argv, char **envp, int has_ext)
    196196{
    197197        int e;
     
    220220        e = errno;
    221221        if (e == ENOEXEC) {
    222                 if (vforked) {
    223                         /* We are currently vfork(2)ed, so raise an
    224                          * exception, and evalcommand will try again
    225                          * with a normal fork(2).
    226                          */
    227                         exraise(psh, EXSHELLPROC);
    228                 }
    229222                initshellproc(psh);
    230223                setinputfile(psh, cmd, 0);
     
    347340            /* nothing*/;
    348341        TRACE((psh, "hash bang '%s'\n", new[0]));
    349         shellexec(psh, new, envp, pathval(psh), 0, 0);
     342        shellexec(psh, new, envp, pathval(psh), 0);
    350343        /* NOTREACHED */
    351344}
  • trunk/src/kash/exec.h

    r2415 r3435  
    7171#endif
    7272
    73 SH_NORETURN_1 void shellexec(struct shinstance *, char **, char **, const char *, int, int) SH_NORETURN_2;
     73SH_NORETURN_1 void shellexec(struct shinstance *, char **, char **, const char *, int) SH_NORETURN_2;
    7474char *padvance(struct shinstance *, const char **, const char *);
    7575int hashcmd(struct shinstance *, int, char **);
  • trunk/src/kash/generated/init.c

    r2652 r3435  
    276276      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/redir.c: */
    277277      {
    278               clearredir(psh, 0);
     278              clearredir(psh);
    279279      }
    280280
     
    283283              char *sm;
    284284
    285               clear_traps(psh, 0);
     285              clear_traps(psh);
    286286              for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) {
    287287                      if (*sm == S_IGN)
  • trunk/src/kash/input.c

    r3065 r3435  
    565565
    566566void
    567 closescript(shinstance *psh, int vforked)
    568 {
    569         if (vforked)
    570                 return;
     567closescript(shinstance *psh)
     568{
    571569        popallfiles(psh);
    572570        if (psh->parsefile->fd > 0) {
  • trunk/src/kash/input.h

    r1233 r3435  
    5858void popfile(struct shinstance *);
    5959void popallfiles(struct shinstance *);
    60 void closescript(struct shinstance *, int);
     60void closescript(struct shinstance *);
    6161
    6262#define pgetc_macro(psh)        (--(psh)->parsenleft >= 0? *(psh)->parsenextc++ : preadbuffer(psh))
  • trunk/src/kash/jobs.c

    r3434 r3435  
    8686#ifdef KASH_USE_FORKSHELL2
    8787static int forkparent(shinstance *psh, struct job *jp, union node *n, int mode, pid_t pid);
    88 static void forkchild(shinstance *psh, struct job *jp, union node *n, int mode, int vforked);
     88static void forkchild(shinstance *psh, struct job *jp, union node *n, int mode);
    8989#endif
    9090
     
    149149                } while (0);
    150150
    151                 setsignal(psh, SIGTSTP, 0);
    152                 setsignal(psh, SIGTTOU, 0);
    153                 setsignal(psh, SIGTTIN, 0);
     151                setsignal(psh, SIGTSTP);
     152                setsignal(psh, SIGTTOU);
     153                setsignal(psh, SIGTTIN);
    154154                if (sh_getpgid(psh, 0) != psh->rootpid && sh_setpgid(psh, 0, psh->rootpid) == -1)
    155155                        error(psh, "Cannot set process group (%s) at %d",
     
    167167                shfile_close(&psh->fdtab, psh->ttyfd);
    168168                psh->ttyfd = -1;
    169                 setsignal(psh, SIGTSTP, 0);
    170                 setsignal(psh, SIGTTOU, 0);
    171                 setsignal(psh, SIGTTIN, 0);
     169                setsignal(psh, SIGTSTP);
     170                setsignal(psh, SIGTTOU);
     171                setsignal(psh, SIGTTIN);
    172172        }
    173173        psh->jobctl = on;
     
    798798                return -1; /* won't get here */
    799799        case 0:
    800                 forkchild(psh, jp, n, mode, 0);
     800                forkchild(psh, jp, n, mode);
    801801                return 0;
    802802        default:
     
    817817                /* child */
    818818                (void)arglen;
    819                 forkchild(psh, jp, n, mode, 0);
     819                forkchild(psh, jp, n, mode);
    820820                sh_exit(psh, child(psh, nchild, argp));
    821821                return 0;
     
    866866#endif
    867867void
    868 forkchild(shinstance *psh, struct job *jp, union node *n, int mode, int vforked)
     868forkchild(shinstance *psh, struct job *jp, union node *n, int mode)
    869869{
    870870        int wasroot;
     
    875875        wasroot = psh->rootshell;
    876876        TRACE((psh, "Child shell %d\n", sh_getpid(psh)));
    877         if (!vforked)
    878                 psh->rootshell = 0;
    879 
    880         closescript(psh, vforked);
    881         clear_traps(psh, vforked);
    882 #if JOBS
    883         if (!vforked)
    884                 psh->jobctl = 0;                /* do job control only in root shell */
     877        psh->rootshell = 0;
     878
     879        closescript(psh);
     880        clear_traps(psh);
     881#if JOBS
     882        psh->jobctl = 0;                /* do job control only in root shell */
    885883        if (wasroot && mode != FORK_NOJOB && mflag(psh)) {
    886884                if (jp == NULL || jp->nprocs == 0)
     
    896894                                    sh_strerror(psh, errno), __LINE__);
    897895                }
    898                 setsignal(psh, SIGTSTP, vforked);
    899                 setsignal(psh, SIGTTOU, vforked);
     896                setsignal(psh, SIGTSTP);
     897                setsignal(psh, SIGTTOU);
    900898        } else if (mode == FORK_BG) {
    901                 ignoresig(psh, SIGINT, vforked);
    902                 ignoresig(psh, SIGQUIT, vforked);
     899                ignoresig(psh, SIGINT);
     900                ignoresig(psh, SIGQUIT);
    903901                if ((jp == NULL || jp->nprocs == 0) &&
    904902                    ! fd0_redirected_p(psh)) {
     
    910908#else
    911909        if (mode == FORK_BG) {
    912                 ignoresig(psh, SIGINT, vforked);
    913                 ignoresig(psh, SIGQUIT, vforked);
     910                ignoresig(psh, SIGINT);
     911                ignoresig(psh, SIGQUIT);
    914912                if ((jp == NULL || jp->nprocs == 0) &&
    915913                    ! fd0_redirected_p(psh)) {
     
    921919#endif
    922920        if (wasroot && iflag(psh)) {
    923                 setsignal(psh, SIGINT, vforked);
    924                 setsignal(psh, SIGQUIT, vforked);
    925                 setsignal(psh, SIGTERM, vforked);
    926         }
    927 
    928         if (!vforked)
    929                 psh->jobs_invalid = 1;
     921                setsignal(psh, SIGINT);
     922                setsignal(psh, SIGQUIT);
     923                setsignal(psh, SIGTERM);
     924        }
     925
     926        psh->jobs_invalid = 1;
    930927}
    931928
  • trunk/src/kash/jobs.h

    r3434 r3435  
    101101#else
    102102int forkshell(struct shinstance *, struct job *, union node *, int);
    103 void forkchild(struct shinstance *, struct job *, union node *, int, int);
     103void forkchild(struct shinstance *, struct job *, union node *, int);
    104104int forkparent(struct shinstance *, struct job *, union node *, int, pid_t);
    105105#endif
  • trunk/src/kash/main.c

    r2457 r3435  
    241241
    242242                for (i = 0; i < SIGSSIZE; i++)
    243                     setsignal(psh, sigs[i], 0);
     243                    setsignal(psh, sigs[i]);
    244244        }
    245245
  • trunk/src/kash/redir.c

    r3433 r3435  
    114114        memory[1] = flags & REDIR_BACKQ;
    115115        if (flags & REDIR_PUSH) {
    116                 /* We don't have to worry about REDIR_VFORK here, as
    117                  * flags & REDIR_PUSH is never true if REDIR_VFORK is set.
    118                  */
    119116                sv = ckmalloc(psh, sizeof (struct redirtab));
    120117                for (i = 0 ; i < 10 ; i++)
     
    174171        char *fname;
    175172        int f;
    176         int oflags = O_WRONLY|O_CREAT|O_TRUNC, eflags;
     173        int oflags = O_WRONLY|O_CREAT|O_TRUNC;
    177174
    178175        /*
     
    186183        case NFROM:
    187184                fname = redir->nfile.expfname;
    188                 if (flags & REDIR_VFORK)
    189                         eflags = O_NONBLOCK;
    190                 else
    191                         eflags = 0;
    192                 if ((f = shfile_open(&psh->fdtab, fname, O_RDONLY|eflags, 0)) < 0)
     185                if ((f = shfile_open(&psh->fdtab, fname, O_RDONLY, 0)) < 0)
    193186                        goto eopen;
    194                 if (eflags)
    195                         (void)shfile_fcntl(&psh->fdtab, f, F_SETFL, shfile_fcntl(&psh->fdtab, f, F_GETFL, 0) & ~eflags);
    196187                break;
    197188        case NFROMTO:
     
    365356
    366357SHELLPROC {
    367         clearredir(psh, 0);
     358        clearredir(psh);
    368359}
    369360
     
    381372
    382373void
    383 clearredir(shinstance *psh, int vforked)
     374clearredir(shinstance *psh)
    384375{
    385376        struct redirtab *rp;
     
    391382                                shfile_close(&psh->fdtab, rp->renamed[i]);
    392383                        }
    393                         if (!vforked)
    394                                 rp->renamed[i] = EMPTY;
     384                        rp->renamed[i] = EMPTY;
    395385                }
    396386        }
  • trunk/src/kash/redir.h

    r2424 r3435  
    3838#define REDIR_PUSH 01           /* save previous values of file descriptors */
    3939#define REDIR_BACKQ 02          /* save the command output in memory */
    40 #define REDIR_VFORK 04          /* running under vfork(2), be careful */
     40//#define REDIR_VFORK 04                /* running under vfork(2), be careful */
    4141
    4242union node;
     
    4444void popredir(struct shinstance *);
    4545int fd0_redirected_p(struct shinstance *);
    46 void clearredir(struct shinstance *, int);
     46void clearredir(struct shinstance *);
    4747int copyfd(struct shinstance *, int, int);
    4848int movefd(struct shinstance *, int, int);
  • trunk/src/kash/shinstance.h

    r3434 r3435  
    178178    int                 skipcount;      /**< number of levels to skip */
    179179    int                 loopnest;       /**< current loop nesting level */
    180 
    181     /* eval.c */
    182     int                 vforked; /** @todo remove this */
    183180
    184181    /* expand.c */
  • trunk/src/kash/trap.c

    r3409 r3435  
    187187
    188188                if (signo != 0)
    189                         setsignal(psh, signo, 0);
     189                        setsignal(psh, signo);
    190190                INTON;
    191191                ap++;
     
    203203
    204204void
    205 clear_traps(shinstance *psh, int vforked)
     205clear_traps(shinstance *psh)
    206206{
    207207        char **tp;
     
    210210                if (*tp && **tp) {      /* trap not NULL or SIG_IGN */
    211211                        INTOFF;
    212                         if (!vforked) {
    213                                 ckfree(psh, *tp);
    214                                 *tp = NULL;
    215                         }
     212                        ckfree(psh, *tp);
     213                        *tp = NULL;
    216214                        if (tp != &psh->trap[0])
    217                                 setsignal(psh, (int)(tp - psh->trap), vforked);
     215                                setsignal(psh, (int)(tp - psh->trap));
    218216                        INTON;
    219217                }
     
    229227
    230228void
    231 setsignal(shinstance *psh, int signo, int vforked)
     229setsignal(shinstance *psh, int signo)
    232230{
    233231        int action;
     
    241239        else
    242240                action = S_IGN;
    243         if (psh->rootshell && !vforked && action == S_DFL) {
     241        if (psh->rootshell && action == S_DFL) {
    244242                switch (signo) {
    245243                case SIGINT:
     
    298296                case S_IGN:     sigact = SH_SIG_IGN;    break;
    299297        }
    300         if (!vforked)
    301                 *t = action;
     298        *t = action;
    302299        sh_siginterrupt(psh, signo, 1);
    303300        sh_signal(psh, signo, sigact);
     
    323320
    324321void
    325 ignoresig(shinstance *psh, int signo, int vforked)
     322ignoresig(shinstance *psh, int signo)
    326323{
    327324        if (psh->sigmode[signo - 1] != S_IGN && psh->sigmode[signo - 1] != S_HARD_IGN) {
    328325                sh_signal(psh, signo, SH_SIG_IGN);
    329326        }
    330         if (!vforked)
    331                 psh->sigmode[signo - 1] = S_HARD_IGN;
     327        psh->sigmode[signo - 1] = S_HARD_IGN;
    332328}
    333329
     
    340336        char *sm;
    341337
    342         clear_traps(psh, 0);
     338        clear_traps(psh);
    343339        for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) {
    344340                if (*sm == S_IGN)
     
    409405        if (on == is_interactive)
    410406                return;
    411         setsignal(psh, SIGINT, 0);
    412         setsignal(psh, SIGQUIT, 0);
    413         setsignal(psh, SIGTERM, 0);
     407        setsignal(psh, SIGINT);
     408        setsignal(psh, SIGQUIT);
     409        setsignal(psh, SIGTERM);
    414410        is_interactive = on;
    415411}
  • trunk/src/kash/trap.h

    r2298 r3435  
    3838
    3939int trapcmd(struct shinstance *, int, char **);
    40 void clear_traps(struct shinstance *, int);
    41 void setsignal(struct shinstance *, int, int);
    42 void ignoresig(struct shinstance *, int, int);
     40void clear_traps(struct shinstance *);
     41void setsignal(struct shinstance *, int);
     42void ignoresig(struct shinstance *, int);
    4343void onsig(struct shinstance *, int);
    4444void dotrap(struct shinstance *);
Note: See TracChangeset for help on using the changeset viewer.

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