mirror of
https://github.com/troglobit/finit.git
synced 2026-10-30 12:50:34 +00:00
UTMP: Set BOOT_TIME record and add shutdown
This patch adds support for initializing /var/run/utmp with the initial reboot as well as a shutdown record in the UTMP db. Also, the run level change now properly records ~ and ~~ as line and id, respectively, and the kernel release and time of each UTMP record is now set properly. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
27899feea0
commit
addc21bdf6
4 files changed
+43
-5
No files matched your search
+30
-2
@@ -24,17 +24,35 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <utmp.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <lite/lite.h>
|
||||
|
||||
int utmp_set(int type, int pid, char *user)
|
||||
int utmp_set(int type, int pid, char *user, char *line, char *id)
|
||||
{
|
||||
int result;
|
||||
struct utmp ut;
|
||||
struct utsname uts;
|
||||
|
||||
switch (type) {
|
||||
case RUN_LVL:
|
||||
case BOOT_TIME:
|
||||
line = "~";
|
||||
id = "~~";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
memset(&ut, 0, sizeof(ut));
|
||||
ut.ut_type = type;
|
||||
ut.ut_pid = pid;
|
||||
strlcpy(ut.ut_user, user, sizeof(ut.ut_user));
|
||||
strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
|
||||
strlcpy(ut.ut_id, id, sizeof(ut.ut_id));
|
||||
if (!uname(&uts))
|
||||
strncpy(ut.ut_host, uts.release, sizeof(ut.ut_host));
|
||||
ut.ut_tv.tv_sec = time(NULL);
|
||||
|
||||
setutent();
|
||||
result = pututline(&ut) ? 0 : 1;;
|
||||
@@ -51,7 +69,17 @@ static int encode(int lvl)
|
||||
|
||||
int utmp_set_runlevel(int pre, int now)
|
||||
{
|
||||
return utmp_set(RUN_LVL, (encode(pre) << 8) | (encode(now) & 0xFF), "runlevel");
|
||||
return utmp_set(RUN_LVL, (encode(pre) << 8) | (encode(now) & 0xFF), "runlevel", NULL, NULL);
|
||||
}
|
||||
|
||||
int utmp_set_boot(void)
|
||||
{
|
||||
return utmp_set(BOOT_TIME, 0, "reboot", NULL, NULL);
|
||||
}
|
||||
|
||||
int utmp_set_halt(void)
|
||||
{
|
||||
return utmp_set(RUN_LVL, 0, "shutdown", NULL, NULL);
|
||||
}
|
||||
|
||||
int utmp_show(char *file)
|
||||
|
||||
Reference in new issue
Block a user