1 8ad51794 2004-03-25 devnull #include <u.h>
2 4dcd9af2 2004-04-15 devnull #include <signal.h>
3 b4a659b6 2004-04-19 devnull #include <libc.h>
4 8ad51794 2004-03-25 devnull #include "term.h"
6 c6687d45 2004-09-21 devnull static void
7 60535a5f 2004-12-26 devnull sys(char *buf, int devnull)
9 c6687d45 2004-09-21 devnull char buf2[100];
10 c6687d45 2004-09-21 devnull char *f[20];
11 c6687d45 2004-09-21 devnull int nf, pid;
13 60535a5f 2004-12-26 devnull notedisable("sys: child");
14 c6687d45 2004-09-21 devnull strcpy(buf2, buf);
15 c6687d45 2004-09-21 devnull nf = tokenize(buf2, f, nelem(f));
16 c6687d45 2004-09-21 devnull f[nf] = nil;
17 c6687d45 2004-09-21 devnull switch(pid = fork()){
19 60535a5f 2004-12-26 devnull close(1);
20 60535a5f 2004-12-26 devnull open("/dev/null", OREAD);
21 60535a5f 2004-12-26 devnull close(2);
22 60535a5f 2004-12-26 devnull open("/dev/null", OREAD);
23 c6687d45 2004-09-21 devnull execvp(f[0], f);
24 60535a5f 2004-12-26 devnull _exit(2);
26 c6687d45 2004-09-21 devnull waitpid();
31 4dcd9af2 2004-04-15 devnull rcstart(int argc, char **argv, int *pfd, int *tfd)
33 a2705f20 2004-04-16 devnull int fd[2], i, pid;
34 8ad51794 2004-03-25 devnull char *xargv[3];
35 8ad51794 2004-03-25 devnull char slave[256];
38 8ad51794 2004-03-25 devnull if(argc == 0){
39 8ad51794 2004-03-25 devnull argc = 2;
40 8ad51794 2004-03-25 devnull argv = xargv;
41 8ad51794 2004-03-25 devnull argv[0] = getenv("SHELL");
42 8ad51794 2004-03-25 devnull if(argv[0] == 0)
43 8ad51794 2004-03-25 devnull argv[0] = "rc";
44 8ad51794 2004-03-25 devnull argv[1] = "-i";
45 8ad51794 2004-03-25 devnull argv[2] = 0;
48 8ad51794 2004-03-25 devnull * fd0 is slave (tty), fd1 is master (pty)
50 8ad51794 2004-03-25 devnull fd[0] = fd[1] = -1;
51 60535a5f 2004-12-26 devnull if(getpts(fd, slave) < 0){
53 75024f0f 2004-03-26 devnull sysfatal("getpts: %r\n");
56 55d360f6 2005-07-13 devnull * notedisable("sys: window size change");
58 55d360f6 2005-07-13 devnull * Can't disable because will be inherited by other programs
59 55d360f6 2005-07-13 devnull * like if you run an xterm from the prompt, and then xterm's
60 1a24aaca 2005-07-21 devnull * resizes won't get handled right. Sigh.
62 1a24aaca 2005-07-21 devnull * Can't not disable because when we stty below we'll get a
63 1a24aaca 2005-07-21 devnull * signal, which will drop us into the thread library note handler,
64 1a24aaca 2005-07-21 devnull * which will get all confused because we just forked and thus
65 1a24aaca 2005-07-21 devnull * have an unknown pid.
67 1a24aaca 2005-07-21 devnull * So disable it internally. ARGH!
69 1a24aaca 2005-07-21 devnull notifyoff("sys: window size change");
71 60535a5f 2004-12-26 devnull pid = fork();
72 60535a5f 2004-12-26 devnull switch(pid){
74 8ad51794 2004-03-25 devnull putenv("TERM", "9term");
75 8ad51794 2004-03-25 devnull sfd = childpty(fd, slave);
76 8ad51794 2004-03-25 devnull dup(sfd, 0);
77 8ad51794 2004-03-25 devnull dup(sfd, 1);
78 8ad51794 2004-03-25 devnull dup(sfd, 2);
79 60535a5f 2004-12-26 devnull sys("stty tabs -onlcr icanon echo erase '^h' intr '^?'", 0);
80 60535a5f 2004-12-26 devnull sys("stty onocr", 1); /* not available on mac */
81 b4a659b6 2004-04-19 devnull if(noecho)
82 60535a5f 2004-12-26 devnull sys("stty -echo", 0);
83 a2705f20 2004-04-16 devnull for(i=3; i<100; i++)
84 a2705f20 2004-04-16 devnull close(i);
85 c6687d45 2004-09-21 devnull signal(SIGINT, SIG_DFL);
86 c6687d45 2004-09-21 devnull signal(SIGHUP, SIG_DFL);
87 c6687d45 2004-09-21 devnull signal(SIGTERM, SIG_DFL);
88 8ad51794 2004-03-25 devnull execvp(argv[0], argv);
89 8ad51794 2004-03-25 devnull fprint(2, "exec %s failed: %r\n", argv[0]);
90 60535a5f 2004-12-26 devnull _exit(2);
93 8ad51794 2004-03-25 devnull sysfatal("proc failed: %r");
96 8ad51794 2004-03-25 devnull *pfd = fd[1];
97 a2705f20 2004-04-16 devnull close(fd[0]);
99 a2705f20 2004-04-16 devnull if((*tfd = open(slave, OREAD)) < 0)
100 a2705f20 2004-04-16 devnull sysfatal("parent open %s: %r", slave);
102 8ad51794 2004-03-25 devnull return pid;