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);
33 rcstart(int argc, char **argv, int *pfd, int *tfd)
43 argv[0] = getenv("SHELL");
51 argv[0] = malloc(strlen(cmd)+2);
52 strcpy(argv[0]+1, cmd);
57 * fd0 is slave (tty), fd1 is master (pty)
60 if(getpts(fd, slave) < 0){
62 sysfatal("getpts: %r\n");
65 * notedisable("sys: window size change");
67 * Can't disable because will be inherited by other programs
68 * like if you run an xterm from the prompt, and then xterm's
69 * resizes won't get handled right. Sigh.
71 * Can't not disable because when we stty below we'll get a
72 * signal, which will drop us into the thread library note handler,
73 * which will get all confused because we just forked and thus
74 * have an unknown pid.
76 * So disable it internally. ARGH!
78 notifyoff("sys: window size change");
80 // This used to be TERM=9term but we don't know of anything that cares.
81 // Worse, various cc have started assuming that TERM != dumb implies
82 // the ability to understand ANSI escape codes. 9term will squelch them
83 // but acme win does not.
84 putenv("TERM", "dumb");
86 // Set $termprog to 9term or win for those who care about what kind of
87 // dumb terminal this is.
88 putenv("termprog", (char*)termprog);
93 sfd = childpty(fd, slave);
97 sys("stty tabs -onlcr icanon echo erase '^h' intr '^?'", 0);
98 sys("stty onocr", 1); /* not available on mac */
101 signal(SIGINT, SIG_DFL);
102 signal(SIGHUP, SIG_DFL);
103 signal(SIGTERM, SIG_DFL);
105 fprint(2, "exec %s failed: %r\n", argv[0]);
109 sysfatal("proc failed: %r");
115 if((*tfd = open(slave, OREAD)) < 0)
116 sysfatal("parent open %s: %r", slave);
128 echoed(char *p, int n)
132 memmove(echo.buf, echo.buf+echo.r, echo.w-echo.r);
136 if(echo.w+n > sizeof echo.buf)
138 if(echo.w+n > sizeof echo.buf)
140 memmove(echo.buf+echo.w, p, n);
146 echocancel(char *p, int n)
152 if(echo.r < echo.w) {
153 if(echo.buf[echo.r] == p[i]) {
157 if(echo.buf[echo.r] == '\n' && p[i] == '\r')
160 if(i+2 <= n && p[i+1] == ' ' && p[i+2] == 0x08)
170 memmove(p, p+i, n-i);
175 dropcrnl(char *p, int n)
179 for(r=w=p; r<p+n; r++) {
180 if(r+1<p+n && *r == '\r' && *(r+1) == '\n')
183 if(r+2<=p+n && *(r+1) == ' ' && *(r+2) == 0x08)