9 sys(char *buf, int devnull)
15 notedisable("sys: child");
17 nf = tokenize(buf2, f, nelem(f));
22 open("/dev/null", OREAD);
24 open("/dev/null", OREAD);
29 noteenable("sys: child");
34 rcstart(int argc, char **argv, int *pfd, int *tfd)
44 argv[0] = getenv("SHELL");
52 argv[0] = malloc(strlen(cmd)+2);
53 strcpy(argv[0]+1, cmd);
58 * fd0 is slave (tty), fd1 is master (pty)
61 if(getpts(fd, slave) < 0){
63 sysfatal("getpts: %r\n");
66 * notedisable("sys: window size change");
68 * Can't disable because will be inherited by other programs
69 * like if you run an xterm from the prompt, and then xterm's
70 * resizes won't get handled right. Sigh.
72 * Can't not disable because when we stty below we'll get a
73 * signal, which will drop us into the thread library note handler,
74 * which will get all confused because we just forked and thus
75 * have an unknown pid.
77 * So disable it internally. ARGH!
79 notifyoff("sys: window size change");
81 // This used to be TERM=9term but we don't know of anything that cares.
82 // Worse, various cc have started assuming that TERM != dumb implies
83 // the ability to understand ANSI escape codes. 9term will squelch them
84 // but acme win does not.
85 putenv("TERM", "dumb");
87 // Set $termprog to 9term or win for those who care about what kind of
88 // dumb terminal this is.
89 putenv("termprog", (char*)termprog);
94 sfd = childpty(fd, slave);
98 sys("stty tabs -onlcr icanon echo erase '^h' intr '^?'", 0);
99 sys("stty onocr", 1); /* not available on mac */
102 signal(SIGINT, SIG_DFL);
103 signal(SIGHUP, SIG_DFL);
104 signal(SIGTERM, SIG_DFL);
106 fprint(2, "exec %s failed: %r\n", argv[0]);
110 sysfatal("proc failed: %r");
116 if((*tfd = open(slave, OREAD)) < 0)
117 sysfatal("parent open %s: %r", slave);
129 echoed(char *p, int n)
133 memmove(echo.buf, echo.buf+echo.r, echo.w-echo.r);
137 if(echo.w+n > sizeof echo.buf)
139 if(echo.w+n > sizeof echo.buf)
141 memmove(echo.buf+echo.w, p, n);
147 echocancel(char *p, int n)
153 if(echo.r < echo.w) {
154 if(echo.buf[echo.r] == p[i]) {
158 if(echo.buf[echo.r] == '\n' && p[i] == '\r')
161 if(i+2 <= n && p[i+1] == ' ' && p[i+2] == 0x08)
171 memmove(p, p+i, n-i);
176 dropcrnl(char *p, int n)
180 for(r=w=p; r<p+n; r++) {
181 if(r+1<p+n && *r == '\r' && *(r+1) == '\n')
184 if(r+2<=p+n && *(r+1) == ' ' && *(r+2) == 0x08)