#include <sys/poll.h>
#include "macro.h"
+#include "path-util.h"
#include "utmp-wtmp.h"
int utmp_get_runlevel(int *runlevel, int *previous) {
a = found->ut_pid & 0xFF;
b = (found->ut_pid >> 8) & 0xFF;
- if (a < 0 || b < 0)
- r = -EIO;
- else {
- *runlevel = a;
+ *runlevel = a;
+ if (previous)
+ *previous = b;
- if (previous)
- *previous = b;
- r = 0;
- }
+ r = 0;
}
endutxent();
strncpy(store.ut_id, sanitize_id(id), sizeof(store.ut_id));
if (line)
- strncpy(store.ut_line, file_name_from_path(line), sizeof(store.ut_line));
+ strncpy(store.ut_line, path_get_file_name(line), sizeof(store.ut_line));
return write_entry_both(&store);
}
if (u->ut_type != USER_PROCESS || u->ut_user[0] == 0)
continue;
+ /* this access is fine, because strlen("/dev/") << 32 (UT_LINESIZE) */
if (path_startswith(u->ut_line, "/dev/"))
path = u->ut_line;
else {
- if (asprintf(&buf, "/dev/%s", u->ut_line) < 0) {
+ if (asprintf(&buf, "/dev/%.*s",
+ (int) sizeof(u->ut_line), u->ut_line) < 0) {
r = -ENOMEM;
goto finish;
}