X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flogin_tty.c;h=e07f1607727b66c61d4f335afa897007d8fc96b7;hb=0c6fd3b84775ca4cf1045d4cc07a2dff4c73f29b;hp=e5ec248eadff7a39702e01f2e59ce35d01e728b4;hpb=61d8728839e77d615f102f12a06bbd3928d55cf8;p=gnulib.git diff --git a/lib/login_tty.c b/lib/login_tty.c index e5ec248ea..e07f16077 100644 --- a/lib/login_tty.c +++ b/lib/login_tty.c @@ -1,6 +1,6 @@ /* Assign a given terminal as controlling terminal and as standard input, standard output, standard error of the current process. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include #include +#include int login_tty (int slave_fd) @@ -31,15 +32,22 @@ login_tty (int slave_fd) setsid (); /* Make fd the controlling terminal for the current process. - On Solaris: A terminal becomes the controlling terminal of a session - if it is being open()ed, at a moment when - 1. it is not already the controlling terminal of some session, and - 2. the process that open()s it is a session leader that does not have - a controlling terminal. - We assume condition 1, try to ensure condition 2, and then open() it. */ + On BSD and OSF/1: There is ioctl TIOCSCTTY for this purpose. + On Solaris: + A terminal becomes the controlling terminal of a session + if it is being open()ed, at a moment when + 1. it is not already the controlling terminal of some session, and + 2. the process that open()s it is a session leader that does not have + a controlling terminal. + We assume condition 1, try to ensure condition 2, and then open() it. + */ for (i = 0; i < 3; i++) if (i != slave_fd) close (i); +#ifdef TIOCSCTTY + if (ioctl (slave_fd, TIOCSCTTY, NULL) < 0) + return -1; +#else { char *slave_name; int dummy_fd; @@ -52,6 +60,7 @@ login_tty (int slave_fd) return -1; close (dummy_fd); } +#endif /* Assign fd to the standard input, standard output, and standard error of the current process. */