-
- i = open("/dev/tty", 0);
- if (i < 0) {
- perror("/dev/tty");
- return;
- }
- if (ioctl(i, (int)TIOCNOTTY, (char *)0) < 0) {
- perror("ioctl(TIOCNOTTY)");
- return;
- }
- (void) close(i);
- if (open(wp->ww_ttyname, 0) < 0) {
- perror(wp->ww_ttyname);
- 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;
- }
- 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)
- (void) strcat(tbuf, WWT_REV);
- if (wwavailmodes & WWM_UL)
- (void) strcat(tbuf, WWT_UL);
- (void) strcat(tbuf, wwkeys);
- environ = env;
+ (void) ioctl(0, TIOCSPGRP, (char *)&pgrp);
+ (void) setpgrp(pgrp, pgrp);
+ /* SIGPIPE is the only one we ignore */
+ (void) signal(SIGPIPE, SIG_DFL);
+ (void) sigsetmask(0);
+ /*
+ * Two conditions that make destructive setenv ok:
+ * 1. setenv() copies the string,
+ * 2. we've already called tgetent which copies the termcap entry.
+ */
+ (void) sprintf(buf, "%sco#%d:li#%d:%s",
+ WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr, wwwintermcap);
+ (void) setenv("TERMCAP", buf, 1);
+ (void) sprintf(buf, "%d", wp->ww_id + 1);
+ (void) setenv("WINDOW_ID", buf, 1);
+ return 0;
+bad:
+ wwerrno = WWE_SYS;
+ return -1;