changeset 13690:4a7853b78e64

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 <mats.andersson@gisladisker.se>.
author Bruno Haible <bruno@clisp.org>
date Fri, 17 Sep 2010 04:00:49 +0200
parents af3a7152efba
children 353ba0b294e1
files ChangeLog modules/login_tty-tests tests/test-login_tty.c
diffstat 3 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-09-16  Bruno Haible  <bruno@clisp.org>
+
+	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 <mats.andersson@gisladisker.se>.
+
 2010-09-16  Bruno Haible  <bruno@clisp.org>
 
 	New module 'tcgetsid'.
--- a/modules/login_tty-tests
+++ b/modules/login_tty-tests
@@ -3,6 +3,7 @@
 
 Depends-on:
 openpty
+tcgetsid
 
 configure.ac:
 
--- a/tests/test-login_tty.c
+++ b/tests/test-login_tty.c
@@ -19,8 +19,12 @@
 /* Specification.  */
 extern int login_tty (int);
 
+#include <errno.h>
 #include <pty.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
 
 int
 main ()
@@ -48,5 +52,23 @@
       }
   }
 
+  /* 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;
 }