2004-03-25 23:03:57 +00:00
|
|
|
#include <u.h>
|
2004-04-15 02:04:30 +00:00
|
|
|
#include <signal.h>
|
2004-04-19 23:03:46 +00:00
|
|
|
#include <libc.h>
|
2004-03-25 23:03:57 +00:00
|
|
|
#include "term.h"
|
|
|
|
|
2004-09-21 01:11:28 +00:00
|
|
|
static void
|
|
|
|
sys(char *buf)
|
|
|
|
{
|
|
|
|
char buf2[100];
|
|
|
|
char *f[20];
|
|
|
|
int nf, pid;
|
|
|
|
|
|
|
|
strcpy(buf2, buf);
|
|
|
|
nf = tokenize(buf2, f, nelem(f));
|
|
|
|
f[nf] = nil;
|
|
|
|
switch(pid = fork()){
|
|
|
|
case 0:
|
|
|
|
execvp(f[0], f);
|
|
|
|
_exits("oops");
|
|
|
|
default:
|
|
|
|
waitpid();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-25 23:03:57 +00:00
|
|
|
int
|
2004-04-15 02:04:30 +00:00
|
|
|
rcstart(int argc, char **argv, int *pfd, int *tfd)
|
2004-03-25 23:03:57 +00:00
|
|
|
{
|
2004-04-16 15:27:29 +00:00
|
|
|
int fd[2], i, pid;
|
2004-03-25 23:03:57 +00:00
|
|
|
char *xargv[3];
|
|
|
|
char slave[256];
|
|
|
|
int sfd;
|
|
|
|
|
|
|
|
if(argc == 0){
|
|
|
|
argc = 2;
|
|
|
|
argv = xargv;
|
|
|
|
argv[0] = getenv("SHELL");
|
|
|
|
if(argv[0] == 0)
|
|
|
|
argv[0] = "rc";
|
|
|
|
argv[1] = "-i";
|
|
|
|
argv[2] = 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* fd0 is slave (tty), fd1 is master (pty)
|
|
|
|
*/
|
|
|
|
fd[0] = fd[1] = -1;
|
|
|
|
if(getpts(fd, slave) < 0)
|
2004-03-26 00:09:27 +00:00
|
|
|
sysfatal("getpts: %r\n");
|
2004-03-25 23:03:57 +00:00
|
|
|
switch(pid = fork()) {
|
|
|
|
case 0:
|
|
|
|
putenv("TERM", "9term");
|
|
|
|
sfd = childpty(fd, slave);
|
|
|
|
dup(sfd, 0);
|
|
|
|
dup(sfd, 1);
|
|
|
|
dup(sfd, 2);
|
2004-09-21 01:11:28 +00:00
|
|
|
sys("stty tabs -onlcr onocr icanon echo erase '^h' intr '^?'");
|
2004-04-19 23:03:46 +00:00
|
|
|
if(noecho)
|
2004-09-21 01:11:28 +00:00
|
|
|
sys("stty -echo");
|
2004-04-16 15:27:29 +00:00
|
|
|
for(i=3; i<100; i++)
|
|
|
|
close(i);
|
2004-09-21 01:11:28 +00:00
|
|
|
signal(SIGINT, SIG_DFL);
|
|
|
|
signal(SIGHUP, SIG_DFL);
|
|
|
|
signal(SIGTERM, SIG_DFL);
|
2004-03-25 23:03:57 +00:00
|
|
|
execvp(argv[0], argv);
|
|
|
|
fprint(2, "exec %s failed: %r\n", argv[0]);
|
|
|
|
_exits("oops");
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
sysfatal("proc failed: %r");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*pfd = fd[1];
|
2004-04-16 15:27:29 +00:00
|
|
|
close(fd[0]);
|
|
|
|
if(tfd){
|
|
|
|
if((*tfd = open(slave, OREAD)) < 0)
|
|
|
|
sysfatal("parent open %s: %r", slave);
|
|
|
|
}
|
2004-03-25 23:03:57 +00:00
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
|