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");
57 argv[0] = malloc(strlen(cmd)+2);
58 strcpy(argv[0]+1, cmd);
63 * fd0 is slave (tty), fd1 is master (pty)
66 if(getpts(fd, slave) < 0){
68 sysfatal("getpts: %r\n");
71 * notedisable("sys: window size change");
73 * Can't disable because will be inherited by other programs
74 * like if you run an xterm from the prompt, and then xterm's
75 * resizes won't get handled right. Sigh.
77 * Can't not disable because when we stty below we'll get a
78 * signal, which will drop us into the thread library note handler,
79 * which will get all confused because we just forked and thus
80 * have an unknown pid.
82 * So disable it internally. ARGH!
84 notifyoff("sys: window size change");
86 // This used to be TERM=9term but we don't know of anything that cares.
87 // Worse, various cc have started assuming that TERM != dumb implies
88 // the ability to understand ANSI escape codes. 9term will squelch them
89 // but acme win does not.
90 putenv("TERM", "dumb");
92 // Set $termprog to 9term or win for those who care about what kind of
93 // dumb terminal this is.
94 putenv("termprog", (char*)termprog);
95 putenv("TERM_PROGRAM", (char*)termprog);
100 sfd = childpty(fd, slave);
104 sys("stty tabs -onlcr icanon echo erase '^h' intr '^?'", 0);
105 sys("stty onocr", 1); /* not available on mac */
108 signal(SIGINT, SIG_DFL);
109 signal(SIGHUP, SIG_DFL);
110 signal(SIGTERM, SIG_DFL);
112 fprint(2, "exec %s failed: %r\n", argv[0]);
116 sysfatal("proc failed: %r");
122 if((*tfd = open(slave, OREAD)) < 0)
123 sysfatal("parent open %s: %r", slave);
135 echoed(char *p, int n)
139 memmove(echo.buf, echo.buf+echo.r, echo.w-echo.r);
143 if(echo.w+n > sizeof echo.buf)
145 if(echo.w+n > sizeof echo.buf)
147 memmove(echo.buf+echo.w, p, n);
153 echocancel(char *p, int n)
159 if(echo.r < echo.w) {
160 if(echo.buf[echo.r] == p[i]) {
164 if(echo.buf[echo.r] == '\n' && p[i] == '\r')
167 if(i+2 <= n && p[i+1] == ' ' && p[i+2] == 0x08)
177 memmove(p, p+i, n-i);
182 dropcrnl(char *p, int n)
186 for(r=w=p; r<p+n; r++) {
187 if(r+1<p+n && *r == '\r' && *(r+1) == '\n')
190 if(r+2<=p+n && *(r+1) == ' ' && *(r+2) == 0x08)