chiark / gitweb /
log: rearrange log function naming
[elogind.git] / src / core / manager.c
index e59649464608b7ec5d9837608af8e266705b746d..7af502aba606b5d1048ca7cd5fe27fd0a50d288c 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
@@ -679,26 +673,13 @@ static int manager_setup_notify(Manager *m) {
                         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));
@@ -748,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;
@@ -880,7 +854,7 @@ static unsigned manager_dispatch_gc_queue(Manager *m) {
 
                 if (u->gc_marker == gc_marker + GC_OFFSET_BAD ||
                     u->gc_marker == gc_marker + GC_OFFSET_UNSURE) {
-                        log_debug_unit(u->id, "Collecting %s", u->id);
+                        log_unit_debug(u->id, "Collecting %s", u->id);
                         u->gc_marker = gc_marker + GC_OFFSET_BAD;
                         unit_add_to_cleanup_queue(u);
                 }
@@ -915,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);
 
@@ -981,6 +956,7 @@ void manager_free(Manager *m) {
         hashmap_free(m->units_requiring_mounts_for);
 
         free(m);
+        return NULL;
 }
 
 int manager_enumerate(Manager *m) {
@@ -1197,7 +1173,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
         if (mode == JOB_ISOLATE && !unit->allow_isolate)
                 return sd_bus_error_setf(e, BUS_ERROR_NO_ISOLATION, "Operation refused, unit may not be isolated.");
 
-        log_debug_unit(unit->id,
+        log_unit_debug(unit->id,
                        "Trying to enqueue job %s/%s/%s", unit->id,
                        job_type_to_string(type), job_mode_to_string(mode));
 
@@ -1223,7 +1199,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
         if (r < 0)
                 goto tr_abort;
 
-        log_debug_unit(unit->id,
+        log_unit_debug(unit->id,
                        "Enqueued job %s/%s as %u", unit->id,
                        job_type_to_string(type), (unsigned) tr->anchor_job->id);
 
@@ -1493,7 +1469,7 @@ static void manager_invoke_notify_message(Manager *m, Unit *u, pid_t pid, char *
                 return;
         }
 
-        log_debug_unit(u->id, "Got notification message for unit %s", u->id);
+        log_unit_debug(u->id, "Got notification message for unit %s", u->id);
 
         if (UNIT_VTABLE(u)->notify_message)
                 UNIT_VTABLE(u)->notify_message(u, pid, tags);
@@ -1589,7 +1565,7 @@ static void invoke_sigchld_event(Manager *m, Unit *u, siginfo_t *si) {
         assert(u);
         assert(si);
 
-        log_debug_unit(u->id, "Child "PID_FMT" belongs to %s", si->si_pid, u->id);
+        log_unit_debug(u->id, "Child "PID_FMT" belongs to %s", si->si_pid, u->id);
 
         unit_unwatch_pid(u, si->si_pid);
         UNIT_VTABLE(u)->sigchld_event(u, si->si_pid, si->si_code, si->si_status);
@@ -1661,11 +1637,11 @@ static int manager_start_target(Manager *m, const char *name, JobMode mode) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
 
-        log_debug_unit(name, "Activating special unit %s", name);
+        log_unit_debug(name, "Activating special unit %s", name);
 
         r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL);
         if (r < 0)
-                log_error_unit(name, "Failed to enqueue %s job: %s", name, bus_error_message(&error, r));
+                log_unit_error(name, "Failed to enqueue %s job: %s", name, bus_error_message(&error, r));
 
         return r;
 }
@@ -2434,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);
         }
 
@@ -2980,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);