gettimeofday: port recent C++ fix to Emacs
[gnulib.git] / tests / test-login_tty.c
index cd08f54..ddd5067 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of login_tty() function.
-   Copyright (C) 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010-2013 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
 /* 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 @@ 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;
 }