From ca4561271e207cec6829e435aa6fae65cbd3c455 Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Mon, 10 Feb 2014 22:47:27 +0000 Subject: [PATCH] =?UTF-8?q?Check=20exit=20code=20from=20dup()=20in=20spawn?= =?UTF-8?q?()=20and=20log=20error=20if=20it=20fail.=20Patch=20from=20Micha?= =?UTF-8?q?=C5=82=20Kulling.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Changelog | 2 ++ src/init.c | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 722aef2..f5c8d60 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -89,6 +89,8 @@ sysvinit (2.89) UNRELEASED; urgency=low define INIT_FIFO. * Use narrowly scoped file descriptor for handling opened TTY in spawn(). Patch from Michał Kulling. + * Check exit code from dup() in spawn() and log error if it fail. + Patch from Michał Kulling. -- Petter Reinholdtsen Sun Apr 11 11:28:55 CEST 2010 diff --git a/src/init.c b/src/init.c index d6234fb..20c2ecb 100644 --- a/src/init.c +++ b/src/init.c @@ -1111,8 +1111,15 @@ pid_t spawn(CHILD *ch, int *res) if ((ftty = console_open(O_RDWR|O_NOCTTY)) >= 0) { /* Take over controlling tty by force */ (void)ioctl(ftty, TIOCSCTTY, 1); - dup(ftty); - dup(ftty); + + if(dup(ftty) < 0){ + initlog(L_VB, "cannot duplicate console fd"); + } + + if(dup(ftty) < 0){ + initlog(L_VB, "cannot duplicate console fd"); + } + } /* @@ -1181,8 +1188,15 @@ pid_t spawn(CHILD *ch, int *res) strerror(errno)); fd = open("/dev/null", O_RDWR); } - dup(fd); - dup(fd); + + if(dup(fd) < 0) { + initlog(L_VB, "cannot duplicate /dev/null fd"); + } + + if(dup(fd) < 0) { + initlog(L_VB, "cannot duplicate /dev/null fd"); + } + } /*