BSD 4 release
[unix-history] / usr / src / cmd / csh / sh.exec.c
index f8937bb..9a79251 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (c) 1979 Regents of the University of California */
+static char *sccsid = "@(#)sh.exec.c 4.1 10/9/80";
+
 #include "sh.h"
 
 /*
 #include "sh.h"
 
 /*
@@ -33,7 +34,9 @@ char  *expath;                /* Path for exerr */
 int    havhash;
 #define        HSHSIZ  511
 char   xhash[HSHSIZ];
 int    havhash;
 #define        HSHSIZ  511
 char   xhash[HSHSIZ];
+#ifdef VFORK
 int    hits, misses;
 int    hits, misses;
+#endif
 
 /* Dummy search path for just absolute search when no path */
 char   *justabs[] =    { "", 0 };
 
 /* Dummy search path for just absolute search when no path */
 char   *justabs[] =    { "", 0 };
@@ -85,6 +88,12 @@ doexec(t)
        xechoit(av);            /* Echo command if -x */
        closech();              /* Close random fd's */
 
        xechoit(av);            /* Echo command if -x */
        closech();              /* Close random fd's */
 
+       /*
+        * We must do this after any possible forking (like `foo`
+        * in glob) so that this shell can still do subprocesses.
+        */
+       sigsys(SIGCHLD, SIG_IGN);       /* sigsys for vforks sake */
+
        /*
         * If no path, no words in path, or a / in the filename
         * then restrict the command search.
        /*
         * If no path, no words in path, or a / in the filename
         * then restrict the command search.
@@ -100,7 +109,9 @@ doexec(t)
        if (havhash)
                hashval = xhash[hash(*av)];
        i = 0;
        if (havhash)
                hashval = xhash[hash(*av)];
        i = 0;
+#ifdef VFORK
        hits++;
        hits++;
+#endif
        do {
                if (!slash && pv[0][0] == '/' && havhash && (hashval & (1 << (i % 8))) == 0)
                        goto cont;
        do {
                if (!slash && pv[0][0] == '/' && havhash && (hashval & (1 << (i % 8))) == 0)
                        goto cont;
@@ -117,12 +128,16 @@ doexec(t)
 #endif
                        xfree(dp);
                }
 #endif
                        xfree(dp);
                }
+#ifdef VFORK
                misses++;
                misses++;
+#endif
 cont:
                pv++;
                i++;
        } while (*pv);
 cont:
                pv++;
                i++;
        } while (*pv);
+#ifdef VFORK
        hits--;
        hits--;
+#endif
 #ifdef VFORK
        Vsav = 0;
        Vav = 0;
 #ifdef VFORK
        Vsav = 0;
        Vav = 0;
@@ -189,7 +204,7 @@ texec(f, t)
                t = blkspl(vp, t);              /* Splice up the new arglst */
                f = *t;
                execv(f, t);
                t = blkspl(vp, t);              /* Splice up the new arglst */
                f = *t;
                execv(f, t);
-               xfree(t);
+               xfree((char *)t);
                /* The sky is falling, the sky is falling! */
 
        case ENOMEM:
                /* The sky is falling, the sky is falling! */
 
        case ENOMEM:
@@ -211,7 +226,11 @@ execash(t, kp)
 {
 
        didcch++;
 {
 
        didcch++;
+       signal(SIGINT, parintr);
+       signal(SIGQUIT, parintr);
+       signal(SIGTERM, parterm);               /* if doexec loses, screw */
        lshift(kp->t_dcom, 1);
        lshift(kp->t_dcom, 1);
+       exiterr++;
        doexec(kp);
        /*NOTREACHED*/
 }
        doexec(kp);
        /*NOTREACHED*/
 }
@@ -273,19 +292,25 @@ dounhash()
        havhash = 0;
 }
 
        havhash = 0;
 }
 
+#ifdef VFORK
 hashstat()
 {
 
        if (hits+misses)
        printf("%d hits, %d misses, %2d%%\n", hits, misses, 100 * hits / (hits + misses));
 }
 hashstat()
 {
 
        if (hits+misses)
        printf("%d hits, %d misses, %2d%%\n", hits, misses, 100 * hits / (hits + misses));
 }
+#endif
 
 hash(cp)
        register char *cp;
 {
 
 hash(cp)
        register char *cp;
 {
-       register int hash = 0;
+       register long hash = 0;
+       int retval;
 
        while (*cp)
                hash += hash + *cp++;
 
        while (*cp)
                hash += hash + *cp++;
-       return (hash % HSHSIZ);
+       if (hash < 0)
+               hash = -hash;
+       retval = hash % HSHSIZ;
+       return (retval);
 }
 }