Changeset 3433 for trunk/src/kash/jobs.c


Ignore:
Timestamp:
Sep 2, 2020, 7:25:31 PM (5 years ago)
Author:
bird
Message:

kash: refactoring forkshell(); simple stuff.

File:
1 edited

Legend:

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

    r3408 r3433  
    800800}
    801801
     802int forkshell2(struct shinstance *psh, struct job *jp, union node *n, int mode,
     803               int (*child)(struct shinstance *, void *, union node *),
     804               union node *nchild, void *argp, size_t arglen)
     805{
     806        pid_t pid;
     807
     808        TRACE((psh, "forkshell2(%%%d, %p, %d, %p, %p, %p, %d) called\n", jp - psh->jobtab, n, mode, child, nchild, argp, (int)arglen));
     809        pid = sh_fork(psh);
     810        if (pid == 0)
     811        {
     812                /* child */
     813                (void)arglen;
     814                forkchild(psh, jp, n, mode, 0);
     815                sh_exit(psh, child(psh, nchild, argp));
     816                return 0;
     817        }
     818
     819        /* parent */
     820        if (pid != -1)
     821                return forkparent(psh, jp, n, mode, pid);
     822        TRACE((psh, "Fork failed, errno=%d\n", errno));
     823        INTON;
     824        error(psh, "Cannot fork");
     825        return -1; /* won't get here */
     826}
     827
    802828int
    803829forkparent(shinstance *psh, struct job *jp, union node *n, int mode, pid_t pid)
Note: See TracChangeset for help on using the changeset viewer.