chiark / gitweb /
Remove some dead code
[elogind.git] / src / shared / utmp-wtmp.c
index 6bba325d3ecc25ebcaf9fde3e621889084d10887..c9b986fc08480f77696685050a2b5277fcf1539f 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/poll.h>
 
 #include "macro.h"
+#include "path-util.h"
 #include "utmp-wtmp.h"
 
 int utmp_get_runlevel(int *runlevel, int *previous) {
@@ -76,15 +77,11 @@ 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();
@@ -224,7 +221,7 @@ int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line
         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);
 }
@@ -402,10 +399,12 @@ int utmp_wall(const char *message, bool (*match_tty)(const char *tty)) {
                 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;
                         }