about summary refs log tree commit diff
path: root/src/misc
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-20 21:01:42 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-20 21:01:42 -0400
commit10d7561db5d51231939fa0b42d17eaac2bff6938 (patch)
treecfcaf6d875c005d258cc6fb2376d45299a85be4e /src/misc
parent4921ce08673d14e53b3931b8536238d944a2c1ce (diff)
downloadmusl-10d7561db5d51231939fa0b42d17eaac2bff6938.tar.gz
musl-10d7561db5d51231939fa0b42d17eaac2bff6938.tar.xz
musl-10d7561db5d51231939fa0b42d17eaac2bff6938.zip
properly create new session/controlling terminal in forkpty
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/forkpty.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/misc/forkpty.c b/src/misc/forkpty.c
index 2d1b0ae2..0bbf2de2 100644
--- a/src/misc/forkpty.c
+++ b/src/misc/forkpty.c
@@ -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);