chiark / gitweb /
core: fix transaction destructiveness check once more
[elogind.git] / src / core / manager.c
index 129f6dd3a851263cbaa2538ba2666665694edc92..d5d6486cc755a9f5ed65afbcbbbd1197db708045 100644 (file)
@@ -79,9 +79,6 @@
 #include "bus-kernel.h"
 #include "time-util.h"
 
-/* As soon as 5s passed since a unit was added to our GC queue, make sure to run a gc sweep */
-#define GC_QUEUE_USEC_MAX (10*USEC_PER_SEC)
-
 /* Initial delay and the interval for printing status messages about running jobs */
 #define JOBS_IN_PROGRESS_WAIT_USEC (5*USEC_PER_SEC)
 #define JOBS_IN_PROGRESS_PERIOD_USEC (USEC_PER_SEC / 3)
@@ -396,9 +393,6 @@ static int manager_setup_signals(Manager *m) {
 
         assert(m);
 
-        if (m->test_run)
-                return 0;
-
         assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
 
         /* We make liberal use of realtime signals here. On
@@ -662,11 +656,9 @@ static int manager_setup_notify(Manager *m) {
                         return -errno;
                 }
 
-                if (m->running_as == SYSTEMD_SYSTEM) {
+                if (m->running_as == SYSTEMD_SYSTEM)
                         m->notify_socket = strdup("/run/systemd/notify");
-                        if (!m->notify_socket)
-                                return log_oom();
-                } else {
+                else {
                         const char *e;
 
                         e = getenv("XDG_RUNTIME_DIR");
@@ -676,31 +668,18 @@ static int manager_setup_notify(Manager *m) {
                         }
 
                         m->notify_socket = strappend(e, "/systemd/notify");
-                        if (!m->notify_socket)
-                                return log_oom();
-
-                        mkdir_parents_label(m->notify_socket, 0755);
                 }
+                if (!m->notify_socket)
+                        return log_oom();
+
+                (void) mkdir_parents_label(m->notify_socket, 0755);
+                (void) unlink(m->notify_socket);
 
                 strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path)-1);
                 r = bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
                 if (r < 0) {
                         log_error("bind(%s) failed: %m", sa.un.sun_path);
-                        if (errno == EADDRINUSE) {
-                                log_notice("Removing %s socket and trying again.", m->notify_socket);
-                                r = unlink(m->notify_socket);
-                                if (r < 0) {
-                                        log_error("Failed to remove %s: %m", m->notify_socket);
-                                        return -EADDRINUSE;
-                                }
-
-                                r = bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
-                                if (r < 0) {
-                                        log_error("bind(%s) failed: %m", sa.un.sun_path);
-                                        return -errno;
-                                }
-                        } else
-                                return -errno;
+                        return -errno;
                 }
 
                 r = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
@@ -750,13 +729,6 @@ static int manager_setup_kdbus(Manager *m) {
         }
 
         log_debug("Successfully set up kdbus on %s", p);
-
-        /* Create the namespace directory here, so that the contents
-         * of that directory is not visible to non-root users. This is
-         * necessary to ensure that users cannot get access to busses
-         * of virtualized users when no UID namespacing is used. */
-        if (m->running_as == SYSTEMD_SYSTEM)
-                mkdir_p_label("/dev/kdbus/domain", 0700);
 #endif
 
         return 0;
@@ -917,11 +889,12 @@ static void manager_clear_jobs_and_units(Manager *m) {
         m->n_running_jobs = 0;
 }
 
-void manager_free(Manager *m) {
+Manager* manager_free(Manager *m) {
         UnitType c;
         int i;
 
-        assert(m);
+        if (!m)
+                return NULL;
 
         manager_clear_jobs_and_units(m);
 
@@ -983,6 +956,7 @@ void manager_free(Manager *m) {
         hashmap_free(m->units_requiring_mounts_for);
 
         free(m);
+        return NULL;
 }
 
 int manager_enumerate(Manager *m) {
@@ -2436,7 +2410,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
                                 m->kdbus_fd = fdset_remove(fds, fd);
                         }
 
-                } else if (bus_track_deserialize_item(&m->deserialized_subscribed, l) == 0)
+                } else if (bus_track_deserialize_item(&m->deserialized_subscribed, l) < 0)
                         log_warning("Unknown serialization item '%s'", l);
         }
 
@@ -2982,12 +2956,14 @@ void manager_set_first_boot(Manager *m, bool b) {
 void manager_status_printf(Manager *m, StatusType type, const char *status, const char *format, ...) {
         va_list ap;
 
-        if (!manager_get_show_status(m, type))
+        /* If m is NULL, assume we're after shutdown and let the messages through. */
+
+        if (m && !manager_get_show_status(m, type))
                 return;
 
         /* XXX We should totally drop the check for ephemeral here
          * and thus effectively make 'Type=idle' pointless. */
-        if (type == STATUS_TYPE_EPHEMERAL && m->n_on_console > 0)
+        if (type == STATUS_TYPE_EPHEMERAL && m && m->n_on_console > 0)
                 return;
 
         va_start(ap, format);