init: fix trying mount devtmpfs into /dev

This commit is contained in:
Sisyphus 2013-08-22 17:27:41 +03:00 committed by Michael Shigorin
parent 267ca6e7d1
commit 515053b74f

29
init.c
View File

@ -79,7 +79,7 @@ static void fatal(const char *) __attribute__((noreturn));
static void fatal(const char *msg)
{
printf("FATAL ERROR IN INIT: %s\nI can't recover from this,"
printf("FATAL ERROR IN INIT: %s\nI can't recover from this, "
"please reboot manually and send bugreport.\n", msg);
while (1);
}
@ -371,22 +371,21 @@ int main(int argc, char **argv)
if (mount("sysfs", "/sys", "sysfs", 0, NULL))
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) {
if (stat("/", &rst))
fatal("stat /");
/* Don't mount /dev if it is already mounted */
if (stat("/dev", &cst))
fatal("stat /dev");
if (rst.st_dev == cst.st_dev && rst.st_ino != cst.st_ino)
/* 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"))
fatal("failed to mount tmpfs filesystem");
}
else
if (mount("udevfs", "/dev", "devtmpfs", 0, "size=8M,mode=0755")) {
if (errno != ENODEV)
fatal("failed to mount devtmpfs filesystem");
/* There is no devtmpfs for current kernel, try mount tmpfs */
if (mount("udev", "/dev", "tmpfs", 0, "size=8M,mode=0755"))
fatal("failed to mount tmpfs filesystem");
}
}
/* ignore Control-C and keyboard stop signals */
sigemptyset(&sig);
@ -551,7 +550,7 @@ int main(int argc, char **argv)
/* Make sure the current directory is not on the same filesystem
as the root directory */
if ( stat("/", &rst) || stat(".", &cst) )
if (stat(".", &cst))
fatal("stat");
if ( rst.st_dev == cst.st_dev )