From f8def336d4a4677f9bf68e152ddf258542c7cd95 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 8 Aug 2016 23:41:52 +0200 Subject: [PATCH] Fix ordering of UTMP events: reboot, then runlevel This patch fixes the ordering of UTMP events. The first event that is expected in /var/run/utmp is reboot, next is the runlevel change to the configured runlevel, e.g. from S --> 2. Let the bootmisc plugin handle this, it knows when /var/run/utmp has been created and is writable. It is not the eact boot time, but close enough for most usees. Signed-off-by: Joachim Nilsson --- finit.c | 3 --- plugins/bootmisc.c | 8 +++----- utmp-api.c | 2 ++ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/finit.c b/finit.c index fc48c7ab..3a1a7236 100644 --- a/finit.c +++ b/finit.c @@ -270,9 +270,6 @@ int main(int argc, char* argv[]) mount("tmpfs", "/run", "tmpfs", MS_NODEV, "mode=0755,size=10%"); umask(022); - /* Set BOOT_TIME UTMP entry */ - utmp_set_boot(); - /* * Parse kernel parameters */ diff --git a/plugins/bootmisc.c b/plugins/bootmisc.c index 5bf751f5..d8e5ba41 100644 --- a/plugins/bootmisc.c +++ b/plugins/bootmisc.c @@ -22,21 +22,19 @@ */ #include -#include #include #include "../config.h" #include "../finit.h" #include "../helpers.h" #include "../plugin.h" +#include "../utmp-api.h" /* * Setup standard FHS 2.3 structure in /var, and write runlevel to UTMP */ static void setup(void *UNUSED(arg)) { - struct utmp entry; - _d("Setting up FHS structure in /var ..."); makedir("/var/cache", 0755); makedir("/var/games", 0755); @@ -77,8 +75,8 @@ static void setup(void *UNUSED(arg)) chmod("/var/log/lastlog", 0664); chown("/var/log/lastlog", 0, getgroup("utmp")); - _d("Setting initial runlevel 'S', bootstrap ..."); - runlevel_set(0, 0); /* Bootstrap 'S' */ + /* Set BOOT_TIME UTMP entry */ + utmp_set_boot(); #ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE touch("/etc/network/run/ifstate"); diff --git a/utmp-api.c b/utmp-api.c index 34956440..97dce884 100644 --- a/utmp-api.c +++ b/utmp-api.c @@ -55,6 +55,8 @@ int utmp_set(int type, int pid, char *user, char *line, char *id) ut.ut_tv.tv_sec = time(NULL); setutent(); + while (getutent()) + ; result = pututline(&ut) ? 0 : 1;; endutent();