From 927956bf78fcaa51aa3f05e99df4d07d6dd4497d Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 9 Jul 2016 10:24:15 +0200 Subject: [PATCH] Set correct initial bootstrap runlevel 'S' This patch corrects a long standing issue with Finit. System initial bootstrap runlevel must be set to 'S' (0), not the configured fallback runlevel 'RUNLEVEL', which likely is '2'. Also, minor cleanup, reduce code duplication. Signed-off-by: Joachim Nilsson --- helpers.c | 1 + plugins/bootmisc.c | 19 +++++-------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/helpers.c b/helpers.c index 4eeeed50..37c9bf63 100644 --- a/helpers.c +++ b/helpers.c @@ -49,6 +49,7 @@ void runlevel_set(int pre, int now) { struct utmp utent; + memset(&utent, 0, sizeof(utent)); utent.ut_type = RUN_LVL; utent.ut_pid = (encode(pre) << 8) | (encode(now) & 0xFF); strlcpy(utent.ut_user, "runlevel", sizeof(utent.ut_user)); diff --git a/plugins/bootmisc.c b/plugins/bootmisc.c index 4398d8bf..37bc862f 100644 --- a/plugins/bootmisc.c +++ b/plugins/bootmisc.c @@ -1,6 +1,6 @@ -/* Setup necessary files for UTMP, tracking logins +/* Setup necessary system files for, e.g. UTMP (tracking logins) * - * Copyright (c) 2012 Joachim Nilsson + * Copyright (c) 2012-2016 Joachim Nilsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,14 +31,11 @@ #include "lite/lite.h" /* - * Setup standard FHS 2.3 structure in /var, and - * write runlevel to UTMP, needed by, e.g., printerdrake. + * Setup standard FHS 2.3 structure in /var, and write runlevel to UTMP */ static void setup(void *UNUSED(arg)) { -#ifdef RUNLEVEL struct utmp entry; -#endif _d("Setting up FHS structure in /var ..."); makedir("/var/cache", 0755); @@ -62,14 +59,8 @@ static void setup(void *UNUSED(arg)) touch("/var/run/utmp"); chown("/var/run/utmp", 0, getgroup("utmp")); -#ifdef RUNLEVEL - memset(&entry, 0, sizeof(struct utmp)); - entry.ut_type = RUN_LVL; - entry.ut_pid = '0' + RUNLEVEL; - setutent(); - pututline(&entry); - endutent(); -#endif + _d("Setting initial runlevel 'S', bootstrap ..."); + runlevel_set(0, 0); /* Bootstrap 'S' */ #ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE touch("/etc/network/run/ifstate");