X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futmp-wtmp.c;h=6fa9a3d7a316edd6f6600f1e7dc98ea04dda0660;hb=1cfc78c91965df340cdde100ad6cb3ed50b28927;hp=30a0c031f3f08908de7313a62cce39f7141f3b16;hpb=9003d9b0d628be059922e522fd35f9c5b4d8b039;p=elogind.git diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 30a0c031f..6fa9a3d7a 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -21,15 +21,16 @@ #include #include -#include #include #include #include #include -#include +#include #include "macro.h" #include "path-util.h" +#include "terminal-util.h" +#include "hostname-util.h" #include "utmp-wtmp.h" int utmp_get_runlevel(int *runlevel, int *previous) { @@ -92,8 +93,6 @@ int utmp_get_runlevel(int *runlevel, int *previous) { static void init_timestamp(struct utmpx *store, usec_t t) { assert(store); - zero(*store); - if (t <= 0) t = now(CLOCK_REALTIME); @@ -143,7 +142,7 @@ static int write_entry_wtmp(const struct utmpx *store) { assert(store); /* wtmp is a simple append-only file where each entry is - simply appended to * the end; i.e. basically a log. */ + simply appended to the end; i.e. basically a log. */ errno = 0; updwtmpx(_PATH_WTMPX, store); @@ -172,7 +171,7 @@ static int write_entry_both(const struct utmpx *store) { } int utmp_put_shutdown(void) { - struct utmpx store; + struct utmpx store = {}; init_entry(&store, 0); @@ -183,7 +182,7 @@ int utmp_put_shutdown(void) { } int utmp_put_reboot(usec_t t) { - struct utmpx store; + struct utmpx store = {}; init_entry(&store, t); @@ -206,16 +205,17 @@ _pure_ static const char *sanitize_id(const char *id) { } int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line) { - struct utmpx store; + struct utmpx store = { + .ut_type = INIT_PROCESS, + .ut_pid = pid, + .ut_session = sid, + }; assert(id); init_timestamp(&store, 0); - store.ut_type = INIT_PROCESS; - store.ut_pid = pid; - store.ut_session = sid; - + /* ut_id needs only be nul-terminated if it is shorter than sizeof(ut_id) */ strncpy(store.ut_id, sanitize_id(id), sizeof(store.ut_id)); if (line) @@ -225,14 +225,15 @@ int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line } int utmp_put_dead_process(const char *id, pid_t pid, int code, int status) { - struct utmpx lookup, store, store_wtmp, *found; + struct utmpx lookup = { + .ut_type = INIT_PROCESS /* looks for DEAD_PROCESS, LOGIN_PROCESS, USER_PROCESS, too */ + }, store, store_wtmp, *found; assert(id); setutxent(); - zero(lookup); - lookup.ut_type = INIT_PROCESS; /* looks for DEAD_PROCESS, LOGIN_PROCESS, USER_PROCESS, too */ + /* ut_id needs only be nul-terminated if it is shorter than sizeof(ut_id) */ strncpy(lookup.ut_id, sanitize_id(id), sizeof(lookup.ut_id)); found = getutxid(&lookup); @@ -260,7 +261,7 @@ int utmp_put_dead_process(const char *id, pid_t pid, int code, int status) { int utmp_put_runlevel(int runlevel, int previous) { - struct utmpx store; + struct utmpx store = {}; int r; assert(runlevel > 0);