2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <sys/mount.h>
16 #include <sys/types.h>
18 #include <sys/sysmacros.h>
25 #include "../utils/utils.h"
27 #include "../libc-compat.h"
28 #include "../container.h"
34 mknod("/dev/null", 0666, makedev(1, 3));
38 early_console(const char *dev
)
43 ERROR("Failed to stat %s: %m\n", dev
);
47 if (patch_stdio(dev
)) {
48 ERROR("Failed to setup i/o redirection\n");
52 fcntl(STDERR_FILENO
, F_SETFL
, fcntl(STDERR_FILENO
, F_GETFL
) | O_NONBLOCK
);
58 unsigned int oldumask
= umask(0);
60 if (!is_container()) {
61 mount("proc", "/proc", "proc", MS_NOATIME
| MS_NODEV
| MS_NOEXEC
| MS_NOSUID
, 0);
62 mount("sysfs", "/sys", "sysfs", MS_NOATIME
| MS_NODEV
| MS_NOEXEC
| MS_NOSUID
, 0);
63 mount("cgroup2", "/sys/fs/cgroup", "cgroup2", MS_NODEV
| MS_NOEXEC
| MS_NOSUID
| MS_RELATIME
, "nsdelegate");
64 mount("tmpfs", "/dev", "tmpfs", MS_NOATIME
| MS_NOEXEC
| MS_NOSUID
, "mode=0755,size=512K");
65 ignore(symlink("/tmp/shm", "/dev/shm"));
66 mkdir("/dev/pts", 0755);
67 mount("devpts", "/dev/pts", "devpts", MS_NOATIME
| MS_NOEXEC
| MS_NOSUID
, 0);
72 early_console("/dev/console");
74 mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID
| MS_NODEV
| MS_NOATIME
, "mode=01777");
75 mkdir("/tmp/shm", 01777);
77 mkdir("/tmp/run", 0755);
78 mkdir("/tmp/lock", 0755);
79 mkdir("/tmp/state", 0755);
86 setenv("PATH", EARLY_PATH
, 1);
98 LOG("Console is alive\n");