From f8170e41fe131d129edab0370716adf666f67cea Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 7 May 2009 13:49:48 +0000 Subject: Add tcsetsid(3). The entire world seems to use the non-standard TIOCSCTTY ioctl to make a TTY a controlling terminal of a session. Even though tcsetsid(3) is also non-standard, I think it's a lot better to use in our own source code, mainly because it's similar to tcsetpgrp(), tcgetpgrp() and tcgetsid(). I stole the idea from QNX. They do it the other way around; their TIOCSCTTY is just a wrapper around tcsetsid(). tcsetsid() then calls into an IPC framework. --- lib/libutil/login_tty.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/libutil') diff --git a/lib/libutil/login_tty.c b/lib/libutil/login_tty.c index 51299bd..a14e244 100644 --- a/lib/libutil/login_tty.c +++ b/lib/libutil/login_tty.c @@ -37,17 +37,21 @@ static char sccsid[] = "@(#)login_tty.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include -#include #include #include +#include #include int login_tty(int fd) { - (void) setsid(); - if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1) + pid_t s; + + s = setsid(); + if (s == -1) + return (-1); + if (tcsetsid(fd, s) == -1) return (-1); (void) dup2(fd, 0); (void) dup2(fd, 1); -- cgit v1.1