]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/update-utmp/update-utmp.c
libudev: hide definition of struct udev_device
[thirdparty/systemd.git] / src / update-utmp / update-utmp.c
index 70ed723a8e90db03598ec21cb14456c0064b9193..bfc78b9739abf4aefd9d25c7bd436ba0d5da2f7b 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <errno.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 
 #if HAVE_AUDIT
@@ -30,6 +32,17 @@ typedef struct Context {
 #endif
 } Context;
 
+static void context_clear(Context *c) {
+        assert(c);
+
+        c->bus = sd_bus_flush_close_unref(c->bus);
+#if HAVE_AUDIT
+        if (c->audit_fd >= 0)
+                audit_close(c->audit_fd);
+        c->audit_fd = -1;
+#endif
+}
+
 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;
@@ -205,7 +218,7 @@ static int on_runlevel(Context *c) {
 }
 
 int main(int argc, char *argv[]) {
-        Context c = {
+        _cleanup_(context_clear) Context c = {
 #if HAVE_AUDIT
                 .audit_fd = -1
 #endif
@@ -222,9 +235,7 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        log_set_target(LOG_TARGET_AUTO);
-        log_parse_environment();
-        log_open();
+        log_setup_service();
 
         umask(0022);
 
@@ -238,8 +249,7 @@ int main(int argc, char *argv[]) {
         r = bus_connect_system_systemd(&c.bus);
         if (r < 0) {
                 log_error_errno(r, "Failed to get D-Bus connection: %m");
-                r = -EIO;
-                goto finish;
+                return EXIT_FAILURE;
         }
 
         log_debug("systemd-update-utmp running as pid "PID_FMT, getpid_cached());
@@ -252,17 +262,10 @@ int main(int argc, char *argv[]) {
                 r = on_runlevel(&c);
         else {
                 log_error("Unknown command %s", argv[1]);
-                r = -EINVAL;
+                return EXIT_FAILURE;
         }
 
         log_debug("systemd-update-utmp stopped as pid "PID_FMT, getpid_cached());
 
-finish:
-#if HAVE_AUDIT
-        if (c.audit_fd >= 0)
-                audit_close(c.audit_fd);
-#endif
-
-        sd_bus_flush_close_unref(c.bus);
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }