# 2.11BSD#431 - /usr/src/lib/libc/gen/execvp.c

##### Functions

    execlp            X
    execvp            X

##### Macros

    NULL              X

       1: #if defined(LIBC_SCCS) && !defined(lint)
       2: static char sccsid[] = "@(#)execvp.c	5.2 (Berkeley) 3/9/86";
       3: #endif LIBC_SCCS and not lint
       4:
       5: /*
       6:  *	execlp(name, arg,...,0)	(like execl, but does path search)
       7:  *	execvp(name, argv)	(like execv, but does path search)
       8:  */
       9: #include <errno.h>
      10: #define NULL    0
      11:
      12: static  char shell[] =  "/bin/sh";
      13: char    *execat(), *getenv();
      14: extern  errno;
      15:
      16: execlp(name, argv)
      17: char *name, *argv;
      18: {
      19:     return(execvp(name, &argv));
      20: }
      21:
      22: execvp(name, argv)
      23: char *name, **argv;
      24: {
      25:     char *pathstr;
      26:     register char *cp;
      27:     char fname[128];
      28:     char *newargs[256];
      29:     int i;
      30:     register unsigned etxtbsy = 1;
      31:     register eacces = 0;
      32:
      33:     if ((pathstr = getenv("PATH")) == NULL)
      34:         pathstr = ":/bin:/usr/bin";
      35:     cp = index(name, '/')? "": pathstr;
      36:
      37:     do {
      38:         cp = execat(cp, name, fname);
      39:     retry:
      40:         execv(fname, argv);
      41:         switch(errno) {
      42:         case ENOEXEC:
      43:             newargs[0] = "sh";
      44:             newargs[1] = fname;
      45:             for (i=1; newargs[i+1]=argv[i]; i++) {
      46:                 if (i>=254) {
      47:                     errno = E2BIG;
      48:                     return(-1);
      49:                 }
      50:             }
      51:             execv(shell, newargs);
      52:             return(-1);
      53:         case ETXTBSY:
      54:             if (++etxtbsy > 5)
      55:                 return(-1);
      56:             sleep(etxtbsy);
      57:             goto retry;
      58:         case EACCES:
      59:             eacces++;
      60:             break;
      61:         case ENOMEM:
      62:         case E2BIG:
      63:             return(-1);
      64:         }
      65:     } while (cp);
      66:     if (eacces)
      67:         errno = EACCES;
      68:     return(-1);
      69: }
      70:
      71: static char *
      72: execat(s1, s2, si)
      73: register char *s1, *s2;
      74: char *si;
      75: {
      76:     register char *s;
      77:
      78:     s = si;
      79:     while (*s1 && *s1 != ':')
      80:         *s++ = *s1++;
      81:     if (si != s)
      82:         *s++ = '/';
      83:     while (*s2)
      84:         *s++ = *s2++;
      85:     *s = '\0';
      86:     return(*s1? ++s1: 0);
      87: }

#### Defined functions

execat defined in line 71; used 2 times

- in line 13, 38

execlp defined in line 16; used 17 times

- in /usr/src/bin/chpass/chpass.c line 415
- in /usr/src/bin/disklabel/disklabel.c line 694
- in /usr/src/bin/login/login.c line 440
- in /usr/src/games/pdp/zork/zork.c line 89-93(4)
- in /usr/src/new/jove/teachjove.c line 37
- in /usr/src/new/notes/src/misc.c line 90-92(2)
- in /usr/src/usr.bin/learn/makpipe.c line 21
- in /usr/src/usr.bin/refer/addbib.c line 214-216(2)
- in /usr/src/usr.sbin/chroot/chroot.c line 51
- in /usr/src/usr.sbin/cron/crontab.c line 391
- in /usr/src/usr.sbin/edquota/edquota.c line 339
- in /usr/src/usr.sbin/vipw/vipw.c line 246

execvp defined in line 22; used 31 times

- in line 19
- in /usr/src/bin/make/dosys.c line 129
- in /usr/src/bin/nice.c line 41
- in /usr/src/bin/time.c line 32
- in /usr/src/libexec/tcpd/safe_finger.c line 185
- in /usr/src/local/afio/afio.c line 2379
- in /usr/src/local/mtools/mcopy.c line 85-87(2), 119, 154
- in /usr/src/new/PORT/perl.1.0.0/arg.c line 766, 803
- in /usr/src/new/PORT/perl.1.0.10/arg.c line 788, 825
- in /usr/src/new/PORT/perl.1.0.16/arg.c line 807, 844
- in /usr/src/new/jove/extend.c line 962
- in /usr/src/ucb/Mail/popen.c line 214
- in /usr/src/ucb/PORT/pascal/pdx/library.c line 164
- in /usr/src/ucb/PORT/pascal/pdx/process/ptrace.c line 115
- in /usr/src/ucb/error/errormain.c line 225
- in /usr/src/ucb/man/man.c line 429
- in /usr/src/ucb/sccs.c line 555
- in /usr/src/ucb/window/wwspawn.c line 36
- in /usr/src/usr.bin/find/find.c line 570
- in /usr/src/usr.bin/learn/mysys.c line 116
- in /usr/src/usr.bin/uucp/uuxqt.c line 710
- in /usr/src/usr.bin/xargs/xargs.c line 283
- in /usr/src/usr.sbin/chroot/chroot.c line 46
- in /usr/src/usr.sbin/cron/popen.c line 117-119(2)

#### Defined variables

sccsid defined in line 2; never used
shell defined in line 12; used 1 times

- in line 51

#### Defined macros

NULL defined in line 10; used 1 times

- in line 33

Last modified: 1986-03-10 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 756 |