bug fix, 4.3BSD/usr.bin/41
[unix-history] / usr / src / usr.bin / window / wwenviron.c
CommitLineData
aa149fde 1#ifndef lint
20029082 2static char sccsid[] = "@(#)wwenviron.c 3.15 %G%";
aa149fde
EW
3#endif
4
60de5df9
EW
5/*
6 * Copyright (c) 1983 Regents of the University of California,
7 * All rights reserved. Redistribution permitted subject to
8 * the terms of the Berkeley Software License Agreement.
9 */
10
aa149fde 11#include "ww.h"
1e40e125 12#include <sys/signal.h>
aa149fde 13
224ba859
EW
14/*
15 * Set up the environment of this process to run in window 'wp'.
224ba859 16 */
aa149fde
EW
17wwenviron(wp)
18register struct ww *wp;
19{
20 register i;
950f1780 21 int pgrp = getpid();
aa149fde 22
7ecf4dca
EW
23 if ((i = open("/dev/tty", 0)) < 0)
24 goto bad;
20029082 25 if (ioctl(i, TIOCNOTTY, (char *)0) < 0)
7ecf4dca 26 goto bad;
aa149fde 27 (void) close(i);
7ecf4dca
EW
28 if ((i = wp->ww_socket) < 0 && (i = open(wp->ww_ttyname, 2)) < 0)
29 goto bad;
eec72f58
EW
30 (void) dup2(i, 0);
31 (void) dup2(i, 1);
32 (void) dup2(i, 2);
33 for (i = wwdtablesize - 1; i > 2; i--)
34 (void) close(i);
20029082 35 (void) ioctl(0, TIOCSPGRP, (char *)&pgrp);
950f1780 36 (void) setpgrp(pgrp, pgrp);
1e40e125 37 (void) signal(SIGPIPE, SIG_DFL);
a6833679 38 (void) sprintf(wwwintermcap, "TERMCAP=%sco#%d:li#%d:%s%s%s%s%s%s%s",
78be6843
EW
39 WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr,
40 wwavailmodes & WWM_REV ? WWT_REV : "",
a6833679 41 wwavailmodes & WWM_BLK ? WWT_BLK : "",
78be6843
EW
42 wwavailmodes & WWM_UL ? WWT_UL : "",
43 wwavailmodes & WWM_GRP ? WWT_GRP : "",
a6833679
EW
44 wwavailmodes & WWM_DIM ? WWT_DIM : "",
45 wwavailmodes & WWM_USR ? WWT_USR : "",
78be6843 46 wwkeys);
7ecf4dca
EW
47 return 0;
48bad:
49 wwerrno = WWE_SYS;
50 return -1;
aa149fde 51}