1 /* Test of login_tty() function.
2 Copyright (C) 2010-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 extern int login_tty (int);
35 /* Open a pseudo-terminal, as a master-slave pair. */
37 int res = openpty (&master, &slave, NULL, NULL, NULL);
40 fprintf (stderr, "openpty returned %d\n", res);
45 /* Create a new session and make it the controlling tty of this session. */
47 int res = login_tty (slave);
50 fprintf (stderr, "login_tty failed\n");
55 /* From here on, we cannot use stderr for error messages any more.
56 If a test fails, just abort. */
58 /* Check that fd = 0, 1, 2 are now open to the controlling terminal for the
59 current process and that it is a session of its own. */
62 for (fd = 0; fd < 3; fd++)
63 if (!(tcgetpgrp (fd) == getpid ()))
65 for (fd = 0; fd < 3; fd++)
67 int sid = tcgetsid (fd);
68 if (!(sid == -1 ? errno == ENOSYS : sid == getpid ()))