plan9port/src/cmd/9term/rcstart.c

64 lines
1 KiB
C
Raw Normal View History

2004-03-25 23:03:57 +00:00
#include <u.h>
#include <libc.h>
#if 0
#include <sys/wait.h>
#endif
#include <signal.h>
2004-03-25 23:03:57 +00:00
#include "term.h"
/*
* Somehow we no longer automatically exit
* when the shell exits; hence the SIGCHLD stuff.
* Something that can be fixed? Axel.
*/
static int pid;
2004-03-25 23:03:57 +00:00
int
rcstart(int argc, char **argv, int *pfd, int *tfd)
2004-03-25 23:03:57 +00:00
{
int fd[2];
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-03-26 02:08:44 +00:00
system("stty tabs -onlcr -echo erase '^h' intr '^?'");
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];
if(tfd)
*tfd = fd[0];
else
close(fd[0]);
2004-03-25 23:03:57 +00:00
return pid;
}