vfork
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Wed, 30 Nov 1983 04:54:28 +0000 (20:54 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Wed, 30 Nov 1983 04:54:28 +0000 (20:54 -0800)
SCCS-vsn: usr.bin/window/cmd1.c 3.15
SCCS-vsn: usr.bin/window/wwenviron.c 3.4
SCCS-vsn: usr.bin/window/wwspawn.c 3.5

usr/src/usr.bin/window/cmd1.c
usr/src/usr.bin/window/wwenviron.c
usr/src/usr.bin/window/wwspawn.c

index 6f2623d..e975d6d 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd1.c      3.14 83/11/29";
+static char *sccsid = "@(#)cmd1.c      3.15 83/11/29";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -178,15 +178,10 @@ char *label;
        reframe();
        wwupdate();
        wwflush();
        reframe();
        wwupdate();
        wwflush();
-       switch (wwfork(w)) {
-       case -1:
+       if (wwspawn(w, shell, shellname, (char *)0) < 0) {
                c_close(w);
                error("%s.", wwerror());
                return 0;
                c_close(w);
                error("%s.", wwerror());
                return 0;
-       case 0:
-               execl(shell, shellname, 0);
-               perror(shell);
-               exit(1);
        }
        return w;
 }
        }
        return w;
 }
index adab561..ca447de 100644 (file)
@@ -1,11 +1,9 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwenviron.c 3.3 83/08/31";
+static char *sccsid = "@(#)wwenviron.c 3.4 83/11/29";
 #endif
 
 #include "ww.h"
 
 #endif
 
 #include "ww.h"
 
-extern char **environ;
-
 /*
  * Set up the environment of this process to run in window 'wp'.
  * Can't report errors in any intelligent way, so don't.
 /*
  * Set up the environment of this process to run in window 'wp'.
  * Can't report errors in any intelligent way, so don't.
@@ -13,11 +11,9 @@ extern char **environ;
 wwenviron(wp)
 register struct ww *wp;
 {
 wwenviron(wp)
 register struct ww *wp;
 {
+       static char **termcap = 0;
+       static char *tbuf;
        register i;
        register i;
-       register char **p, **q;
-       char **termcap = 0;
-       char **env;
-       char *tbuf;
 
        (void) dup2(wp->ww_tty, 0);
        (void) dup2(wp->ww_tty, 1);
 
        (void) dup2(wp->ww_tty, 0);
        (void) dup2(wp->ww_tty, 1);
@@ -40,23 +36,34 @@ register struct ww *wp;
                return;
        }
 
                return;
        }
 
-       for (i = 0, p = environ; *p; p++, i++)
-               ;
-       if ((env = (char **)malloc((unsigned)(i + 3) * sizeof (char *))) == 0)
-               return;
-       if ((tbuf = malloc((unsigned) 1024)) == 0)
-               return;
-       for (p = environ, q = env; *p; p++, q++) {
-               if (strncmp(*p, "TERM=", 5) == 0)
-                       *q = WWT_TERM;
-               else if (strncmp(*p, "TERMCAP=", 8) == 0)
-                       termcap = q;
-               else
-                       *q = *p;
+       /*
+        * Do this only once if vfork().
+        */
+       if (termcap == 0) {
+               extern char **environ;
+               static char **env;
+               register char **p, **q;
+
+               for (i = 0, p = environ; *p; p++, i++)
+                       ;
+               env = (char **)malloc((unsigned)(i + 3) * sizeof (char *));
+               if (env == 0)
+                       return;
+               if ((tbuf = malloc((unsigned) 1024)) == 0)
+                       return;
+               for (p = environ, q = env; *p; p++, q++) {
+                       if (strncmp(*p, "TERM=", 5) == 0)
+                               *q = WWT_TERM;
+                       else if (strncmp(*p, "TERMCAP=", 8) == 0)
+                               termcap = q;
+                       else
+                               *q = *p;
+               }
+               if (termcap == 0)
+                       termcap = q++;
+               *q = 0;
+               environ = env;
        }
        }
-       if (termcap == 0)
-               termcap = q++;
-       *q = 0;
        *termcap = sprintf(tbuf, "TERMCAP=%sco#%d:li#%d:",
                WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr);
        if (wwavailmodes & WWM_REV)
        *termcap = sprintf(tbuf, "TERMCAP=%sco#%d:li#%d:",
                WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr);
        if (wwavailmodes & WWM_REV)
@@ -64,5 +71,4 @@ register struct ww *wp;
        if (wwavailmodes & WWM_UL)
                (void) strcat(tbuf, WWT_UL);
        (void) strcat(tbuf, wwkeys);
        if (wwavailmodes & WWM_UL)
                (void) strcat(tbuf, WWT_UL);
        (void) strcat(tbuf, wwkeys);
-       environ = env;
 }
 }
index 308a0a2..2929194 100644 (file)
@@ -1,24 +1,30 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwspawn.c   3.4 83/10/19";
+static char *sccsid = "@(#)wwspawn.c   3.5 83/11/29";
 #endif
 
 #include "ww.h"
 
 #endif
 
 #include "ww.h"
 
-wwfork(wp)
+/*VARARGS3*/
+wwspawn(wp, file, argv0)
 register struct ww *wp;
 register struct ww *wp;
+char *file, *argv0;
 {
 {
-       switch (wp->ww_pid = fork()) {
+       int pid;
+
+       switch (pid = vfork()) {
        case -1:
                wwerrno = WWE_SYS;
                return -1;
        case 0:
        case -1:
                wwerrno = WWE_SYS;
                return -1;
        case 0:
-               wp->ww_state = WWS_INCHILD;
                wwenviron(wp);
                wwenviron(wp);
-               return 0;
+               execv(file, &argv0);
+               perror(file);
+               exit(1);
        default:
        default:
+               wp->ww_pid = pid;
                wp->ww_state = WWS_HASPROC;
                (void) close(wp->ww_tty);
                wp->ww_tty = -1;
                wp->ww_state = WWS_HASPROC;
                (void) close(wp->ww_tty);
                wp->ww_tty = -1;
-               return wp->ww_pid;
+               return pid;
        }
 }
        }
 }