chiark / gitweb /
systemctl: sort 'list-units' output
[elogind.git] / src / utmp-wtmp.c
index 5aafb7b722272b411c051746a2bc834f64e0475f..46dfba336aaa7317ba9824cbc230b20e71e0be6f 100644 (file)
@@ -202,11 +202,11 @@ int utmp_put_runlevel(usec_t t, int runlevel, int previous) {
 
                         previous = 0;
                 }
-
-                if (previous == runlevel)
-                        return 0;
         }
 
+        if (previous == runlevel)
+                return 0;
+
         init_entry(&store, t);
 
         store.ut_type = RUN_LVL;
@@ -291,17 +291,19 @@ finish:
 int utmp_wall(const char *message) {
         struct utmpx *u;
         char date[26];
-        char *text, *hn, *un, *tty;
+        char *text = NULL, *hn = NULL, *un = NULL, *tty = NULL;
         int r;
         time_t t;
 
         if (!(hn = gethostname_malloc()) ||
-            !(un = getlogname_malloc()) ||
-            !(tty = getttyname_malloc())) {
+            !(un = getlogname_malloc())) {
                 r = -ENOMEM;
                 goto finish;
         }
 
+        if ((r = getttyname_malloc(&tty)) < 0)
+                goto finish;
+
         time(&t);
         assert_se(ctime_r(&t, date));
         delete_chars(date, "\n\r");