BSD 4_3 release
[unix-history] / usr / src / usr.bin / find / find.c
index 98914b2..e948647 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef        lint
 #ifndef        lint
-static char *sccsid = "@(#)find.c      4.12 (Berkeley) %G%";
+static char *sccsid = "@(#)find.c      4.17 (Berkeley) 1/31/86";
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
@@ -201,7 +201,8 @@ struct anode *e3() { /* parse parens and predicates */
                nouser(), nogroup(), ls(), dummy();
        struct anode *p1;
        int i;
                nouser(), nogroup(), ls(), dummy();
        struct anode *p1;
        int i;
-       register char *a, *b, s;
+       register char *a, *b;
+       register int s;
 
        a = nxtarg();
        if(EQ(a, "(")) {
 
        a = nxtarg();
        if(EQ(a, "(")) {
@@ -551,7 +552,7 @@ doex(com)
        register char *na;
        static char *nargv[50];
        static ccode;
        register char *na;
        static char *nargv[50];
        static ccode;
-       register int w, pid, (*sigint)(), (*sigquit)(), cantexec;
+       register int w, pid, omask;
 
        ccode = np = 0;
        while (na=Argv[com++]) {
 
        ccode = np = 0;
        while (na=Argv[com++]) {
@@ -562,11 +563,6 @@ doex(com)
        }
        nargv[np] = 0;
        if (np==0) return(9);
        }
        nargv[np] = 0;
        if (np==0) return(9);
-       /*
-        * This is a kludge, but the alternative is to reserve
-        * some exit code (e.g. 0xff) to denote inability to exec.
-        */
-       cantexec = 0;
        switch (pid = vfork()) {
        case -1:
                perror("find: Can't fork");
        switch (pid = vfork()) {
        case -1:
                perror("find: Can't fork");
@@ -576,22 +572,22 @@ doex(com)
        case 0:
                chdir(Home);
                execvp(nargv[0], nargv, np);
        case 0:
                chdir(Home);
                execvp(nargv[0], nargv, np);
-               cantexec = 1;   /* XXX */
-               _exit(1);
+               write(2, "find: Can't execute ", 20);
+               perror(nargv[0]);
+               /*
+                * Kill ourselves; our exit status will be a suicide
+                * note indicating we couldn't do the "exec".
+                */
+               kill(getpid(), SIGUSR1);
                break;
 
        default:
                break;
 
        default:
-               sigint = signal(SIGINT, SIG_IGN);
-               sigquit = signal(SIGQUIT, SIG_IGN);
+               omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT));
                while ((w = wait(&ccode)) != pid && w != -1)
                        ;
                while ((w = wait(&ccode)) != pid && w != -1)
                        ;
-               signal(SIGQUIT, sigquit);
-               signal(SIGINT, sigint);
-               if (cantexec) { /* XXX */
-                       fprintf(stderr, "find: Can't execute ");
-                       perror(nargv[0]);
+               (void) sigsetmask(omask);
+               if ((ccode & 0177) == SIGUSR1)
                        exit(1);
                        exit(1);
-               }
                return (ccode != 0 ? 0 : 1);
        }
 }
                return (ccode != 0 ? 0 : 1);
        }
 }
@@ -718,7 +714,8 @@ register char *s, *p;
                                        return(0);
 
                        case '-':
                                        return(0);
 
                        case '-':
-                               k |= lc <= scc && scc <= (cc=p[1]);
+                               cc = p[1];
+                               k |= lc <= scc && scc <= cc;
                        }
                        if (scc==(lc=cc)) k++;
                }
                        }
                        if (scc==(lc=cc)) k++;
                }
@@ -967,13 +964,11 @@ getname(uid)
        register struct passwd *pw;
        struct passwd *getpwent();
        register int cp;
        register struct passwd *pw;
        struct passwd *getpwent();
        register int cp;
-#ifndef        NO_PW_STAYOPEN
        extern int _pw_stayopen;
 
        _pw_stayopen = 1;
        extern int _pw_stayopen;
 
        _pw_stayopen = 1;
-#endif
 
 
-#if    ((NUID) & ((NUID) - 1) != 0)
+#if    (((NUID) & ((NUID) - 1)) != 0)
        cp = uid % (NUID);
 #else
        cp = uid & ((NUID) - 1);
        cp = uid % (NUID);
 #else
        cp = uid & ((NUID) - 1);
@@ -1168,9 +1163,20 @@ list(file, stp)
                sprintf(fsize, "%8ld", stp->st_size);
 #ifdef S_IFLNK
                if (pmode[0] == 'l') {
                sprintf(fsize, "%8ld", stp->st_size);
 #ifdef S_IFLNK
                if (pmode[0] == 'l') {
-                       who = readlink(file, flink, sizeof flink - 1);
+                       /*
+                        * Need to get the tail of the file name, since we have
+                        * already chdir()ed into the directory of the file
+                        */
+                       cp = rindex(file, '/');
+                       if (cp == NULL)
+                               cp = file;
+                       else
+                               cp++;
+                       who = readlink(cp, flink, sizeof flink - 1);
                        if (who >= 0)
                                flink[who] = '\0';
                        if (who >= 0)
                                flink[who] = '\0';
+                       else
+                               flink[0] = '\0';
                }
 #endif
        }
                }
 #endif
        }