ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit f308a587400f29391626fe7243256c918cfd120a
parent dfc2f7edac556f9b4e95ba016a6011fff33b2d30
Author: sin <sin@2f30.org>
Date:   Thu Apr 10 11:21:12 +0100

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

Diffstat:
getty.c | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git 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;