inittab: use patch_stdio() for stdio redirection
authorJo-Philipp Wich <jo@mein.io>
Tue, 17 May 2016 15:00:46 +0000 (17:00 +0200)
committerJohn Crispin <john@phrozen.org>
Mon, 16 May 2016 19:00:30 +0000 (21:00 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
inittab.c

index f8f0218f219b01023de4270483cf09eda134a3e8..622601ab3e316bebe421a53f7b3fd942bf1eb21d 100644 (file)
--- a/inittab.c
+++ b/inittab.c
@@ -93,22 +93,14 @@ static int dev_exist(const char *dev)
 
 static void fork_worker(struct init_action *a)
 {
-       int fd;
        pid_t p;
 
        a->proc.pid = fork();
        if (!a->proc.pid) {
                p = setsid();
 
-               fd = dev_open(a->id);
-               if (fd != -1)
-               {
-                       dup2(fd, STDIN_FILENO);
-                       dup2(fd, STDOUT_FILENO);
-                       dup2(fd, STDERR_FILENO);
-                       if (fd > STDERR_FILENO)
-                               close(fd);
-               }
+               if (patch_stdio(a->id))
+                       ERROR("Failed to setup i/o redirection\n");
 
                ioctl(STDIN_FILENO, TIOCSCTTY, 1);
                tcsetpgrp(STDIN_FILENO, p);