chiark / gitweb /
job: always add waiting jobs to run queue during coldplug
[elogind.git] / src / core / job.c
index 93fa44a506a050ceae598d315c76130cddf46dde..dc4f44150c3c6fbc091092762ad36ef74ac07436 100644 (file)
@@ -37,7 +37,7 @@
 #include "special.h"
 #include "async.h"
 #include "virt.h"
-#include "dbus-client-track.h"
+#include "dbus.h"
 
 Job* job_new_raw(Unit *unit) {
         Job *j;
@@ -90,7 +90,8 @@ void job_free(Job *j) {
 
         sd_event_source_unref(j->timer_event_source);
 
-        bus_client_track_free(j->subscribed);
+        sd_bus_track_unref(j->subscribed);
+        strv_free(j->deserialized_subscribed);
 
         free(j);
 }
@@ -610,8 +611,6 @@ _pure_ static const char *job_get_status_message_format_try_harder(Unit *u, JobT
         return NULL;
 }
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
 static void job_print_status_message(Unit *u, JobType t, JobResult result) {
         const char *format;
 
@@ -619,6 +618,8 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
         assert(t >= 0);
         assert(t < _JOB_TYPE_MAX);
 
+        DISABLE_WARNING_FORMAT_NONLITERAL;
+
         if (t == JOB_START) {
                 format = job_get_status_message_format(u, t, result);
                 if (!format)
@@ -681,11 +682,10 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
                 if (result == JOB_SKIPPED)
                         unit_status_printf(u, ANSI_HIGHLIGHT_ON " INFO " ANSI_HIGHLIGHT_OFF, "%s is not active.");
         }
+
+        REENABLE_WARNING;
 }
-#pragma GCC diagnostic pop
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
 static void job_log_status_message(Unit *u, JobType t, JobResult result) {
         const char *format;
         char buf[LINE_MAX];
@@ -704,8 +704,10 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
         if (!format)
                 return;
 
+        DISABLE_WARNING_FORMAT_NONLITERAL;
         snprintf(buf, sizeof(buf), format, unit_description(u));
         char_array_0(buf);
+        REENABLE_WARNING;
 
         if (t == JOB_START) {
                 sd_id128_t mid;
@@ -734,7 +736,6 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
                            "MESSAGE=%s", buf,
                            NULL);
 }
-#pragma GCC diagnostic pop
 
 int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
         Unit *u;
@@ -872,7 +873,12 @@ int job_start_timer(Job *j) {
         if (j->unit->job_timeout <= 0)
                 return 0;
 
-        r = sd_event_add_monotonic(j->manager->event, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j, &j->timer_event_source);
+        r = sd_event_add_time(
+                        j->manager->event,
+                        &j->timer_event_source,
+                        CLOCK_MONOTONIC,
+                        j->begin_usec + j->unit->job_timeout, 0,
+                        job_dispatch_timer, j);
         if (r < 0)
                 return r;
 
@@ -931,7 +937,7 @@ int job_serialize(Job *j, FILE *f, FDSet *fds) {
         if (j->begin_usec > 0)
                 fprintf(f, "job-begin="USEC_FMT"\n", j->begin_usec);
 
-        bus_client_track_serialize(j->manager, f, j->subscribed);
+        bus_track_serialize(j->subscribed, f);
 
         /* End marker */
         fputc('\n', f);
@@ -1035,13 +1041,10 @@ int job_deserialize(Job *j, FILE *f, FDSet *fds) {
                         else
                                 j->begin_usec = ull;
 
-                } else {
-                        char t[strlen(l) + 1 + strlen(v) + 1];
-
-                        strcpy(stpcpy(stpcpy(t, l), "="), v);
+                } else if (streq(l, "subscribed")) {
 
-                        if (bus_client_track_deserialize_item(j->manager, &j->subscribed, t) == 0)
-                                log_debug("Unknown deserialization key '%s'", l);
+                        if (strv_extend(&j->deserialized_subscribed, v) < 0)
+                                return log_oom();
                 }
         }
 }
@@ -1051,13 +1054,27 @@ int job_coldplug(Job *j) {
 
         assert(j);
 
-        if (j->begin_usec <= 0)
+        /* After deserialization is complete and the bus connection
+         * set up again, let's start watching our subscribers again */
+        r = bus_track_coldplug(j->manager, &j->subscribed, &j->deserialized_subscribed);
+        if (r < 0)
+                return r;
+
+        if (j->state == JOB_WAITING)
+                job_add_to_run_queue(j);
+
+        if (j->begin_usec == 0 || j->unit->job_timeout == 0)
                 return 0;
 
         if (j->timer_event_source)
                 j->timer_event_source = sd_event_source_unref(j->timer_event_source);
 
-        r = sd_event_add_monotonic(j->manager->event, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j, &j->timer_event_source);
+        r = sd_event_add_time(
+                        j->manager->event,
+                        &j->timer_event_source,
+                        CLOCK_MONOTONIC,
+                        j->begin_usec + j->unit->job_timeout, 0,
+                        job_dispatch_timer, j);
         if (r < 0)
                 log_debug("Failed to restart timeout for job: %s", strerror(-r));
 
@@ -1118,9 +1135,6 @@ int job_get_timeout(Job *j, uint64_t *timeout) {
 
         *timeout = MIN(x, y);
 
-        log_info("job_get_timeout %s %d/%"PRIu64" %d/%"PRIu64" -> 1/%"PRIu64,
-                 j->unit->id, r, x, q, y, *timeout);
-
         return 1;
 }
 
@@ -1149,9 +1163,9 @@ static const char* const job_mode_table[_JOB_MODE_MAX] = {
         [JOB_REPLACE] = "replace",
         [JOB_REPLACE_IRREVERSIBLY] = "replace-irreversibly",
         [JOB_ISOLATE] = "isolate",
+        [JOB_FLUSH] = "flush",
         [JOB_IGNORE_DEPENDENCIES] = "ignore-dependencies",
         [JOB_IGNORE_REQUIREMENTS] = "ignore-requirements",
-        [JOB_FLUSH] = "flush",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(job_mode, JobMode);