diff options
-rw-r--r-- | loginutils/getty.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/loginutils/getty.c b/loginutils/getty.c index 230846008..3496f0284 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
@@ -556,10 +556,12 @@ int getty_main(int argc UNUSED_PARAM, char **argv) | |||
556 | * In this case (setsid failed) we may still have ctty, | 556 | * In this case (setsid failed) we may still have ctty, |
557 | * and it may be different from tty we need to control! | 557 | * and it may be different from tty we need to control! |
558 | * If we still have ctty, on Linux ioctl(TIOCSCTTY) | 558 | * If we still have ctty, on Linux ioctl(TIOCSCTTY) |
559 | * (which we are going to call a bit later) always fails. | 559 | * (which we are going to use a bit later) always fails - |
560 | * Try to drop ctty now to prevent that. | 560 | * even if we try to take ctty which is already ours! |
561 | * Try to drop old ctty now to prevent that. | ||
562 | * Use O_NONBLOCK: old ctty may be a serial line. | ||
561 | */ | 563 | */ |
562 | fd = open("/dev/tty", O_RDWR); | 564 | fd = open("/dev/tty", O_RDWR | O_NONBLOCK); |
563 | if (fd >= 0) { | 565 | if (fd >= 0) { |
564 | ioctl(fd, TIOCNOTTY); | 566 | ioctl(fd, TIOCNOTTY); |
565 | close(fd); | 567 | close(fd); |