chiark / gitweb /
tests: add tests for environment serialization
[elogind.git] / src / update-utmp / update-utmp.c
index 7162084062fe95f9861322266291b5517ad6406e..5e2d2c60e600df57e31917a317c361339933601a 100644 (file)
 //#include "util.h"
 #include "utmp-wtmp.h"
 
-/// includes needed by elogind:
+/// Additional includes needed by elogind
 #include "string-util.h"
 #include "time-util.h"
 #include "update-utmp.h"
-
-
 typedef struct Context {
         sd_bus *bus;
 #ifdef HAVE_AUDIT
@@ -51,6 +49,7 @@ typedef struct Context {
 #endif
 } Context;
 
+#if 0 /// UNNEEDED by elogind
 static usec_t get_startup_time(Context *c) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         usec_t t = 0;
@@ -74,7 +73,6 @@ static usec_t get_startup_time(Context *c) {
         return t;
 }
 
-#if 0 /// UNNEEDED by elogind
 static int get_current_runlevel(Context *c) {
         static const struct {
                 const int runlevel;
@@ -114,7 +112,7 @@ static int get_current_runlevel(Context *c) {
                 if (r < 0)
                         return log_warning_errno(r, "Failed to get state: %s", bus_error_message(&error, r));
 
-                if (streq(state, "active") || streq(state, "reloading"))
+                if (STR_IN_SET(state, "active", "reloading"))
                         return table[i].runlevel;
         }
 
@@ -139,9 +137,13 @@ static int on_reboot(Context *c) {
                 }
 #endif
 
+#if 0 /// systemd hasn't started the system, so elogind always uses NOW()
         /* If this call fails it will return 0, which
          * utmp_put_reboot() will then fix to the current time */
         t = get_startup_time(c);
+#else
+        t = now(CLOCK_REALTIME);
+#endif // 0
 
         q = utmp_put_reboot(t);
         if (q < 0) {
@@ -270,7 +272,6 @@ void update_utmp(int argc, char* argv[], sd_bus *bus) {
         if (c.audit_fd < 0 && errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
                 log_error_errno(errno, "Failed to connect to audit log: %m");
 #endif
-
 #if 0 /// UNNEEDED by elogind
         r = bus_connect_system_systemd(&c.bus);
         if (r < 0) {
@@ -302,14 +303,12 @@ finish:
         else if (streq(argv[1], "shutdown"))
                 (void)on_shutdown(&c);
 #endif // 0
-
 #ifdef HAVE_AUDIT
         if (c.audit_fd >= 0)
                 audit_close(c.audit_fd);
 #endif
 
         sd_bus_flush_close_unref(c.bus);
-
 #if 0 /// UNNEEDED by elogind
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 #endif // 0