#include <sys/utsname.h>
#include <fcntl.h>
#include <unistd.h>
-#include <sys/poll.h>
+#include <poll.h>
#include "macro.h"
#include "path-util.h"
static void init_timestamp(struct utmpx *store, usec_t t) {
assert(store);
- zero(*store);
-
if (t <= 0)
t = now(CLOCK_REALTIME);
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);
}
int utmp_put_shutdown(void) {
- struct utmpx store;
+ struct utmpx store = {};
init_entry(&store, 0);
}
int utmp_put_reboot(usec_t t) {
- struct utmpx store;
+ struct utmpx store = {};
init_entry(&store, t);
}
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)
}
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);
int utmp_put_runlevel(int runlevel, int previous) {
- struct utmpx store;
+ struct utmpx store = {};
int r;
assert(runlevel > 0);