chiark / gitweb /
log: fix order of log_unit_struct() to match other logging calls
[elogind.git] / src / core / manager.c
index 7abc8a9a5e43c9a7177b4dba56a5b43a1665bc8c..63102d17852d34752b64a3b2907e8228caa2af1f 100644 (file)
@@ -722,7 +722,12 @@ static int manager_setup_kdbus(Manager *m) {
         if (m->test_run || m->kdbus_fd >= 0)
                 return 0;
 
-        m->kdbus_fd = bus_kernel_create_bus(m->running_as == SYSTEMD_SYSTEM ? "system" : "user", m->running_as == SYSTEMD_SYSTEM, &p);
+        bus_kernel_fix_attach_mask();
+
+        m->kdbus_fd = bus_kernel_create_bus(
+                        m->running_as == SYSTEMD_SYSTEM ? "system" : "user",
+                        m->running_as == SYSTEMD_SYSTEM, &p);
+
         if (m->kdbus_fd < 0) {
                 log_debug("Failed to set up kdbus: %s", strerror(-m->kdbus_fd));
                 return m->kdbus_fd;
@@ -854,7 +859,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);
                 }
@@ -889,11 +894,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);
 
@@ -955,6 +961,7 @@ void manager_free(Manager *m) {
         hashmap_free(m->units_requiring_mounts_for);
 
         free(m);
+        return NULL;
 }
 
 int manager_enumerate(Manager *m) {
@@ -1171,7 +1178,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));
 
@@ -1197,7 +1204,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);
 
@@ -1467,7 +1474,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);
@@ -1563,7 +1570,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);
@@ -1635,11 +1642,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;
 }
@@ -1874,8 +1881,8 @@ static int manager_dispatch_time_change_fd(sd_event_source *source, int fd, uint
         assert(m->time_change_fd == fd);
 
         log_struct(LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),
-                   "MESSAGE=Time has been changed",
+                   LOG_MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),
+                   LOG_MESSAGE("Time has been changed"),
                    NULL);
 
         /* Restart the watch */
@@ -2583,28 +2590,28 @@ static void manager_notify_finished(Manager *m) {
                         initrd_usec = m->userspace_timestamp.monotonic - m->initrd_timestamp.monotonic;
 
                         log_struct(LOG_INFO,
-                                   MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
                                    "KERNEL_USEC="USEC_FMT, kernel_usec,
                                    "INITRD_USEC="USEC_FMT, initrd_usec,
                                    "USERSPACE_USEC="USEC_FMT, userspace_usec,
-                                   "MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
-                                   format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
-                                   format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
-                                   format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
-                                   format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
+                                   LOG_MESSAGE("Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
+                                               format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
+                                               format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
+                                               format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
+                                               format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)),
                                    NULL);
                 } else {
                         kernel_usec = m->userspace_timestamp.monotonic - m->kernel_timestamp.monotonic;
                         initrd_usec = 0;
 
                         log_struct(LOG_INFO,
-                                   MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
                                    "KERNEL_USEC="USEC_FMT, kernel_usec,
                                    "USERSPACE_USEC="USEC_FMT, userspace_usec,
-                                   "MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
-                                   format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
-                                   format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
-                                   format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
+                                   LOG_MESSAGE("Startup finished in %s (kernel) + %s (userspace) = %s.",
+                                               format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
+                                               format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
+                                               format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)),
                                    NULL);
                 }
         } else {
@@ -2612,10 +2619,10 @@ static void manager_notify_finished(Manager *m) {
                 total_usec = userspace_usec = m->finish_timestamp.monotonic - m->userspace_timestamp.monotonic;
 
                 log_struct(LOG_INFO,
-                           MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
+                           LOG_MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
                            "USERSPACE_USEC="USEC_FMT, userspace_usec,
-                           "MESSAGE=Startup finished in %s.",
-                           format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
+                           LOG_MESSAGE("Startup finished in %s.",
+                                       format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)),
                            NULL);
         }
 
@@ -2954,12 +2961,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);