Assume kernel has devtmpfs enabled --> cleanup device creation & mount

Cleanup device creation and initial mount by assuming that the kernel
has devtmpfs enabled.  This is the default for most modern GNU/Linux
distributions.  See http://lwn.net/Articles/331818/ for more info.

Also, since finit is targeted at deeply embedded systems hooks for the
BusyBox udev replacement, mdev has been added.  If MDEV is defined in
the build it will take care of both hotplugging of devices and initial
setup of /dev

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2012-09-17 16:05:41 +02:00
1 parent 2f527215d0
commit 855c7d8251
5 files changed
+76 -111

No files matched your search

+9 -7
View File
@@ -31,13 +31,14 @@ EXEC = finit
OBJS = finit.o helpers.o initctl.o signal.o OBJS = finit.o helpers.o initctl.o signal.o
SRCS = $(OBJS:.o=.c) SRCS = $(OBJS:.o=.c)
DEPS = $(addprefix .,$(SRCS:.c=.d)) DEPS = $(addprefix .,$(SRCS:.c=.d))
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\" CFLAGS += -W -Wall -Werror -Os
CPPFLAGS += -DLISTEN_INITCTL -DBUILTIN_RUNPARTS
CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE
# Disable annoying gcc warning for "warn_unused_result", see GIT 37af997 # Disable annoying gcc warning for "warn_unused_result", see GIT 37af997
CPPFLAGS += -U_FORTIFY_SOURCE CPPFLAGS += -U_FORTIFY_SOURCE
CPPFLAGS += -I$(ROOTDIR)/$(CONFIG_LINUXDIR)/include/ CPPFLAGS += -I$(ROOTDIR)/$(CONFIG_LINUXDIR)/include/
CFLAGS += -W -Wall -Werror -Os # Build for embedded systems, not notebook by default, see finit.h
CPPFLAGS += -DEMBEDDED_SYSTEM -DBUILTIN_RUNPARTS
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\"
CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE
prefix ?= /usr/local prefix ?= /usr/local
sysconfdir ?= /etc sysconfdir ?= /etc
@@ -52,21 +53,22 @@ $(OBJS): Makefile
finit: $(OBJS) finit: $(OBJS)
# @ln -sf /sbin/finit /sbin/init
install: all install: all
@install -d $(DESTDIR)$(prefix)/sbin @install -d $(DESTDIR)$(prefix)/sbin
@install -d $(DESTDIR)$(sysconfdir) @install -d $(DESTDIR)$(sysconfdir)
@install -d $(DESTDIR)$(datadir) @install -d $(DESTDIR)$(datadir)
@install -d $(DESTDIR)$(mandir) @install -d $(DESTDIR)$(mandir)
@for file in $(EXEC); do \ @for file in $(EXEC); do \
printf " INSTALL $(DESTDIR)$(prefix)/sbin/$$file\n"; \
install -m 0755 $$file $(DESTDIR)$(prefix)/sbin/$$file; \ install -m 0755 $$file $(DESTDIR)$(prefix)/sbin/$$file; \
done done
@ln -sf /sbin/finit /sbin/init
uninstall: uninstall:
-@for file in $(EXEC); do \ -@for file in $(EXEC); do \
printf " REMOVE $(DESTDIR)$(prefix)/sbin/$$file\n"; \
$(RM) $(DESTDIR)$(prefix)/sbin/$$file; \ $(RM) $(DESTDIR)$(prefix)/sbin/$$file; \
done done
-@$(RM) /sbin/finit /sbin/init
clean: clean:
-@$(RM) $(OBJS) $(DEPS) $(EXEC) -@$(RM) $(OBJS) $(DEPS) $(EXEC)
-1
View File
@@ -1,6 +1,5 @@
# Some junk files we always want to be removed when doing a make clean. # Some junk files we always want to be removed when doing a make clean.
JUNK = *~ *.bak *.aux *.dvi *.idx *.ind *.log *.ps *.map .*.d DEADJOE semantic.cache *.gdb *.elf core core.* JUNK = *~ *.bak *.aux *.dvi *.idx *.ind *.log *.ps *.map .*.d DEADJOE semantic.cache *.gdb *.elf core core.*
RM := -@$(RM)
MAKE := @$(MAKE) MAKE := @$(MAKE)
MAKEFLAGS = --no-print-directory MAKEFLAGS = --no-print-directory
+20 -66
View File
@@ -79,8 +79,24 @@ int main(void)
chdir("/"); chdir("/");
umask(022); umask(022);
/*
* Mount base file system, kernel is assumed to run devtmpfs for /dev
*/
mount("none", "/proc", "proc", 0, NULL); mount("none", "/proc", "proc", 0, NULL);
mount("none", "/proc/bus/usb", "usbfs", 0, NULL);
mount("none", "/sys", "sysfs", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL);
mkdir("/dev/pts", 0755);
mkdir("/dev/shm", 0755);
mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=620");
mount("none", "/dev/shm", "tmpfs", 0, NULL);
/*
* Populate /dev and prepare for runtime events from kernel.
*/
#ifdef MDEV
system("sysctl -w kernel.hotplug=" MDEV);
system(MDEV " -s");
#endif
/* /*
* Parse kernel parameters * Parse kernel parameters
@@ -153,44 +169,12 @@ int main(void)
system(cmd); system(cmd);
continue; continue;
} }
#ifdef MAKE_DEVICES
/* This is used if the system uses udev and doesn't
* mount /dev as tmpfs in the initrd, or if it doesn't
* use an initrd. Mount /dev as tmpfs and create basic
* device nodes.
*/
if (MATCH_CMD(line, "mountdev", x)) {
mount("none", "/dev", "tmpfs", 0, "mode=0755");
chardev("/dev/null", 0666, 1, 3);
blkdev("/dev/sda1", 0660, 8, 1);
blkdev("/dev/sda2", 0660, 8, 2);
blkdev("/dev/sda3", 0660, 8, 3);
blkdev("/dev/sda4", 0660, 8, 4);
blkdev("/dev/sda5", 0660, 8, 5);
blkdev("/dev/sda6", 0660, 8, 6);
#ifdef MAKE_DEV_VCS
/* Caio reports that newer X.org needs these */
blkdev("/dev/vcs1", 0660, 7, 1);
blkdev("/dev/vcs2", 0660, 7, 2);
blkdev("/dev/vcs3", 0660, 7, 3);
blkdev("/dev/vcs4", 0660, 7, 4);
blkdev("/dev/vcsa1", 0660, 7, 129);
blkdev("/dev/vcsa2", 0660, 7, 130);
blkdev("/dev/vcsa3", 0660, 7, 131);
blkdev("/dev/vcsa4", 0660, 7, 132);
#endif
continue;
}
/* This works only if /dev is tmpfs! If not, create
* devices statically on the filesystem
*/
if (MATCH_CMD(line, "mknod ", x)) { if (MATCH_CMD(line, "mknod ", x)) {
strcpy(cmd, "/bin/mknod "); strcpy(cmd, "/bin/mknod ");
build_cmd(cmd, x, CMD_SIZE); build_cmd(cmd, x, CMD_SIZE);
system(cmd); system(cmd);
continue; continue;
} }
#endif
} }
fclose(f); fclose(f);
} }
@@ -203,42 +187,12 @@ int main(void)
#ifdef REMOUNT_ROOTFS_RW #ifdef REMOUNT_ROOTFS_RW
system("/bin/mount -n -o remount,rw /"); system("/bin/mount -n -o remount,rw /");
#endif #endif
umask(0); #ifdef SYSROOT
#ifdef MAKE_DEVICES
mkdir("/dev/shm", 0755);
mkdir("/dev/pts", 0755);
#endif
mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=620");
mount("none", "/dev/shm", "tmpfs", 0, NULL);
mount("none", "/tmp", "tmpfs", 0, "mode=1777,size=128m");
mount("none", "/var/run", "tmpfs", 0, "mode=0755");
mount("none", "/var/lock", "tmpfs", 0, "mode=1777");
mount("none", "/proc/bus/usb", "usbfs", 0, NULL);
mount(SYSROOT, "/", NULL, MS_MOVE, NULL); mount(SYSROOT, "/", NULL, MS_MOVE, NULL);
_d("make devices");
#ifdef MAKE_DEVICES
mkdir("/dev/input", 0755);
chardev("/dev/urandom", 0666, 1, 9);
chardev("/dev/ptmx", 0666, 5, 2);
chardev("/dev/null", 0666, 1, 3);
chmod("/dev/null", 0666);
chardev("/dev/mem", 0640, 1, 1);
chardev("/dev/tty0", 0660, 4, 0);
chardev("/dev/tty1", 0660, 4, 1);
chardev("/dev/tty2", 0660, 4, 2);
chardev("/dev/tty3", 0660, 4, 3);
chardev("/dev/input/mice", 0660, 13, 63);
chardev("/dev/input/event0", 0660, 13, 64);
chardev("/dev/agpgart", 0660, 10, 175);
blkdev("/dev/loop0", 0600, 7, 0);
#endif #endif
umask(0);
unlink("/etc/mtab"); unlink("/etc/mtab");
system("mount -a"); system("mount -a");
umask(0022); umask(0022);
/* /*
@@ -296,9 +250,9 @@ int main(void)
run_parts("/etc/resolvconf/update.d", "-i", NULL); run_parts("/etc/resolvconf/update.d", "-i", NULL);
#else #else
system(RUNPARTS " --arg=i /etc/resolvconf/update.d"); system(RUNPARTS " --arg=i /etc/resolvconf/update.d");
#endif #endif /* BUILTIN_RUNPARTS */
chdir("/"); chdir("/");
#endif #endif /* USE_ETC_RESOLVCONF_RUN */
#ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE #ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE
touch("/etc/network/run/ifstate"); touch("/etc/network/run/ifstate");
+46 -36
View File
@@ -47,47 +47,57 @@
/* Distribution configuration */ /* Distribution configuration */
#if defined DIST_MDV /* Mandriva */ #if defined EMBEDDED_SYSTEM
#define RANDOMSEED "/var/lib/random-seed" # define CONSOLE "/dev/console"
#define SYSROOT "/sysroot" # define MDEV "/sbin/mdev"
#define CONSOLE "/dev/console" # define GETTY "/sbin/getty -L 115200 ttyS0 vt100"
#define GETTY "/usr/bin/openvt /sbin/mingetty tty2" # define LISTEN_INITCTL
#define RUNPARTS "/usr/bin/run-parts" #elif defined DIST_MDV /* Mandriva */
#define REMOUNT_ROOTFS_RW # define RANDOMSEED "/var/lib/random-seed"
#define MAKE_DEVICES # define SYSROOT "/sysroot"
#define MAKE_DEV_VCS # define CONSOLE "/dev/console"
#define PAM_CONSOLE # define GETTY "/usr/bin/openvt /sbin/mingetty tty2"
#define LISTEN_INITCTL # define RUNPARTS "/usr/bin/run-parts"
#define RUNLEVEL 5 # define REMOUNT_ROOTFS_RW
#define USE_MESSAGE_BUS # define PAM_CONSOLE
# define LISTEN_INITCTL
# define RUNLEVEL 5
# define USE_MESSAGE_BUS
#elif defined DIST_EEEXUBUNTU /* eeeXubuntu */ #elif defined DIST_EEEXUBUNTU /* eeeXubuntu */
#define RANDOMSEED "/var/lib/urandom/random-seed" # define RANDOMSEED "/var/lib/urandom/random-seed"
#define SYSROOT "/sysroot" # define SYSROOT "/sysroot"
#define CONSOLE "/dev/console" # define CONSOLE "/dev/console"
#define GETTY "/usr/bin/openvt /sbin/getty 38400 tty2" # define GETTY "/usr/bin/openvt /sbin/getty 38400 tty2"
#define RUNPARTS "/bin/run-parts" # define RUNPARTS "/bin/run-parts"
#define REMOUNT_ROOTFS_RW # define REMOUNT_ROOTFS_RW
#define MAKE_DEVICES # define TOUCH_ETC_NETWORK_RUN_IFSTATE
#define TOUCH_ETC_NETWORK_RUN_IFSTATE # define LISTEN_INITCTL
#define LISTEN_INITCTL #elif defined DIST_ORIGEEE /* original EeePC distribution */
#else /* original Eeepc distribution */ # define RANDOMSEED "/var/lib/urandom/random-seed"
#define RANDOMSEED "/var/lib/urandom/random-seed" # define SYSROOT "/mnt"
#define SYSROOT "/mnt" # define CONSOLE "/dev/console"
#define CONSOLE "/dev/console" # define GETTY "/usr/bin/openvt /sbin/getty 38400 tty2"
#define GETTY "/usr/bin/openvt /sbin/getty 38400 tty2" # define RUNPARTS "/bin/run-parts"
#define RUNPARTS "/bin/run-parts" # define TOUCH_ETC_NETWORK_RUN_IFSTATE
#define TOUCH_ETC_NETWORK_RUN_IFSTATE # define USE_ETC_RESOLVCONF_RUN
#define USE_ETC_RESOLVCONF_RUN #else /* Ubuntu */
# define RANDOMSEED "/var/lib/urandom/random-seed"
# define CONSOLE "/dev/console"
# define MDEV "\"/bin/busybox mdev\""
# define GETTY "/usr/bin/openvt /sbin/getty 38400 tty2"
# define REMOUNT_ROOTFS_RW
# define TOUCH_ETC_NETWORK_RUN_IFSTATE
# define LISTEN_INITCTL
#endif #endif
#define SYNC_SHUTDOWN "/var/lock/finit.shutdown" #define SYNC_SHUTDOWN "/var/lock/finit.shutdown"
#define SYNC_STOPPED "/var/lock/finit.stopped" #define SYNC_STOPPED "/var/lock/finit.stopped"
#ifndef DEFUSER #ifndef DEFUSER
#define DEFUSER "user" # define DEFUSER "user"
#endif #endif
#ifndef DEFHOST #ifndef DEFHOST
#define DEFHOST "noname" # define DEFHOST "noname"
#endif #endif
#define LINE_SIZE 1024 #define LINE_SIZE 1024
@@ -96,16 +106,16 @@
#define HOSTNAME_SIZE 32 #define HOSTNAME_SIZE 32
#ifndef touch #ifndef touch
#define touch(x) mknod((x), S_IFREG|0644, 0) # define touch(x) mknod((x), S_IFREG|0644, 0)
#endif #endif
#ifndef chardev #ifndef chardev
#define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min))) # define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
#endif #endif
#ifndef blkdev #ifndef blkdev
#define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min))) # define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min)))
#endif #endif
#ifndef fexist #ifndef fexist
#define fexist(x) (access(x, F_OK) != -1) # define fexist(x) (access(x, F_OK) != -1)
#endif #endif
/* Match one command. */ /* Match one command. */
+1 -1
View File
@@ -22,7 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#ifdef LISTEN_INITCTL
#include <features.h> #include <features.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
@@ -45,6 +44,7 @@ struct init_request {
char data[368]; char data[368];
}; };
#ifdef LISTEN_INITCTL
/* Standard reboot/shutdown utilities talk to init using /dev/initctl. /* Standard reboot/shutdown utilities talk to init using /dev/initctl.
* We should check if the fifo was recreated and reopen it. * We should check if the fifo was recreated and reopen it.
*/ */