[hackers] [ubase] Error out if dup2 doesn't return the fd we want || sin

From: <git_AT_suckless.org>
Date: Thu, 10 Apr 2014 12:21:58 +0200

commit f308a587400f29391626fe7243256c918cfd120a
Author: sin <sin_AT_2f30.org>
Date: Thu Apr 10 11:21:12 2014 +0100

    Error out if dup2 doesn't return the fd we want

diff --git a/getty.c b/getty.c
index 73f918d..3a580ad 100644
--- a/getty.c
+++ b/getty.c
_AT_@ -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;
Received on Thu Apr 10 2014 - 12:21:58 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 10 2014 - 12:24:07 CEST