X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fgetty-generator%2Fgetty-generator.c;h=08b3b1e7dfbcf9eaabb563602f7f2479544f4ac5;hb=9d16d0c7d0b05e3ff278c3c95e1f2f871f348dd3;hp=feb58156ea1687409f9f81e68ac7d312dc102efb;hpb=207d1d0922d4e668cc6fac98be39e5a8b83ebc8a;p=elogind.git diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index feb58156e..08b3b1e7d 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "log.h" #include "util.h" @@ -92,12 +93,38 @@ 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"; _cleanup_free_ char *active = NULL; const char *j; @@ -147,7 +174,7 @@ int main(int argc, char *argv[]) { t = tty; /* Then, make sure it's actually a pty */ - t = path_startswith(tty, "pts/"); + t = path_startswith(t, "pts/"); if (!t) continue; @@ -178,6 +205,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. */