lint
[unix-history] / usr / src / usr.bin / window / wwspawn.c
index 916be00..bfe4898 100644 (file)
@@ -1,71 +1,44 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwspawn.c   1.6 83/07/26";
+static char *sccsid = "@(#)wwspawn.c   3.7 84/01/13";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
-
-extern int _wwdtablesize;
-extern char _wwtermcap[];
-
-wwfork(wp)
+#include <signal.h>
+
+/*
+ * There is a dead lock with vfork and closing of pseudo-ports.
+ * So we have to be sneaky.
+ */
+/*VARARGS3*/
+wwspawn(wp, file, argv0)
 register struct ww *wp;
 register struct ww *wp;
+char *file, *argv0;
 {
 {
-       switch (wp->ww_pid = fork()) {
+       extern int errno;
+       extern char *sys_errlist[];
+       int pid;
+
+       (void) sighold(SIGCHLD);
+       switch (pid = vfork()) {
        case -1:
        case -1:
+               wwerrno = WWE_SYS;
+               (void) sigrelse(SIGCHLD);
                return -1;
        case 0:
                return -1;
        case 0:
-               wp->ww_state = WW_INCHILD;
                wwenviron(wp);
                wwenviron(wp);
-               return 0;
+               errno = 0;
+               execv(file, &argv0);
+               _exit(1);
        default:
        default:
-               wp->ww_state = WW_HASPROC;
-               close(wp->ww_tty);
-               wp->ww_tty = -1;
-               return wp->ww_pid;
-       }
-}
-
-#define TERM   "TERM=window"
-#define TERMCAP        "TERMCAP=WW|window|window package:\
-       :cr=^M:nl=^J:bl=^G:\
-       :al=\\EL:am:le=^H:bs:cd=\\EJ:ce=\\EK:cl=\\EE:cm=\\EY%%+ %%+ :\
-       :co#%d:dc=\\EN:dl=\\EM:do=\\EB:ei=\\EO:ho=\\EH:li#%d:im=\\E@:mi:\
-       :nd=\\EC:ta=^I:pt:up=\\EA:"
-static char *env[100];
-static char buf[1024];
-extern char **environ;
-extern char _wwkeys[];
-
-wwenviron(wp)
-register struct ww *wp;
-{
-       register i;
-       register char **p, **q;
-       char **termcap = 0;
-
-       dup2(wp->ww_tty, 0);
-       dup2(wp->ww_tty, 1);
-       dup2(wp->ww_tty, 2);
-       for (i = _wwdtablesize - 1; i > 2; i--)
-               close(i);
-
-       i = open("/dev/tty");
-       ioctl(i, TIOCNOTTY, 0);
-       close(i);
-       open(wp->ww_ttyname, 0);
-
-       for (p = environ, q = env; *p; p++, q++) {
-               if (strncmp(*p, "TERM=", 5) == 0)
-                       *q = TERM;
-               else if (strncmp(*p, "TERMCAP=", 8) == 0)
-                       termcap = q;
-               else
-                       *q = *p;
+               if (errno != 0) {
+                       wwerrno = WWE_SYS;
+                       (void) sigrelse(SIGCHLD);
+                       return -1;
+               } else {
+                       wp->ww_pid = pid;
+                       wp->ww_state = WWS_HASPROC;
+                       (void) sigrelse(SIGCHLD);
+                       return pid;
+               }
        }
        }
-       if (termcap == 0)
-               termcap = q++;
-       *q = 0;
-       *termcap = sprintf(buf, TERMCAP, wp->ww_i.ncol, wp->ww_i.nrow);
-       strcat(buf, _wwkeys);
-       environ = env;
 }
 }