提交 10d7561d 编写于 作者: R Rich Felker

properly create new session/controlling terminal in forkpty

上级 4921ce08
#include <pty.h> #include <pty.h>
#include <unistd.h> #include <unistd.h>
#include <sys/ioctl.h>
int forkpty(int *m, char *name, const struct termios *tio, const struct winsize *ws) 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 ...@@ -10,10 +11,12 @@ int forkpty(int *m, char *name, const struct termios *tio, const struct winsize
pid = fork(); pid = fork();
if (!pid) { if (!pid) {
close(*m); close(*m);
setsid();
ioctl(s, TIOCSCTTY, (char *)0);
dup2(s, 0); dup2(s, 0);
dup2(s, 1); dup2(s, 1);
dup2(s, 2); dup2(s, 2);
close(s); if (s>2) close(s);
return 0; return 0;
} }
close(s); close(s);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册