From f308a587400f29391626fe7243256c918cfd120a Mon Sep 17 00:00:00 2001 From: sin Date: Thu, 10 Apr 2014 11:21:12 +0100 Subject: [PATCH] Error out if dup2 doesn't return the fd we want --- getty.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/getty.c b/getty.c index 73f918d..3a580ad 100644 --- a/getty.c +++ b/getty.c @@ -65,9 +65,12 @@ main(int argc, char *argv[]) fd = open(tty, O_RDWR); if (fd < 0) eprintf("open %s:", tty); - dup2(fd, STDIN_FILENO); - dup2(fd, STDOUT_FILENO); - dup2(fd, STDERR_FILENO); + if (dup2(fd, STDIN_FILENO) != STDIN_FILENO) + eprintf("dup2:"); + if (dup2(fd, STDOUT_FILENO) != STDOUT_FILENO) + eprintf("dup2:"); + if (dup2(fd, STDERR_FILENO) != STDERR_FILENO) + eprintf("dup2:"); sa.sa_handler = SIG_DFL; sa.sa_flags = 0;