chiark / gitweb /
update TODO
[elogind.git] / src / getty-generator / getty-generator.c
index aeb6d71d740dede6757b61d6507bf1382a9e4e27..6a4aa2c1d9a133d793b06d5d1c761ffd44d893b2 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include "log.h"
 #include "util.h"
@@ -92,12 +93,39 @@ static int add_container_getty(const char *tty) {
         return add_symlink("container-getty@.service", n);
 }
 
+static int verify_tty(const char *name) {
+        _cleanup_close_ int fd = -1;
+        const char *p;
+
+        /* Some TTYs are weird and have been enumerated but don't work
+         * when you try to use them, such as classic ttyS0 and
+         * friends. Let's check that and open the device and run
+         * isatty() on it. */
+
+        p = strappenda("/dev/", name);
+
+        /* O_NONBLOCK is essential here, to make sure we don't wait
+         * for DCD */
+        fd = open(p, O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC|O_NOFOLLOW);
+        if (fd < 0)
+                return -errno;
+
+        errno = 0;
+        if (isatty(fd) <= 0)
+                return errno ? -errno : -EIO;
+
+        return 0;
+}
+
 int main(int argc, char *argv[]) {
 
         static const char virtualization_consoles[] =
                 "hvc0\0"
                 "xvc0\0"
-                "hvsi0\0";
+                "hvsi0\0"
+                "sclp_line0\0"
+                "ttysclp0\0"
+                "3270!tty1\0";
 
         _cleanup_free_ char *active = NULL;
         const char *j;
@@ -178,6 +206,9 @@ int main(int argc, char *argv[]) {
                         if (isempty(tty) || tty_is_vc(tty))
                                 continue;
 
+                        if (verify_tty(tty) < 0)
+                                continue;
+
                         /* We assume that gettys on virtual terminals are
                          * started via manual configuration and do this magic
                          * only for non-VC terminals. */