properly create new session/controlling terminal in forkpty

This commit is contained in:
Rich Felker 2011-04-20 21:01:42 -04:00
parent 4921ce0867
commit 10d7561db5
1 changed files with 4 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include <pty.h>
#include <unistd.h>
#include <sys/ioctl.h>
int forkpty(int *m, char *name, const struct termios *tio, const struct winsize *ws)
{
@ -10,10 +11,12 @@ int forkpty(int *m, char *name, const struct termios *tio, const struct winsize
pid = fork();
if (!pid) {
close(*m);
setsid();
ioctl(s, TIOCSCTTY, (char *)0);
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
close(s);
if (s>2) close(s);
return 0;
}
close(s);