init: Use devtmpfs for /dev if possible.
If devtmpfs already mounted into /dev (see CONFIG_DEVTMPFS_MOUNT kernel option) then do nothing. Otherwise try to mount devtmpfs or tmpfs.
This commit is contained in:
parent
19090fbacc
commit
f3240f3f36
32
init.c
32
init.c
@ -87,6 +87,17 @@ void warn(char *msg)
|
|||||||
printf("W: %s\n", msg);
|
printf("W: %s\n", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _mknod(const char *pathname, mode_t mode, dev_t dev)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = mknod(pathname, mode, dev);
|
||||||
|
if (rc < 0 && errno == EEXIST)
|
||||||
|
rc = 0;
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
/* fork to:
|
/* fork to:
|
||||||
* (1) watch /proc/kmsg and copy the stuff to /dev/tty4
|
* (1) watch /proc/kmsg and copy the stuff to /dev/tty4
|
||||||
* (2) listens to /dev/log and copy also this stuff (log from programs)
|
* (2) listens to /dev/log and copy also this stuff (log from programs)
|
||||||
@ -101,7 +112,7 @@ pid_t doklog()
|
|||||||
if ((in = open("/proc/kmsg", O_RDONLY, 0)) < 0)
|
if ((in = open("/proc/kmsg", O_RDONLY, 0)) < 0)
|
||||||
fatal("failed to open /proc/kmsg");
|
fatal("failed to open /proc/kmsg");
|
||||||
|
|
||||||
if (mknod("/dev/tty4", S_IFCHR, MKDEV(4, 4)) < 0 ||
|
if (_mknod("/dev/tty4", S_IFCHR, MKDEV(4, 4)) < 0 ||
|
||||||
(out = open("/dev/tty4", O_WRONLY, 0)) < 0)
|
(out = open("/dev/tty4", O_WRONLY, 0)) < 0)
|
||||||
fatal("failed to open /dev/tty4");
|
fatal("failed to open /dev/tty4");
|
||||||
|
|
||||||
@ -357,8 +368,23 @@ int main(int argc, char **argv)
|
|||||||
fatal("failed to mount proc filesystem");
|
fatal("failed to mount proc filesystem");
|
||||||
if (mount("sysfs", "/sys", "sysfs", 0, NULL))
|
if (mount("sysfs", "/sys", "sysfs", 0, NULL))
|
||||||
fatal("failed to mount sysfs filesystem");
|
fatal("failed to mount sysfs filesystem");
|
||||||
|
|
||||||
|
if (statfs("/dev", &sfs))
|
||||||
|
fatal("statfs /dev");
|
||||||
|
/* Don't mount /dev if it is already mounted as tmpfs */
|
||||||
|
if (sfs.f_type != TMPFS_MAGIC) {
|
||||||
|
/* Try mount devtmpfs into /dev */
|
||||||
|
if (mount("udevfs", "/dev", "devtmpfs", 0, "size=10M,mode=0755")) {
|
||||||
|
if (errno == ENODEV) {
|
||||||
|
/* There is no devtmpfs for current kernel,
|
||||||
|
* try mount tmpfs */
|
||||||
if (mount("udev", "/dev", "tmpfs", 0, "size=10M,mode=0755"))
|
if (mount("udev", "/dev", "tmpfs", 0, "size=10M,mode=0755"))
|
||||||
fatal("failed to mount tmpfs filesystem");
|
fatal("failed to mount tmpfs filesystem");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fatal("failed to mount devtmpfs filesystem");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ignore Control-C and keyboard stop signals */
|
/* ignore Control-C and keyboard stop signals */
|
||||||
sigemptyset(&sig);
|
sigemptyset(&sig);
|
||||||
@ -366,7 +392,7 @@ int main(int argc, char **argv)
|
|||||||
sigaddset(&sig, SIGTSTP);
|
sigaddset(&sig, SIGTSTP);
|
||||||
sigprocmask(SIG_BLOCK, &sig, NULL);
|
sigprocmask(SIG_BLOCK, &sig, NULL);
|
||||||
|
|
||||||
if (mknod("/dev/console", S_IFCHR, MKDEV(5, 1)) < 0 ||
|
if (_mknod("/dev/console", S_IFCHR, MKDEV(5, 1)) < 0 ||
|
||||||
(fd = open("/dev/console", O_RDWR, 0)) < 0) {
|
(fd = open("/dev/console", O_RDWR, 0)) < 0) {
|
||||||
fatal("failed to open /dev/console");
|
fatal("failed to open /dev/console");
|
||||||
}
|
}
|
||||||
@ -376,7 +402,7 @@ int main(int argc, char **argv)
|
|||||||
dup2(fd, 2);
|
dup2(fd, 2);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (mknod("/dev/null", S_IFCHR, MKDEV(1, 3)) < 0)
|
if (_mknod("/dev/null", S_IFCHR, MKDEV(1, 3)) < 0)
|
||||||
fatal("failed to create /dev/null");
|
fatal("failed to create /dev/null");
|
||||||
|
|
||||||
/* I set me up as session leader (probably not necessary?) */
|
/* I set me up as session leader (probably not necessary?) */
|
||||||
|
Loading…
Reference in New Issue
Block a user