chiark / gitweb /
load-fragment: a few modernizations
[elogind.git] / src / core / job.c
index 301d83a9dc1b51fbc1b1a01916c0e64f18c00c0e..8d51aa3fdd7036be8286f3acb2cd3b45663bf84a 100644 (file)
@@ -470,11 +470,10 @@ int job_run_and_invalidate(Job *j) {
         assert(j);
         assert(j->installed);
         assert(j->type < _JOB_TYPE_MAX_IN_TRANSACTION);
+        assert(j->in_run_queue);
 
-        if (j->in_run_queue) {
-                LIST_REMOVE(Job, run_queue, j->manager->run_queue, j);
-                j->in_run_queue = false;
-        }
+        LIST_REMOVE(Job, run_queue, j->manager->run_queue, j);
+        j->in_run_queue = false;
 
         if (j->state != JOB_WAITING)
                 return 0;
@@ -551,50 +550,71 @@ int job_run_and_invalidate(Job *j) {
 }
 
 static void job_print_status_message(Unit *u, JobType t, JobResult result) {
-        assert(u);
+        const UnitStatusMessageFormats *format_table;
+        const char *format;
+
+        format_table = &UNIT_VTABLE(u)->status_message_formats;
+        if (!format_table)
+                return;
 
         if (t == JOB_START) {
 
+                format = format_table->finished_start_job[result];
+                if (!format)
+                        return;
+
                 switch (result) {
 
                 case JOB_DONE:
                         if (u->condition_result)
-                                unit_status_printf(u, ANSI_HIGHLIGHT_GREEN_ON "  OK  " ANSI_HIGHLIGHT_OFF, "Started %s.", unit_description(u));
+                                unit_status_printf(u, ANSI_HIGHLIGHT_GREEN_ON "  OK  " ANSI_HIGHLIGHT_OFF, format, unit_description(u));
                         break;
 
                 case JOB_FAILED:
-                        unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON "FAILED" ANSI_HIGHLIGHT_OFF, "Failed to start %s.", unit_description(u));
-                        unit_status_printf(u, NULL, "See 'systemctl status %s' for details.", u->id);
+                        unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON "FAILED" ANSI_HIGHLIGHT_OFF, format, unit_description(u));
+                        unit_status_printf(u, "", "See 'systemctl status %s' for details.", u->id);
                         break;
 
                 case JOB_DEPENDENCY:
-                        unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " ABORT" ANSI_HIGHLIGHT_OFF, "Dependency failed. Aborted start of %s.", unit_description(u));
+                        unit_status_printf(u, ANSI_HIGHLIGHT_YELLOW_ON "DEPEND" ANSI_HIGHLIGHT_OFF, format, unit_description(u));
                         break;
 
                 case JOB_TIMEOUT:
-                        unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " TIME " ANSI_HIGHLIGHT_OFF, "Timed out starting %s.", unit_description(u));
+                        unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " TIME " ANSI_HIGHLIGHT_OFF, format, unit_description(u));
                         break;
 
                 default:
                         ;
                 }
 
-        } else if (t == JOB_STOP) {
+        } else if (t == JOB_STOP || t == JOB_RESTART) {
+
+                format = format_table->finished_stop_job[result];
+                if (!format)
+                        return;
 
                 switch (result) {
 
                 case JOB_TIMEOUT:
-                        unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " TIME " ANSI_HIGHLIGHT_OFF, "Timed out stopping %s.", unit_description(u));
+                        unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON " TIME " ANSI_HIGHLIGHT_OFF, format, unit_description(u));
                         break;
 
                 case JOB_DONE:
                 case JOB_FAILED:
-                        unit_status_printf(u, ANSI_HIGHLIGHT_GREEN_ON "  OK  " ANSI_HIGHLIGHT_OFF, "Stopped %s.", unit_description(u));
+                        unit_status_printf(u, ANSI_HIGHLIGHT_GREEN_ON "  OK  " ANSI_HIGHLIGHT_OFF, format, unit_description(u));
                         break;
 
                 default:
                         ;
                 }
+
+        } else if (t == JOB_VERIFY_ACTIVE) {
+
+                /* When verify-active detects the unit is inactive, report it.
+                 * Most likely a DEPEND warning from a requisiting unit will
+                 * occur next and it's nice to see what was requisited. */
+                if (result == JOB_SKIPPED)
+                        unit_status_printf(u, ANSI_HIGHLIGHT_ON " INFO " ANSI_HIGHLIGHT_OFF, "%s is not active.", unit_description(u));
         }
 }
 
@@ -608,34 +628,34 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
         assert(j->installed);
         assert(j->type < _JOB_TYPE_MAX_IN_TRANSACTION);
 
+        u = j->unit;
+        t = j->type;
+
+        j->result = result;
+
+        log_debug("Job %s/%s finished, result=%s", u->id, job_type_to_string(t), job_result_to_string(result));
+
+        job_print_status_message(u, t, result);
+
         job_add_to_dbus_queue(j);
 
         /* Patch restart jobs so that they become normal start jobs */
-        if (result == JOB_DONE && j->type == JOB_RESTART) {
+        if (result == JOB_DONE && t == JOB_RESTART) {
 
                 job_change_type(j, JOB_START);
                 j->state = JOB_WAITING;
 
                 job_add_to_run_queue(j);
 
-                u = j->unit;
                 goto finish;
         }
 
-        j->result = result;
-
-        log_debug("Job %s/%s finished, result=%s", j->unit->id, job_type_to_string(j->type), job_result_to_string(result));
-
         if (result == JOB_FAILED)
                 j->manager->n_failed_jobs ++;
 
-        u = j->unit;
-        t = j->type;
         job_uninstall(j);
         job_free(j);
 
-        job_print_status_message(u, t, result);
-
         /* Fail depending jobs on failure */
         if (result != JOB_DONE && recursive) {