BSD 4_4_Lite2 release
[unix-history] / usr / src / bin / csh / exec.c
index f449f69..49c04ae 100644 (file)
@@ -1,12 +1,38 @@
 /*-
 /*-
- * Copyright (c) 1980, 1991 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)exec.c     5.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)exec.c     8.3 (Berkeley) 5/23/95";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -63,7 +89,7 @@ static Char *expath;          /* Path for exerr */
 #define HSHMUL         243
 static char xhash[HSHSIZ / 8];
 
 #define HSHMUL         243
 static char xhash[HSHSIZ / 8];
 
-#define hash(a, b)     ((a) * HSHMUL + (b) & HSHMASK)
+#define hash(a, b)     (((a) * HSHMUL + (b)) & HSHMASK)
 #define bit(h, b)      ((h)[(b) >> 3] & 1 << ((b) & 7))        /* bit test */
 #define bis(h, b)      ((h)[(b) >> 3] |= 1 << ((b) & 7))       /* bit set */
 static int hits, misses;
 #define bit(h, b)      ((h)[(b) >> 3] & 1 << ((b) & 7))        /* bit test */
 #define bis(h, b)      ((h)[(b) >> 3] |= 1 << ((b) & 7))       /* bit set */
 static int hits, misses;
@@ -90,6 +116,7 @@ doexec(v, t)
     register bool slash;
     register int hashval = 0, hashval1, i;
     Char   *blk[2];
     register bool slash;
     register int hashval = 0, hashval1, i;
     Char   *blk[2];
+    sigset_t sigset;
 
     /*
      * Glob the command name. We will search $path even if this does something,
 
     /*
      * Glob the command name. We will search $path even if this does something,
@@ -165,7 +192,8 @@ doexec(v, t)
      * We must do this AFTER any possible forking (like `foo` in glob) so that
      * this shell can still do subprocesses.
      */
      * We must do this AFTER any possible forking (like `foo` in glob) so that
      * this shell can still do subprocesses.
      */
-    (void) sigsetmask((sigset_t) 0);
+    sigemptyset(&sigset);
+    sigprocmask(SIG_SETMASK, &sigset, NULL);
     /*
      * 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.
@@ -441,7 +469,7 @@ dohash(v, t)
                continue;
            if (dp->d_name[0] == '.' &&
                (dp->d_name[1] == '\0' ||
                continue;
            if (dp->d_name[0] == '.' &&
                (dp->d_name[1] == '\0' ||
-                dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
+                (dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
                continue;
            hashval = hash(hashname(str2short(dp->d_name)), i);
            bis(xhash, hashval);
                continue;
            hashval = hash(hashname(str2short(dp->d_name)), i);
            bis(xhash, hashval);
@@ -608,7 +636,7 @@ dowhich(v, c)
     lex[2].word = STRret;
 
     while (*++v) {
     lex[2].word = STRret;
 
     while (*++v) {
-       if (vp = adrof1(*v, &aliases)) {
+       if ((vp = adrof1(*v, &aliases)) != NULL) {
            (void) fprintf(cshout, "%s: \t aliased to ", vis_str(*v));
            blkpr(cshout, vp->vec);
            (void) fputc('\n', cshout);
            (void) fprintf(cshout, "%s: \t aliased to ", vis_str(*v));
            blkpr(cshout, vp->vec);
            (void) fputc('\n', cshout);
@@ -628,7 +656,7 @@ tellmewhat(lex)
     register struct biltins *bptr;
     register struct wordent *sp = lex->next;
     bool    aliased = 0;
     register struct biltins *bptr;
     register struct wordent *sp = lex->next;
     bool    aliased = 0;
-    Char   *s0, *s1, *s2;
+    Char   *s0, *s1, *s2, *cmd;
     Char    qc;
 
     if (adrof1(sp->word, &aliases)) {
     Char    qc;
 
     if (adrof1(sp->word, &aliases)) {
@@ -675,7 +703,9 @@ tellmewhat(lex)
        }
     }
 
        }
     }
 
-    if (i = iscommand(strip(sp->word))) {
+    sp->word = cmd = globone(sp->word, G_IGNORE);
+
+    if ((i = iscommand(strip(sp->word))) != 0) {
        register Char **pv;
        register struct varent *v;
        bool    slash = any(short2str(sp->word), '/');
        register Char **pv;
        register struct varent *v;
        bool    slash = any(short2str(sp->word), '/');
@@ -689,10 +719,15 @@ tellmewhat(lex)
        while (--i)
            pv++;
        if (pv[0][0] == 0 || eq(pv[0], STRdot)) {
        while (--i)
            pv++;
        if (pv[0][0] == 0 || eq(pv[0], STRdot)) {
-           sp->word = Strspl(STRdotsl, sp->word);
-           prlex(cshout, lex);
-           xfree((ptr_t) sp->word);
+           if (!slash) {
+               sp->word = Strspl(STRdotsl, sp->word);
+               prlex(cshout, lex);
+               xfree((ptr_t) sp->word);
+           }
+           else
+               prlex(cshout, lex);
            sp->word = s0;      /* we save and then restore this */
            sp->word = s0;      /* we save and then restore this */
+           xfree((ptr_t) cmd);
            return;
        }
        s1 = Strspl(*pv, STRslash);
            return;
        }
        s1 = Strspl(*pv, STRslash);
@@ -707,4 +742,5 @@ tellmewhat(lex)
        (void) fprintf(csherr, "%s: Command not found.\n", vis_str(sp->word));
     }
     sp->word = s0;             /* we save and then restore this */
        (void) fprintf(csherr, "%s: Command not found.\n", vis_str(sp->word));
     }
     sp->word = s0;             /* we save and then restore this */
+    xfree((ptr_t) cmd);
 }
 }