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 <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-07-09 10:24:15 +02:00
1 parent 05938a88ce
commit 927956bf78
2 files changed
+6 -14

No files matched your search

+1
View File
@@ -49,6 +49,7 @@ void runlevel_set(int pre, int now)
{ {
struct utmp utent; struct utmp utent;
memset(&utent, 0, sizeof(utent));
utent.ut_type = RUN_LVL; utent.ut_type = RUN_LVL;
utent.ut_pid = (encode(pre) << 8) | (encode(now) & 0xFF); utent.ut_pid = (encode(pre) << 8) | (encode(now) & 0xFF);
strlcpy(utent.ut_user, "runlevel", sizeof(utent.ut_user)); strlcpy(utent.ut_user, "runlevel", sizeof(utent.ut_user));
+5 -14
View File
@@ -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 <troglobit@gmail.com> * Copyright (c) 2012-2016 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -31,14 +31,11 @@
#include "lite/lite.h" #include "lite/lite.h"
/* /*
* Setup standard FHS 2.3 structure in /var, and * Setup standard FHS 2.3 structure in /var, and write runlevel to UTMP
* write runlevel to UTMP, needed by, e.g., printerdrake.
*/ */
static void setup(void *UNUSED(arg)) static void setup(void *UNUSED(arg))
{ {
#ifdef RUNLEVEL
struct utmp entry; struct utmp entry;
#endif
_d("Setting up FHS structure in /var ..."); _d("Setting up FHS structure in /var ...");
makedir("/var/cache", 0755); makedir("/var/cache", 0755);
@@ -62,14 +59,8 @@ static void setup(void *UNUSED(arg))
touch("/var/run/utmp"); touch("/var/run/utmp");
chown("/var/run/utmp", 0, getgroup("utmp")); chown("/var/run/utmp", 0, getgroup("utmp"));
#ifdef RUNLEVEL _d("Setting initial runlevel 'S', bootstrap ...");
memset(&entry, 0, sizeof(struct utmp)); runlevel_set(0, 0); /* Bootstrap 'S' */
entry.ut_type = RUN_LVL;
entry.ut_pid = '0' + RUNLEVEL;
setutent();
pututline(&entry);
endutent();
#endif
#ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE #ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE
touch("/etc/network/run/ifstate"); touch("/etc/network/run/ifstate");