From b7c95ee2f21751f24fd6245a8545cc8b3c555e60 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 17 Sep 2010 04:00:49 +0200 Subject: [PATCH] login_tty: Stricter unit test. * modules/login_tty-tests (Depends-on): Add tcgetsid. * tests/test-login_tty.c (main): Also check the results of tcgetpgrp() and tcgetsid() after login_tty. Reported by Mats Erik Andersson . --- ChangeLog | 8 ++++++++ modules/login_tty-tests | 1 + tests/test-login_tty.c | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/ChangeLog b/ChangeLog index d86265a15..25c63a520 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2010-09-16 Bruno Haible + login_tty: Stricter unit test. + * modules/login_tty-tests (Depends-on): Add tcgetsid. + * tests/test-login_tty.c (main): Also check the results of tcgetpgrp() + and tcgetsid() after login_tty. + Reported by Mats Erik Andersson . + +2010-09-16 Bruno Haible + New module 'tcgetsid'. * lib/tcgetsid.c: New file. * m4/tcgetsid.m4: New file. diff --git a/modules/login_tty-tests b/modules/login_tty-tests index b9cbbd739..306b0ebe1 100644 --- a/modules/login_tty-tests +++ b/modules/login_tty-tests @@ -3,6 +3,7 @@ tests/test-login_tty.c Depends-on: openpty +tcgetsid configure.ac: diff --git a/tests/test-login_tty.c b/tests/test-login_tty.c index cd08f54b4..8560c5a6d 100644 --- a/tests/test-login_tty.c +++ b/tests/test-login_tty.c @@ -19,8 +19,12 @@ /* Specification. */ extern int login_tty (int); +#include #include #include +#include +#include +#include int main () @@ -48,5 +52,23 @@ main () } } + /* From here on, we cannot use stderr for error messages any more. + If a test fails, just abort. */ + + /* Check that fd = 0, 1, 2 are now open to the controlling terminal for the + current process and that it is a session of its own. */ + { + int fd; + for (fd = 0; fd < 3; fd++) + if (!(tcgetpgrp (fd) == getpid ())) + abort (); + for (fd = 0; fd < 3; fd++) + { + int sid = tcgetsid (fd); + if (!(sid == -1 ? errno == ENOSYS : sid == getpid ())) + abort (); + } + } + return 0; } -- 2.11.0