diff options
-rw-r--r-- | src/finit.c | 184 | ||||
-rw-r--r-- | src/log.c | 2 | ||||
-rw-r--r-- | src/sig.c | 14 |
3 files changed, 5 insertions, 195 deletions
diff --git a/src/finit.c b/src/finit.c index 7c5dc23..8a521a1 100644 --- a/src/finit.c +++ b/src/finit.c @@ -245,27 +245,12 @@ int main(int argc, char* argv[]) { int ret; char *devfsd; + svc_t *svc; uev_ctx_t loop; - /* - * finit/init/telinit client tool uses /dev/initctl pipe - * for compatibility but initctl client tool uses socket - */ - if (getpid() != 1) - return client(argc, argv); - - /* Set up canvas */ - screen_init(); - - /* - * In case of emergency. - */ - emergency_shell(); - - /* - * Initial setup of signals, ignore all until we're up. - */ - sig_init(); + /* Clear shmem before start */ + for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) + memset(svc, 0, sizeof(svc_t)); /* * Initalize event context. @@ -274,186 +259,25 @@ int main(int argc, char* argv[]) ctx = &loop; /* - * Set the PATH early to something sane - */ - setenv("PATH", _PATH_STDPATH, 1); - - /* - * Mount base file system, kernel is assumed to run devtmpfs for /dev - */ - chdir("/"); - umask(0); - mount("none", "/proc", "proc", 0, NULL); - mount("none", "/sys", "sysfs", 0, NULL); - if (fisdir("/proc/bus/usb")) - mount("none", "/proc/bus/usb", "usbfs", 0, NULL); - - /* - * Parse kernel parameters, including log_init() - */ - conf_parse_cmdline(); - - /* - * Load plugins early, finit.conf may contain references to - * features implemented by plugins. - */ - ret = plugin_init(&loop, PLUGIN_PATH); - - /* - * Hello world. - */ - banner(); - - /* Show results after banner() */ - print(ret, "Loading plugins"); - - /* - * Check file filesystems in /etc/fstab - */ - for (int pass = 1; pass < 10; pass++) { - if (fsck(pass)) - break; - } - - /* - * Some non-embedded systems without an initramfs may not have /dev mounted yet - * If they do, check if system has udevadm and perform cleanup from initramfs - */ - if (!fismnt("/dev")) - mount("udev", "/dev", "devtmpfs", MS_RELATIME, "size=10%,nr_inodes=61156,mode=755"); - else if (whichp("udevadm")) - run_interactive("udevadm info --cleanup-db", "Cleaning up udev db"); - - /* Some systems use /dev/pts */ - makedir("/dev/pts", 0755); - mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620"); - - makedir("/dev/shm", 0755); - if (!fismnt("/dev/shm")) - mount("shm", "/dev/shm", "tmpfs", 0, NULL); - - /* - * New tmpfs based /run for volatile runtime data - * For details, see http://lwn.net/Articles/436012/ - */ - if (fisdir("/run") && !fismnt("/run")) - mount("tmpfs", "/run", "tmpfs", MS_NODEV, "mode=0755,size=10%"); - umask(022); - - /* - * Populate /dev and prepare for runtime events from kernel. - */ - if (whichp("mdev")) { - /* Embedded Linux systems usually have BusyBox mdev */ - if (log_is_debug()) - touch("/dev/mdev.log"); - devfsd = "mdev -s"; - } else { - if (whichp("udevd")) - devfsd = "udevd --daemon"; - else - devfsd = "/lib/systemd/systemd-udevd --daemon"; - } - - run_interactive(devfsd, "Populating device tree"); - if (whichp("udevadm")) { - run("udevadm trigger --action=add --type=subsystems"); - run("udevadm trigger --action=add --type=devices"); - run("udevadm settle --timeout=120"); - } - - /* * Parse /etc/finit.conf and all *.conf in /etc/finit.d/ to * figure out how to bootstrap the system. */ conf_parse_config(); - /* - * Start built-in watchdog as soon as possible, if enabled - */ - watchdog(argv[0]); - - /* Set hostname as soon as possible, for syslog et al. */ - set_hostname(&hostname); - - /* - * Mount filesystems - */ -#ifdef REMOUNT_ROOTFS - run("mount -n -o remount,rw /"); -#endif -#ifdef SYSROOT - mount(SYSROOT, "/", NULL, MS_MOVE, NULL); -#endif - - /* Debian has this little script to copy generated rules while the system was read-only */ - if (fexist("/lib/udev/udev-finish")) - run_interactive("/lib/udev/udev-finish", "Finalizing udev"); - - _d("Root FS up, calling hooks ..."); - plugin_run_hooks(HOOK_ROOTFS_UP); - - umask(0); - if (run_interactive("mount -na", "Mounting filesystems")) - plugin_run_hooks(HOOK_MOUNT_ERROR); - - run("swapon -ea"); - umask(0022); - /* Base FS up, enable standard SysV init signals */ sig_setup(&loop); - _d("Base FS up, calling hooks ..."); - plugin_run_hooks(HOOK_BASEFS_UP); - /* * Initalize state machine and start all bootstrap tasks * NOTE: no network available! */ sm_init(&sm); - sm_step(&sm); - - /* - * Network stuff - */ - networking(); - umask(022); - - /* Hooks that rely on loopback, or basic networking being up. */ - plugin_run_hooks(HOOK_NETWORK_UP); /* * Start all tasks/services in the configured runlevel */ service_runlevel(cfglevel); - _d("Running svc up hooks ..."); - plugin_run_hooks(HOOK_SVC_UP); - - /* - * Run startup scripts in the runparts directory, if any. - */ - if (runparts && fisdir(runparts)) { - _d("Running startup scripts in %s ...", runparts); - run_parts(runparts, NULL); - service_reload_dynamic(); - } - - /* Convenient SysV compat for when you just don't care ... */ - if (!access(FINIT_RC_LOCAL, X_OK)) { - run_interactive(FINIT_RC_LOCAL, "Calling %s", FINIT_RC_LOCAL); - service_reload_dynamic(); - } - - /* Hooks that should run at the very end */ - plugin_run_hooks(HOOK_SYSTEM_UP); - - /* Enable silent mode before starting TTYs */ - log_silent(); - - /* Delayed start of TTYs at bootstrap */ - tty_runlevel(); - /* Start new initctl API responder */ api_init(&loop); @@ -143,7 +143,7 @@ void logit(int prio, const char *fmt, ...) log_open(); } - vsyslog(prio, fmt, ap); + vfprintf(stderr, fmt, ap); done: va_end(ap); } @@ -370,15 +370,6 @@ void sig_setup(uev_ctx_t *ctx) erase(SYNC_SHUTDOWN); erase(SYNC_STOPPED); - /* Standard SysV init calls ctrl-alt-delete handler */ - uev_signal_init(ctx, &sigint_watcher, sigint_cb, NULL, SIGINT); - uev_signal_init(ctx, &sigpwr_watcher, sigint_cb, NULL, SIGPWR); - - /* BusyBox init style signals for halt, power-off and reboot. */ - uev_signal_init(ctx, &sigusr1_watcher, sigusr1_cb, NULL, SIGUSR1); - uev_signal_init(ctx, &sigusr2_watcher, sigusr2_cb, NULL, SIGUSR2); - uev_signal_init(ctx, &sigterm_watcher, sigterm_cb, NULL, SIGTERM); - /* Some C APIs may need SIGALRM for implementing timers. */ IGNSIG(sa, SIGALRM, 0); @@ -388,11 +379,6 @@ void sig_setup(uev_ctx_t *ctx) /* After initial bootstrap of Finit we call the service monitor to reap children */ uev_signal_init(ctx, &sigchld_watcher, sigchld_cb, NULL, SIGCHLD); - /* Stopping init is a bit tricky. */ - uev_signal_init(ctx, &sigstop_watcher, sigstop_cb, NULL, SIGSTOP); - uev_signal_init(ctx, &sigtstp_watcher, sigstop_cb, NULL, SIGTSTP); - uev_signal_init(ctx, &sigcont_watcher, sigcont_cb, NULL, SIGCONT); - setsid(); } |