rework `namei' interface to eliminate global variables
[unix-history] / usr / src / sys / kern / kern_exec.c
index b8465c3..42ff5ff 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_exec.c     4.1     83/05/27        */
+/*     kern_exec.c     6.3     84/07/08        */
 
 #include "../machine/reg.h"
 #include "../machine/pte.h"
 
 #include "../machine/reg.h"
 #include "../machine/pte.h"
 #include "../h/text.h"
 #include "../h/file.h"
 #include "../h/uio.h"
 #include "../h/text.h"
 #include "../h/file.h"
 #include "../h/uio.h"
-#include "../h/nami.h"
 #include "../h/acct.h"
 
 #include "../h/acct.h"
 
+#ifdef vax
+#include "../vax/mtpr.h"
+#endif
+
 /*
  * exec system call, with and without environments.
  */
 /*
  * exec system call, with and without environments.
  */
@@ -49,9 +52,13 @@ execve()
        swblk_t bno;
        char cfname[MAXCOMLEN + 1];
        char cfarg[SHSIZE];
        swblk_t bno;
        char cfname[MAXCOMLEN + 1];
        char cfarg[SHSIZE];
+       register struct nameidata *ndp = &u.u_nd;
        int resid;
 
        int resid;
 
-       if ((ip = namei(uchar, LOOKUP, 1)) == NULL)
+       ndp->ni_nameiop = LOOKUP | FOLLOW;
+       ndp->ni_segflg = UIO_USERSPACE;
+       ndp->ni_dirp = ((struct execa *)u.u_ap)->fname;
+       if ((ip = namei(ndp)) == NULL)
                return;
        bno = 0;
        bp = 0;
                return;
        bno = 0;
        bp = 0;
@@ -93,9 +100,8 @@ execve()
            0, 1, &resid);
        if (u.u_error)
                goto bad;
            0, 1, &resid);
        if (u.u_error)
                goto bad;
-       u.u_count = resid;
 #ifndef lint
 #ifndef lint
-       if (u.u_count > sizeof(u.u_exdata) - sizeof(u.u_exdata.Ux_A) &&
+       if (resid > sizeof(u.u_exdata) - sizeof(u.u_exdata.Ux_A) &&
            u.u_exdata.ux_shell[0] != '#') {
                u.u_error = ENOEXEC;
                goto bad;
            u.u_exdata.ux_shell[0] != '#') {
                u.u_error = ENOEXEC;
                goto bad;
@@ -140,7 +146,7 @@ execve()
                cp = &u.u_exdata.ux_shell[2];
                while (*cp == ' ')
                        cp++;
                cp = &u.u_exdata.ux_shell[2];
                while (*cp == ' ')
                        cp++;
-               u.u_dirp = cp;
+               ndp->ni_dirp = cp;
                while (*cp && *cp != ' ')
                        cp++;
                sharg = NULL;
                while (*cp && *cp != ' ')
                        cp++;
                sharg = NULL;
@@ -153,14 +159,16 @@ execve()
                                sharg = cfarg;
                        }
                }
                                sharg = cfarg;
                        }
                }
-               if (u.u_dent.d_namlen > MAXCOMLEN)
-                       u.u_dent.d_namlen = MAXCOMLEN;
-               bcopy((caddr_t)u.u_dent.d_name, (caddr_t)cfname,
-                   (unsigned)(u.u_dent.d_namlen + 1));
+               if (ndp->ni_dent.d_namlen > MAXCOMLEN)
+                       ndp->ni_dent.d_namlen = MAXCOMLEN;
+               bcopy((caddr_t)ndp->ni_dent.d_name, (caddr_t)cfname,
+                   (unsigned)(ndp->ni_dent.d_namlen + 1));
                cfname[MAXCOMLEN] = 0;
                indir = 1;
                iput(ip);
                cfname[MAXCOMLEN] = 0;
                indir = 1;
                iput(ip);
-               ip = namei(schar, LOOKUP, 1);
+               ndp->ni_nameiop = LOOKUP | FOLLOW;
+               ndp->ni_segflg = UIO_SYSSPACE;
+               ip = namei(ndp);
                if (ip == NULL)
                        return;
                goto again;
                if (ip == NULL)
                        return;
                goto again;
@@ -228,9 +236,9 @@ execve()
        bp = 0;
        nc = (nc + NBPW-1) & ~(NBPW-1);
        if (indir) {
        bp = 0;
        nc = (nc + NBPW-1) & ~(NBPW-1);
        if (indir) {
-               u.u_dent.d_namlen = strlen(cfname);
-               bcopy((caddr_t)cfname, (caddr_t)u.u_dent.d_name,
-                   (unsigned)(u.u_dent.d_namlen + 1));
+               ndp->ni_dent.d_namlen = strlen(cfname);
+               bcopy((caddr_t)cfname, (caddr_t)ndp->ni_dent.d_name,
+                   (unsigned)(ndp->ni_dent.d_namlen + 1));
        }
        getxfile(ip, nc + (na+4)*NBPW, uid, gid);
        if (u.u_error) {
        }
        getxfile(ip, nc + (na+4)*NBPW, uid, gid);
        if (u.u_error) {
@@ -280,6 +288,12 @@ badarg:
        }
        (void) suword((caddr_t)ap, 0);
        setregs();
        }
        (void) suword((caddr_t)ap, 0);
        setregs();
+       /*
+        * Remember file name for accounting.
+        */
+       u.u_acflag &= ~AFORK;
+       bcopy((caddr_t)ndp->ni_dent.d_name, (caddr_t)u.u_comm,
+           (unsigned)(ndp->ni_dent.d_namlen + 1));
 bad:
        if (bp)
                brelse(bp);
 bad:
        if (bp)
                brelse(bp);
@@ -352,7 +366,7 @@ getxfile(ip, nargc, uid, gid)
                        sleep((caddr_t)u.u_procp, PZERO - 1);
                u.u_procp->p_flag &= ~(SVFDONE|SKEEP);
        }
                        sleep((caddr_t)u.u_procp, PZERO - 1);
                u.u_procp->p_flag &= ~(SVFDONE|SKEEP);
        }
-       u.u_procp->p_flag &= ~(SPAGI|SSEQL|SUANOM|SNUSIG);
+       u.u_procp->p_flag &= ~(SPAGI|SSEQL|SUANOM|SOUSIG);
        u.u_procp->p_flag |= pagi;
        u.u_dmap = u.u_cdmap;
        u.u_smap = u.u_csmap;
        u.u_procp->p_flag |= pagi;
        u.u_dmap = u.u_cdmap;
        u.u_smap = u.u_csmap;
@@ -373,7 +387,6 @@ getxfile(ip, nargc, uid, gid)
 
 #ifdef vax
        /* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */
 
 #ifdef vax
        /* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */
-#include "../vax/mtpr.h"               /* XXX */
        mtpr(TBIA, 0);
 #endif
 
        mtpr(TBIA, 0);
 #endif
 
@@ -391,6 +404,7 @@ getxfile(ip, nargc, uid, gid)
        u.u_tsize = ts;
        u.u_dsize = ds;
        u.u_ssize = ss;
        u.u_tsize = ts;
        u.u_dsize = ds;
        u.u_ssize = ss;
+       u.u_prof.pr_scale = 0;
 bad:
        return;
 }
 bad:
        return;
 }
@@ -400,70 +414,32 @@ bad:
  */
 setregs()
 {
  */
 setregs()
 {
-       register int (**rp)();
-       register int i, sigmask;
-
-       for (rp = &u.u_signal[1], sigmask = 1; rp < &u.u_signal[NSIG];
-           sigmask <<= 1, rp++) {
-               switch (*rp) {
-
-               case SIG_IGN:
-               case SIG_DFL:
-               case SIG_HOLD:
-                       continue;
+       register int i;
+       register struct proc *p = u.u_procp;
 
 
-               default:
-                       /*
-                        * Normal or deferring catch; revert to default.
-                        */
-                       (void) spl6();
-                       *rp = SIG_DFL;
-                       if ((int)*rp & 1)
-                               u.u_procp->p_siga0 |= sigmask;
-                       else
-                               u.u_procp->p_siga0 &= ~sigmask;
-                       if ((int)*rp & 2)
-                               u.u_procp->p_siga1 |= sigmask;
-                       else
-                               u.u_procp->p_siga1 &= ~sigmask;
-                       (void) spl0();
-                       continue;
-               }
+       /*
+        * Reset caught signals.  Held signals
+        * remain held through p_sigmask.
+        */
+       while (p->p_sigcatch) {
+               (void) spl6();
+               i = ffs(p->p_sigcatch);
+               p->p_sigcatch &= ~(1 << (i - 1));
+               u.u_signal[i] = SIG_DFL;
+               (void) spl0();
        }
        }
-#ifdef vax
-/*
+#ifdef notdef
+       /* should pass args to init on the stack */
        for (rp = &u.u_ar0[0]; rp < &u.u_ar0[16];)
                *rp++ = 0;
        for (rp = &u.u_ar0[0]; rp < &u.u_ar0[16];)
                *rp++ = 0;
-*/
-       u.u_ar0[PC] = u.u_exdata.ux_entloc+2;
-#endif
-#ifdef sun
-       { register struct regs *r = (struct regs *)u.u_ar0;
-         for (i = 0; i < 8; i++) {
-               r->r_dreg[i] = 0;
-               if (&r->r_areg[i] != &r->r_sp)
-                       r->r_areg[i] = 0;
-         }
-         r->r_sr = PSL_USERSET;
-         r->r_pc = u.u_exdata.ux_entloc;
-       }
 #endif
 #endif
+       u.u_ar0[PC] = u.u_exdata.ux_entloc+2;
        for (i=0; i<NOFILE; i++) {
                if (u.u_pofile[i]&UF_EXCLOSE) {
        for (i=0; i<NOFILE; i++) {
                if (u.u_pofile[i]&UF_EXCLOSE) {
-                       closef(u.u_ofile[i], u.u_pofile[i]);
+                       closef(u.u_ofile[i]);
                        u.u_ofile[i] = NULL;
                        u.u_pofile[i] = 0;
                }
                u.u_pofile[i] &= ~UF_MAPPED;
        }
                        u.u_ofile[i] = NULL;
                        u.u_pofile[i] = 0;
                }
                u.u_pofile[i] &= ~UF_MAPPED;
        }
-
-       /*
-        * Remember file name for accounting.
-        */
-       u.u_acflag &= ~AFORK;
-       bcopy((caddr_t)u.u_dent.d_name, (caddr_t)u.u_comm,
-           (unsigned)(u.u_dent.d_namlen + 1));
-#ifdef sun
-       u.u_eosys = REALLYRETURN;
-#endif
 }
 }