X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=initd%2Fearly.c;h=7028ff8a4b79e0d5f29573d29855a21b8cae1bf8;hp=89c8104625aa80a8c874a78eeae8d553415173db;hb=7aad9409d22dc38b71ec75d2aafcfa32426b5594;hpb=b6618ffab8ed4981c57f53929276559698541462 diff --git a/initd/early.c b/initd/early.c index 89c8104..7028ff8 100644 --- a/initd/early.c +++ b/initd/early.c @@ -15,13 +15,16 @@ #include #include #include +#include #include #include #include #include +#include "../utils/utils.h" #include "init.h" +#include "../libc-compat.h" static void early_dev(void) @@ -34,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); } @@ -62,34 +56,34 @@ early_mounts(void) { unsigned int oldumask = umask(0); - mount("proc", "/proc", "proc", MS_NOATIME, 0); - mount("sysfs", "/sys", "sysfs", MS_NOATIME, 0); - mount("none", "/sys/fs/cgroup", "cgroup", 0, 0); - mount("tmpfs", "/dev", "tmpfs", MS_NOATIME, "mode=0755,size=512K"); - symlink("/tmp/shm", "/dev/shm"); + mount("proc", "/proc", "proc", MS_NOATIME | MS_NODEV | MS_NOEXEC | MS_NOSUID, 0); + mount("sysfs", "/sys", "sysfs", MS_NOATIME | MS_NODEV | MS_NOEXEC | MS_NOSUID, 0); + mount("cgroup", "/sys/fs/cgroup", "cgroup", MS_NODEV | MS_NOEXEC | MS_NOSUID, 0); + mount("tmpfs", "/dev", "tmpfs", MS_NOATIME | MS_NOSUID, "mode=0755,size=512K"); + ignore(symlink("/tmp/shm", "/dev/shm")); mkdir("/dev/pts", 0755); - mount("devpts", "/dev/pts", "devpts", MS_NOATIME, "mode=600"); + mount("devpts", "/dev/pts", "devpts", MS_NOATIME | MS_NOEXEC | MS_NOSUID, "mode=600"); early_dev(); early_console("/dev/console"); if (mount_zram_on_tmp()) { - mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME, NULL); + mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME, 0); mkdir("/tmp/shm", 01777); } else { mkdir("/tmp/shm", 01777); 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); } static void early_env(void) { - setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin", 1); + setenv("PATH", EARLY_PATH, 1); } void