system: always support staged sysupgrade
[project/procd.git] / initd / early.c
index 4343516..7028ff8 100644 (file)
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/sysmacros.h>
 
 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <stdlib.h>
 
+#include "../utils/utils.h"
 #include "init.h"
 #include "../libc-compat.h"
 
@@ -35,25 +37,16 @@ static void
 early_console(const char *dev)
 {
        struct stat s;
-       int dd;
 
        if (stat(dev, &s)) {
                ERROR("Failed to stat %s\n", dev);
                return;
        }
 
-       dd = open(dev, O_RDWR);
-       if (dd < 0)
-               dd = open("/dev/null", O_RDWR);
-
-       dup2(dd, STDIN_FILENO);
-       dup2(dd, STDOUT_FILENO);
-       dup2(dd, STDERR_FILENO);
-
-       if (dd != STDIN_FILENO &&
-           dd != STDOUT_FILENO &&
-           dd != STDERR_FILENO)
-               close(dd);
+       if (patch_stdio(dev)) {
+               ERROR("Failed to setup i/o redirection\n");
+               return;
+       }
 
        fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
 }
@@ -81,9 +74,9 @@ early_mounts(void)
                mount("tmpfs", "/tmp/shm", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME,
                                "mode=01777");
        }
-       mkdir("/tmp/run", 0777);
-       mkdir("/tmp/lock", 0777);
-       mkdir("/tmp/state", 0777);
+       mkdir("/tmp/run", 0755);
+       mkdir("/tmp/lock", 0755);
+       mkdir("/tmp/state", 0755);
        umask(oldumask);
 }