1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "sd-messages.h"
8 #include "alloc-util.h"
18 #include "parse-util.h"
19 #include "serialize.h"
21 #include "sort-util.h"
23 #include "stdio-util.h"
24 #include "string-table.h"
25 #include "string-util.h"
27 #include "terminal-util.h"
31 Job
* job_new_raw(Unit
*unit
) {
34 /* used for deserialization */
43 .manager
= unit
->manager
,
45 .type
= _JOB_TYPE_INVALID
,
51 Job
* job_new(Unit
*unit
, JobType type
) {
54 assert(type
< _JOB_TYPE_MAX
);
56 j
= job_new_raw(unit
);
60 j
->id
= j
->manager
->current_job_id
++;
63 /* We don't link it here, that's what job_dependency() is for */
68 void job_unlink(Job
*j
) {
70 assert(!j
->installed
);
71 assert(!j
->transaction_prev
);
72 assert(!j
->transaction_next
);
73 assert(!j
->subject_list
);
74 assert(!j
->object_list
);
76 if (j
->in_run_queue
) {
77 prioq_remove(j
->manager
->run_queue
, j
, &j
->run_queue_idx
);
78 j
->in_run_queue
= false;
81 if (j
->in_dbus_queue
) {
82 LIST_REMOVE(dbus_queue
, j
->manager
->dbus_job_queue
, j
);
83 j
->in_dbus_queue
= false;
87 LIST_REMOVE(gc_queue
, j
->manager
->gc_job_queue
, j
);
88 j
->in_gc_queue
= false;
91 j
->timer_event_source
= sd_event_source_unref(j
->timer_event_source
);
94 Job
* job_free(Job
*j
) {
96 assert(!j
->installed
);
97 assert(!j
->transaction_prev
);
98 assert(!j
->transaction_next
);
99 assert(!j
->subject_list
);
100 assert(!j
->object_list
);
104 sd_bus_track_unref(j
->bus_track
);
105 strv_free(j
->deserialized_clients
);
110 static void job_set_state(Job
*j
, JobState state
) {
113 assert(state
< _JOB_STATE_MAX
);
115 if (j
->state
== state
)
123 if (j
->state
== JOB_RUNNING
)
124 j
->unit
->manager
->n_running_jobs
++;
126 assert(j
->state
== JOB_WAITING
);
127 assert(j
->unit
->manager
->n_running_jobs
> 0);
129 j
->unit
->manager
->n_running_jobs
--;
131 if (j
->unit
->manager
->n_running_jobs
<= 0)
132 j
->unit
->manager
->jobs_in_progress_event_source
= sd_event_source_unref(j
->unit
->manager
->jobs_in_progress_event_source
);
136 void job_uninstall(Job
*j
) {
139 assert(j
->installed
);
141 job_set_state(j
, JOB_WAITING
);
143 pj
= (j
->type
== JOB_NOP
) ? &j
->unit
->nop_job
: &j
->unit
->job
;
146 /* Detach from next 'bigger' objects */
148 /* daemon-reload should be transparent to job observers */
149 if (!MANAGER_IS_RELOADING(j
->manager
))
150 bus_job_send_removed_signal(j
);
154 unit_add_to_gc_queue(j
->unit
);
156 unit_add_to_dbus_queue(j
->unit
); /* The Job property of the unit has changed now */
158 hashmap_remove_value(j
->manager
->jobs
, UINT32_TO_PTR(j
->id
), j
);
159 j
->installed
= false;
162 static bool job_type_allows_late_merge(JobType t
) {
163 /* Tells whether it is OK to merge a job of type 't' with an already
165 * Reloads cannot be merged this way. Think of the sequence:
166 * 1. Reload of a daemon is in progress; the daemon has already loaded
167 * its config file, but hasn't completed the reload operation yet.
168 * 2. Edit foo's config file.
169 * 3. Trigger another reload to have the daemon use the new config.
170 * Should the second reload job be merged into the first one, the daemon
171 * would not know about the new config.
172 * JOB_RESTART jobs on the other hand can be merged, because they get
173 * patched into JOB_START after stopping the unit. So if we see a
174 * JOB_RESTART running, it means the unit hasn't stopped yet and at
175 * this time the merge is still allowed. */
176 return t
!= JOB_RELOAD
;
179 static void job_merge_into_installed(Job
*j
, Job
*other
) {
180 assert(j
->installed
);
181 assert(j
->unit
== other
->unit
);
183 if (j
->type
!= JOB_NOP
)
184 assert_se(job_type_merge_and_collapse(&j
->type
, other
->type
, j
->unit
) == 0);
186 assert(other
->type
== JOB_NOP
);
188 j
->irreversible
= j
->irreversible
|| other
->irreversible
;
189 j
->ignore_order
= j
->ignore_order
|| other
->ignore_order
;
192 Job
* job_install(Job
*j
) {
196 assert(!j
->installed
);
197 assert(j
->type
< _JOB_TYPE_MAX_IN_TRANSACTION
);
198 assert(j
->state
== JOB_WAITING
);
200 pj
= (j
->type
== JOB_NOP
) ? &j
->unit
->nop_job
: &j
->unit
->job
;
204 if (job_type_is_conflicting(uj
->type
, j
->type
))
205 job_finish_and_invalidate(uj
, JOB_CANCELED
, false, false);
207 /* not conflicting, i.e. mergeable */
209 if (uj
->state
== JOB_WAITING
||
210 (job_type_allows_late_merge(j
->type
) && job_type_is_superset(uj
->type
, j
->type
))) {
211 job_merge_into_installed(uj
, j
);
212 log_unit_debug(uj
->unit
,
213 "Merged %s/%s into installed job %s/%s as %"PRIu32
,
214 j
->unit
->id
, job_type_to_string(j
->type
), uj
->unit
->id
,
215 job_type_to_string(uj
->type
), uj
->id
);
218 /* already running and not safe to merge into */
219 /* Patch uj to become a merged job and re-run it. */
220 /* XXX It should be safer to queue j to run after uj finishes, but it is
221 * not currently possible to have more than one installed job per unit. */
222 job_merge_into_installed(uj
, j
);
223 log_unit_debug(uj
->unit
,
224 "Merged into running job, re-running: %s/%s as %"PRIu32
,
225 uj
->unit
->id
, job_type_to_string(uj
->type
), uj
->id
);
227 job_set_state(uj
, JOB_WAITING
);
233 /* Install the job */
237 j
->manager
->n_installed_jobs
++;
238 log_unit_debug(j
->unit
,
239 "Installed new job %s/%s as %u",
240 j
->unit
->id
, job_type_to_string(j
->type
), (unsigned) j
->id
);
242 job_add_to_gc_queue(j
);
244 job_add_to_dbus_queue(j
); /* announce this job to clients */
245 unit_add_to_dbus_queue(j
->unit
); /* The Job property of the unit has changed now */
250 int job_install_deserialized(Job
*j
) {
254 assert(!j
->installed
);
256 if (j
->type
< 0 || j
->type
>= _JOB_TYPE_MAX_IN_TRANSACTION
)
257 return log_unit_debug_errno(j
->unit
, SYNTHETIC_ERRNO(EINVAL
),
258 "Invalid job type %s in deserialization.",
259 strna(job_type_to_string(j
->type
)));
261 pj
= (j
->type
== JOB_NOP
) ? &j
->unit
->nop_job
: &j
->unit
->job
;
263 return log_unit_debug_errno(j
->unit
, SYNTHETIC_ERRNO(EEXIST
),
264 "Unit already has a job installed. Not installing deserialized job.");
266 r
= hashmap_ensure_put(&j
->manager
->jobs
, NULL
, UINT32_TO_PTR(j
->id
), j
);
268 return log_unit_debug_errno(j
->unit
, r
, "Job ID %" PRIu32
" already used, cannot deserialize job.", j
->id
);
270 return log_unit_debug_errno(j
->unit
, r
, "Failed to insert job into jobs hash table: %m");
275 if (j
->state
== JOB_RUNNING
)
276 j
->unit
->manager
->n_running_jobs
++;
278 log_unit_debug(j
->unit
,
279 "Reinstalled deserialized job %s/%s as %u",
280 j
->unit
->id
, job_type_to_string(j
->type
), (unsigned) j
->id
);
284 JobDependency
* job_dependency_new(Job
*subject
, Job
*object
, bool matters
, bool conflicts
) {
289 /* Adds a new job link, which encodes that the 'subject' job
290 * needs the 'object' job in some way. If 'subject' is NULL
291 * this means the 'anchor' job (i.e. the one the user
292 * explicitly asked for) is the requester. */
294 l
= new0(JobDependency
, 1);
298 l
->subject
= subject
;
300 l
->matters
= matters
;
301 l
->conflicts
= conflicts
;
304 LIST_PREPEND(subject
, subject
->subject_list
, l
);
306 LIST_PREPEND(object
, object
->object_list
, l
);
311 void job_dependency_free(JobDependency
*l
) {
315 LIST_REMOVE(subject
, l
->subject
->subject_list
, l
);
317 LIST_REMOVE(object
, l
->object
->object_list
, l
);
322 void job_dump(Job
*j
, FILE *f
, const char *prefix
) {
326 prefix
= strempty(prefix
);
330 "%s\tAction: %s -> %s\n"
332 "%s\tIrreversible: %s\n"
335 prefix
, j
->unit
->id
, job_type_to_string(j
->type
),
336 prefix
, job_state_to_string(j
->state
),
337 prefix
, yes_no(j
->irreversible
),
338 prefix
, yes_no(job_may_gc(j
)));
342 * Merging is commutative, so imagine the matrix as symmetric. We store only
343 * its lower triangle to avoid duplication. We don't store the main diagonal,
344 * because A merged with A is simply A.
346 * If the resulting type is collapsed immediately afterwards (to get rid of
347 * the JOB_RELOAD_OR_START, which lies outside the lookup function's domain),
348 * the following properties hold:
350 * Merging is associative! A merged with B, and then merged with C is the same
351 * as A merged with the result of B merged with C.
353 * Mergeability is transitive! If A can be merged with B and B with C then
356 * Also, if A merged with B cannot be merged with C, then either A or B cannot
357 * be merged with C either.
359 static const JobType job_merging_table
[] = {
360 /* What \ With * JOB_START JOB_VERIFY_ACTIVE JOB_STOP JOB_RELOAD */
361 /*********************************************************************************/
363 /*JOB_VERIFY_ACTIVE */ JOB_START
,
364 /*JOB_STOP */ -1, -1,
365 /*JOB_RELOAD */ JOB_RELOAD_OR_START
, JOB_RELOAD
, -1,
366 /*JOB_RESTART */ JOB_RESTART
, JOB_RESTART
, -1, JOB_RESTART
,
369 JobType
job_type_lookup_merge(JobType a
, JobType b
) {
370 assert_cc(ELEMENTSOF(job_merging_table
) == _JOB_TYPE_MAX_MERGING
* (_JOB_TYPE_MAX_MERGING
- 1) / 2);
371 assert(a
>= 0 && a
< _JOB_TYPE_MAX_MERGING
);
372 assert(b
>= 0 && b
< _JOB_TYPE_MAX_MERGING
);
383 return job_merging_table
[(a
- 1) * a
/ 2 + b
];
386 bool job_type_is_redundant(JobType a
, UnitActiveState b
) {
390 return IN_SET(b
, UNIT_ACTIVE
, UNIT_RELOADING
);
393 return IN_SET(b
, UNIT_INACTIVE
, UNIT_FAILED
);
395 case JOB_VERIFY_ACTIVE
:
396 return IN_SET(b
, UNIT_ACTIVE
, UNIT_RELOADING
);
404 b
== UNIT_ACTIVATING
;
410 assert_not_reached("Invalid job type");
414 JobType
job_type_collapse(JobType t
, Unit
*u
) {
419 case JOB_TRY_RESTART
:
420 s
= unit_active_state(u
);
421 if (!UNIT_IS_ACTIVE_OR_RELOADING(s
))
427 s
= unit_active_state(u
);
428 if (!UNIT_IS_ACTIVE_OR_RELOADING(s
))
433 case JOB_RELOAD_OR_START
:
434 s
= unit_active_state(u
);
435 if (!UNIT_IS_ACTIVE_OR_RELOADING(s
))
445 int job_type_merge_and_collapse(JobType
*a
, JobType b
, Unit
*u
) {
448 t
= job_type_lookup_merge(*a
, b
);
452 *a
= job_type_collapse(t
, u
);
456 static bool job_is_runnable(Job
*j
) {
461 assert(j
->installed
);
463 /* Checks whether there is any job running for the units this
464 * job needs to be running after (in the case of a 'positive'
465 * job type) or before (in the case of a 'negative' job
468 /* Note that unit types have a say in what is runnable,
469 * too. For example, if they return -EAGAIN from
470 * unit_start() they can indicate they are not
473 /* First check if there is an override */
477 if (j
->type
== JOB_NOP
)
480 HASHMAP_FOREACH_KEY(v
, other
, j
->unit
->dependencies
[UNIT_AFTER
])
481 if (other
->job
&& job_compare(j
, other
->job
, UNIT_AFTER
) > 0) {
482 log_unit_debug(j
->unit
,
483 "starting held back, waiting for: %s",
488 HASHMAP_FOREACH_KEY(v
, other
, j
->unit
->dependencies
[UNIT_BEFORE
])
489 if (other
->job
&& job_compare(j
, other
->job
, UNIT_BEFORE
) > 0) {
490 log_unit_debug(j
->unit
,
491 "stopping held back, waiting for: %s",
499 static void job_change_type(Job
*j
, JobType newtype
) {
502 log_unit_debug(j
->unit
,
503 "Converting job %s/%s -> %s/%s",
504 j
->unit
->id
, job_type_to_string(j
->type
),
505 j
->unit
->id
, job_type_to_string(newtype
));
510 _pure_
static const char* job_get_begin_status_message_format(Unit
*u
, JobType t
) {
516 return "Reloading %s.";
518 assert(IN_SET(t
, JOB_START
, JOB_STOP
));
520 format
= UNIT_VTABLE(u
)->status_message_formats
.starting_stopping
[t
== JOB_STOP
];
524 /* Return generic strings */
526 return "Starting %s.";
528 assert(t
== JOB_STOP
);
529 return "Stopping %s.";
533 static void job_print_begin_status_message(Unit
*u
, JobType t
) {
538 /* Reload status messages have traditionally not been printed to console. */
539 if (!IN_SET(t
, JOB_START
, JOB_STOP
))
542 format
= job_get_begin_status_message_format(u
, t
);
544 DISABLE_WARNING_FORMAT_NONLITERAL
;
545 unit_status_printf(u
, STATUS_TYPE_NORMAL
, "", format
);
549 static void job_log_begin_status_message(Unit
*u
, uint32_t job_id
, JobType t
) {
550 const char *format
, *mid
;
555 assert(t
< _JOB_TYPE_MAX
);
557 if (!IN_SET(t
, JOB_START
, JOB_STOP
, JOB_RELOAD
))
560 if (log_on_console()) /* Skip this if it would only go on the console anyway */
563 /* We log status messages for all units and all operations. */
565 format
= job_get_begin_status_message_format(u
, t
);
567 DISABLE_WARNING_FORMAT_NONLITERAL
;
568 (void) snprintf(buf
, sizeof buf
, format
, unit_status_string(u
));
571 mid
= t
== JOB_START
? "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTING_STR
:
572 t
== JOB_STOP
? "MESSAGE_ID=" SD_MESSAGE_UNIT_STOPPING_STR
:
573 "MESSAGE_ID=" SD_MESSAGE_UNIT_RELOADING_STR
;
575 /* Note that we deliberately use LOG_MESSAGE() instead of
576 * LOG_UNIT_MESSAGE() here, since this is supposed to mimic
577 * closely what is written to screen using the status output,
578 * which is supposed the highest level, friendliest output
579 * possible, which means we should avoid the low-level unit
582 LOG_MESSAGE("%s", buf
),
583 "JOB_ID=%" PRIu32
, job_id
,
584 "JOB_TYPE=%s", job_type_to_string(t
),
586 LOG_UNIT_INVOCATION_ID(u
),
590 static void job_emit_begin_status_message(Unit
*u
, uint32_t job_id
, JobType t
) {
593 assert(t
< _JOB_TYPE_MAX
);
595 job_log_begin_status_message(u
, job_id
, t
);
596 job_print_begin_status_message(u
, t
);
599 static int job_perform_on_unit(Job
**j
) {
606 /* While we execute this operation the job might go away (for
607 * example: because it finishes immediately or is replaced by
608 * a new, conflicting job.) To make sure we don't access a
609 * freed job later on we store the id here, so that we can
610 * verify the job is still valid. */
637 assert_not_reached("Invalid job type");
640 /* Log if the job still exists and the start/stop/reload function actually did something. Note that this means
641 * for units for which there's no 'activating' phase (i.e. because we transition directly from 'inactive' to
642 * 'active') we'll possibly skip the "Starting..." message. */
643 *j
= manager_get_job(m
, id
);
645 job_emit_begin_status_message(u
, id
, t
);
650 int job_run_and_invalidate(Job
*j
) {
654 assert(j
->installed
);
655 assert(j
->type
< _JOB_TYPE_MAX_IN_TRANSACTION
);
656 assert(j
->in_run_queue
);
658 prioq_remove(j
->manager
->run_queue
, j
, &j
->run_queue_idx
);
659 j
->in_run_queue
= false;
661 if (j
->state
!= JOB_WAITING
)
664 if (!job_is_runnable(j
))
667 job_start_timer(j
, true);
668 job_set_state(j
, JOB_RUNNING
);
669 job_add_to_dbus_queue(j
);
673 case JOB_VERIFY_ACTIVE
: {
676 t
= unit_active_state(j
->unit
);
677 if (UNIT_IS_ACTIVE_OR_RELOADING(t
))
679 else if (t
== UNIT_ACTIVATING
)
689 r
= job_perform_on_unit(&j
);
691 /* If the unit type does not support starting/stopping, then simply wait. */
697 r
= job_perform_on_unit(&j
);
705 assert_not_reached("Unknown job type");
710 job_set_state(j
, JOB_WAITING
); /* Hmm, not ready after all, let's return to JOB_WAITING state */
711 else if (r
== -EALREADY
) /* already being executed */
712 r
= job_finish_and_invalidate(j
, JOB_DONE
, true, true);
713 else if (r
== -ECOMM
) /* condition failed, but all is good */
714 r
= job_finish_and_invalidate(j
, JOB_DONE
, true, false);
715 else if (r
== -EBADR
)
716 r
= job_finish_and_invalidate(j
, JOB_SKIPPED
, true, false);
717 else if (r
== -ENOEXEC
)
718 r
= job_finish_and_invalidate(j
, JOB_INVALID
, true, false);
719 else if (r
== -EPROTO
)
720 r
= job_finish_and_invalidate(j
, JOB_ASSERT
, true, false);
721 else if (r
== -EOPNOTSUPP
)
722 r
= job_finish_and_invalidate(j
, JOB_UNSUPPORTED
, true, false);
723 else if (r
== -ENOLINK
)
724 r
= job_finish_and_invalidate(j
, JOB_DEPENDENCY
, true, false);
725 else if (r
== -ESTALE
)
726 r
= job_finish_and_invalidate(j
, JOB_ONCE
, true, false);
728 r
= job_finish_and_invalidate(j
, JOB_FAILED
, true, false);
734 _pure_
static const char *job_get_done_status_message_format(Unit
*u
, JobType t
, JobResult result
) {
736 static const char *const generic_finished_start_job
[_JOB_RESULT_MAX
] = {
737 [JOB_DONE
] = "Started %s.",
738 [JOB_TIMEOUT
] = "Timed out starting %s.",
739 [JOB_FAILED
] = "Failed to start %s.",
740 [JOB_DEPENDENCY
] = "Dependency failed for %s.",
741 [JOB_ASSERT
] = "Assertion failed for %s.",
742 [JOB_UNSUPPORTED
] = "Starting of %s not supported.",
743 [JOB_COLLECTED
] = "Unnecessary job for %s was removed.",
744 [JOB_ONCE
] = "Unit %s has been started before and cannot be started again."
746 static const char *const generic_finished_stop_job
[_JOB_RESULT_MAX
] = {
747 [JOB_DONE
] = "Stopped %s.",
748 [JOB_FAILED
] = "Stopped (with error) %s.",
749 [JOB_TIMEOUT
] = "Timed out stopping %s.",
751 static const char *const generic_finished_reload_job
[_JOB_RESULT_MAX
] = {
752 [JOB_DONE
] = "Reloaded %s.",
753 [JOB_FAILED
] = "Reload failed for %s.",
754 [JOB_TIMEOUT
] = "Timed out reloading %s.",
756 /* When verify-active detects the unit is inactive, report it.
757 * Most likely a DEPEND warning from a requisiting unit will
758 * occur next and it's nice to see what was requisited. */
759 static const char *const generic_finished_verify_active_job
[_JOB_RESULT_MAX
] = {
760 [JOB_SKIPPED
] = "%s is not active.",
767 assert(t
< _JOB_TYPE_MAX
);
769 if (IN_SET(t
, JOB_START
, JOB_STOP
, JOB_RESTART
)) {
770 const UnitStatusMessageFormats
*formats
= &UNIT_VTABLE(u
)->status_message_formats
;
771 if (formats
->finished_job
) {
772 format
= formats
->finished_job(u
, t
, result
);
776 format
= t
== JOB_START
?
777 formats
->finished_start_job
[result
] :
778 formats
->finished_stop_job
[result
];
783 /* Return generic strings */
785 return generic_finished_start_job
[result
];
786 else if (IN_SET(t
, JOB_STOP
, JOB_RESTART
))
787 return generic_finished_stop_job
[result
];
788 else if (t
== JOB_RELOAD
)
789 return generic_finished_reload_job
[result
];
790 else if (t
== JOB_VERIFY_ACTIVE
)
791 return generic_finished_verify_active_job
[result
];
796 static const struct {
797 const char *color
, *word
;
798 } job_print_done_status_messages
[_JOB_RESULT_MAX
] = {
799 [JOB_DONE
] = { ANSI_OK_COLOR
, " OK " },
800 [JOB_TIMEOUT
] = { ANSI_HIGHLIGHT_RED
, " TIME " },
801 [JOB_FAILED
] = { ANSI_HIGHLIGHT_RED
, "FAILED" },
802 [JOB_DEPENDENCY
] = { ANSI_HIGHLIGHT_YELLOW
, "DEPEND" },
803 [JOB_SKIPPED
] = { ANSI_HIGHLIGHT
, " INFO " },
804 [JOB_ASSERT
] = { ANSI_HIGHLIGHT_YELLOW
, "ASSERT" },
805 [JOB_UNSUPPORTED
] = { ANSI_HIGHLIGHT_YELLOW
, "UNSUPP" },
807 [JOB_ONCE
] = { ANSI_HIGHLIGHT_RED
, " ONCE " },
810 static void job_print_done_status_message(Unit
*u
, JobType t
, JobResult result
) {
816 assert(t
< _JOB_TYPE_MAX
);
818 /* Reload status messages have traditionally not been printed to console. */
822 /* No message if the job did not actually do anything due to failed condition. */
823 if (t
== JOB_START
&& result
== JOB_DONE
&& !u
->condition_result
)
826 if (!job_print_done_status_messages
[result
].word
)
829 format
= job_get_done_status_message_format(u
, t
, result
);
833 if (log_get_show_color())
834 status
= strjoina(job_print_done_status_messages
[result
].color
,
835 job_print_done_status_messages
[result
].word
,
838 status
= job_print_done_status_messages
[result
].word
;
840 DISABLE_WARNING_FORMAT_NONLITERAL
;
841 unit_status_printf(u
,
842 result
== JOB_DONE
? STATUS_TYPE_NORMAL
: STATUS_TYPE_NOTICE
,
846 if (t
== JOB_START
&& result
== JOB_FAILED
) {
847 _cleanup_free_
char *quoted
;
849 quoted
= shell_maybe_quote(u
->id
, 0);
850 manager_status_printf(u
->manager
, STATUS_TYPE_NORMAL
, NULL
, "See 'systemctl status %s' for details.", strna(quoted
));
854 static void job_log_done_status_message(Unit
*u
, uint32_t job_id
, JobType t
, JobResult result
) {
855 const char *format
, *mid
;
857 static const int job_result_log_level
[_JOB_RESULT_MAX
] = {
858 [JOB_DONE
] = LOG_INFO
,
859 [JOB_CANCELED
] = LOG_INFO
,
860 [JOB_TIMEOUT
] = LOG_ERR
,
861 [JOB_FAILED
] = LOG_ERR
,
862 [JOB_DEPENDENCY
] = LOG_WARNING
,
863 [JOB_SKIPPED
] = LOG_NOTICE
,
864 [JOB_INVALID
] = LOG_INFO
,
865 [JOB_ASSERT
] = LOG_WARNING
,
866 [JOB_UNSUPPORTED
] = LOG_WARNING
,
867 [JOB_COLLECTED
] = LOG_INFO
,
868 [JOB_ONCE
] = LOG_ERR
,
873 assert(t
< _JOB_TYPE_MAX
);
875 /* Skip printing if output goes to the console, and job_print_status_message()
876 will actually print something to the console. */
877 if (log_on_console() && job_print_done_status_messages
[result
].word
)
880 /* Show condition check message if the job did not actually do anything due to failed condition. */
881 if (t
== JOB_START
&& result
== JOB_DONE
&& !u
->condition_result
) {
883 "MESSAGE=Condition check resulted in %s being skipped.", unit_status_string(u
),
884 "JOB_ID=%" PRIu32
, job_id
,
885 "JOB_TYPE=%s", job_type_to_string(t
),
886 "JOB_RESULT=%s", job_result_to_string(result
),
888 LOG_UNIT_INVOCATION_ID(u
),
889 "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTED_STR
);
894 format
= job_get_done_status_message_format(u
, t
, result
);
898 /* The description might be longer than the buffer, but that's OK,
899 * we'll just truncate it here. Note that we use snprintf() rather than
900 * xsprintf() on purpose here: we are fine with truncation and don't
901 * consider that an error. */
902 DISABLE_WARNING_FORMAT_NONLITERAL
;
903 (void) snprintf(buf
, sizeof(buf
), format
, unit_status_string(u
));
909 if (result
== JOB_DONE
)
910 mid
= "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTED_STR
;
912 mid
= "MESSAGE_ID=" SD_MESSAGE_UNIT_FAILED_STR
;
916 mid
= "MESSAGE_ID=" SD_MESSAGE_UNIT_RELOADED_STR
;
921 mid
= "MESSAGE_ID=" SD_MESSAGE_UNIT_STOPPED_STR
;
925 log_struct(job_result_log_level
[result
],
926 LOG_MESSAGE("%s", buf
),
927 "JOB_ID=%" PRIu32
, job_id
,
928 "JOB_TYPE=%s", job_type_to_string(t
),
929 "JOB_RESULT=%s", job_result_to_string(result
),
931 LOG_UNIT_INVOCATION_ID(u
));
935 log_struct(job_result_log_level
[result
],
936 LOG_MESSAGE("%s", buf
),
937 "JOB_ID=%" PRIu32
, job_id
,
938 "JOB_TYPE=%s", job_type_to_string(t
),
939 "JOB_RESULT=%s", job_result_to_string(result
),
941 LOG_UNIT_INVOCATION_ID(u
),
945 static void job_emit_done_status_message(Unit
*u
, uint32_t job_id
, JobType t
, JobResult result
) {
948 job_log_done_status_message(u
, job_id
, t
, result
);
949 job_print_done_status_message(u
, t
, result
);
952 static void job_fail_dependencies(Unit
*u
, UnitDependency d
) {
958 HASHMAP_FOREACH_KEY(v
, other
, u
->dependencies
[d
]) {
963 if (!IN_SET(j
->type
, JOB_START
, JOB_VERIFY_ACTIVE
))
966 job_finish_and_invalidate(j
, JOB_DEPENDENCY
, true, false);
970 int job_finish_and_invalidate(Job
*j
, JobResult result
, bool recursive
, bool already
) {
977 assert(j
->installed
);
978 assert(j
->type
< _JOB_TYPE_MAX_IN_TRANSACTION
);
985 log_unit_debug(u
, "Job %" PRIu32
" %s/%s finished, result=%s",
986 j
->id
, u
->id
, job_type_to_string(t
), job_result_to_string(result
));
988 /* If this job did nothing to the respective unit we don't log the status message */
990 job_emit_done_status_message(u
, j
->id
, t
, result
);
992 /* Patch restart jobs so that they become normal start jobs */
993 if (result
== JOB_DONE
&& t
== JOB_RESTART
) {
995 job_change_type(j
, JOB_START
);
996 job_set_state(j
, JOB_WAITING
);
998 job_add_to_dbus_queue(j
);
999 job_add_to_run_queue(j
);
1000 job_add_to_gc_queue(j
);
1005 if (IN_SET(result
, JOB_FAILED
, JOB_INVALID
))
1006 j
->manager
->n_failed_jobs
++;
1011 /* Fail depending jobs on failure */
1012 if (result
!= JOB_DONE
&& recursive
) {
1013 if (IN_SET(t
, JOB_START
, JOB_VERIFY_ACTIVE
)) {
1014 job_fail_dependencies(u
, UNIT_REQUIRED_BY
);
1015 job_fail_dependencies(u
, UNIT_REQUISITE_OF
);
1016 job_fail_dependencies(u
, UNIT_BOUND_BY
);
1017 } else if (t
== JOB_STOP
)
1018 job_fail_dependencies(u
, UNIT_CONFLICTED_BY
);
1021 /* A special check to make sure we take down anything RequisiteOf if we
1022 * aren't active. This is when the verify-active job merges with a
1023 * satisfying job type, and then loses it's invalidation effect, as the
1024 * result there is JOB_DONE for the start job we merged into, while we
1025 * should be failing the depending job if the said unit isn't in fact
1026 * active. Oneshots are an example of this, where going directly from
1027 * activating to inactive is success.
1029 * This happens when you use ConditionXYZ= in a unit too, since in that
1030 * case the job completes with the JOB_DONE result, but the unit never
1031 * really becomes active. Note that such a case still involves merging:
1033 * A start job waits for something else, and a verify-active comes in
1034 * and merges in the installed job. Then, later, when it becomes
1035 * runnable, it finishes with JOB_DONE result as execution on conditions
1036 * not being met is skipped, breaking our dependency semantics.
1038 * Also, depending on if start job waits or not, the merging may or may
1039 * not happen (the verify-active job may trigger after it finishes), so
1040 * you get undeterministic results without this check.
1042 if (result
== JOB_DONE
&& recursive
&& !UNIT_IS_ACTIVE_OR_RELOADING(unit_active_state(u
))) {
1043 if (IN_SET(t
, JOB_START
, JOB_RELOAD
))
1044 job_fail_dependencies(u
, UNIT_REQUISITE_OF
);
1046 /* Trigger OnFailure dependencies that are not generated by
1047 * the unit itself. We don't treat JOB_CANCELED as failure in
1048 * this context. And JOB_FAILURE is already handled by the
1050 if (IN_SET(result
, JOB_TIMEOUT
, JOB_DEPENDENCY
)) {
1051 log_struct(LOG_NOTICE
,
1052 "JOB_TYPE=%s", job_type_to_string(t
),
1053 "JOB_RESULT=%s", job_result_to_string(result
),
1055 LOG_UNIT_MESSAGE(u
, "Job %s/%s failed with result '%s'.",
1057 job_type_to_string(t
),
1058 job_result_to_string(result
)));
1060 unit_start_on_failure(u
);
1063 unit_trigger_notify(u
);
1066 /* Try to start the next jobs that can be started */
1067 HASHMAP_FOREACH_KEY(v
, other
, u
->dependencies
[UNIT_AFTER
])
1069 job_add_to_run_queue(other
->job
);
1070 job_add_to_gc_queue(other
->job
);
1072 HASHMAP_FOREACH_KEY(v
, other
, u
->dependencies
[UNIT_BEFORE
])
1074 job_add_to_run_queue(other
->job
);
1075 job_add_to_gc_queue(other
->job
);
1078 manager_check_finished(u
->manager
);
1083 static int job_dispatch_timer(sd_event_source
*s
, uint64_t monotonic
, void *userdata
) {
1088 assert(s
== j
->timer_event_source
);
1090 log_unit_warning(j
->unit
, "Job %s/%s timed out.", j
->unit
->id
, job_type_to_string(j
->type
));
1093 job_finish_and_invalidate(j
, JOB_TIMEOUT
, true, false);
1095 emergency_action(u
->manager
, u
->job_timeout_action
,
1096 EMERGENCY_ACTION_IS_WATCHDOG
|EMERGENCY_ACTION_WARN
,
1097 u
->job_timeout_reboot_arg
, -1, "job timed out");
1102 int job_start_timer(Job
*j
, bool job_running
) {
1104 usec_t timeout_time
, old_timeout_time
;
1107 j
->begin_running_usec
= now(CLOCK_MONOTONIC
);
1109 if (j
->unit
->job_running_timeout
== USEC_INFINITY
)
1112 timeout_time
= usec_add(j
->begin_running_usec
, j
->unit
->job_running_timeout
);
1114 if (j
->timer_event_source
) {
1115 /* Update only if JobRunningTimeoutSec= results in earlier timeout */
1116 r
= sd_event_source_get_time(j
->timer_event_source
, &old_timeout_time
);
1120 if (old_timeout_time
<= timeout_time
)
1123 return sd_event_source_set_time(j
->timer_event_source
, timeout_time
);
1126 if (j
->timer_event_source
)
1129 j
->begin_usec
= now(CLOCK_MONOTONIC
);
1131 if (j
->unit
->job_timeout
== USEC_INFINITY
)
1134 timeout_time
= usec_add(j
->begin_usec
, j
->unit
->job_timeout
);
1137 r
= sd_event_add_time(
1139 &j
->timer_event_source
,
1142 job_dispatch_timer
, j
);
1146 (void) sd_event_source_set_description(j
->timer_event_source
, "job-start");
1151 void job_add_to_run_queue(Job
*j
) {
1155 assert(j
->installed
);
1157 if (j
->in_run_queue
)
1160 if (prioq_isempty(j
->manager
->run_queue
)) {
1161 r
= sd_event_source_set_enabled(j
->manager
->run_queue_event_source
, SD_EVENT_ONESHOT
);
1163 log_warning_errno(r
, "Failed to enable job run queue event source, ignoring: %m");
1166 r
= prioq_put(j
->manager
->run_queue
, j
, &j
->run_queue_idx
);
1168 log_warning_errno(r
, "Failed put job in run queue, ignoring: %m");
1170 j
->in_run_queue
= true;
1173 void job_add_to_dbus_queue(Job
*j
) {
1175 assert(j
->installed
);
1177 if (j
->in_dbus_queue
)
1180 /* We don't check if anybody is subscribed here, since this
1181 * job might just have been created and not yet assigned to a
1182 * connection/client. */
1184 LIST_PREPEND(dbus_queue
, j
->manager
->dbus_job_queue
, j
);
1185 j
->in_dbus_queue
= true;
1188 char *job_dbus_path(Job
*j
) {
1193 if (asprintf(&p
, "/org/freedesktop/systemd1/job/%"PRIu32
, j
->id
) < 0)
1199 int job_serialize(Job
*j
, FILE *f
) {
1203 (void) serialize_item_format(f
, "job-id", "%u", j
->id
);
1204 (void) serialize_item(f
, "job-type", job_type_to_string(j
->type
));
1205 (void) serialize_item(f
, "job-state", job_state_to_string(j
->state
));
1206 (void) serialize_bool(f
, "job-irreversible", j
->irreversible
);
1207 (void) serialize_bool(f
, "job-sent-dbus-new-signal", j
->sent_dbus_new_signal
);
1208 (void) serialize_bool(f
, "job-ignore-order", j
->ignore_order
);
1210 if (j
->begin_usec
> 0)
1211 (void) serialize_usec(f
, "job-begin", j
->begin_usec
);
1212 if (j
->begin_running_usec
> 0)
1213 (void) serialize_usec(f
, "job-begin-running", j
->begin_running_usec
);
1215 bus_track_serialize(j
->bus_track
, f
, "subscribed");
1222 int job_deserialize(Job
*j
, FILE *f
) {
1229 _cleanup_free_
char *line
= NULL
;
1233 r
= read_line(f
, LONG_LINE_MAX
, &line
);
1235 return log_error_errno(r
, "Failed to read serialization line: %m");
1245 k
= strcspn(l
, "=");
1253 if (streq(l
, "job-id")) {
1255 if (safe_atou32(v
, &j
->id
) < 0)
1256 log_debug("Failed to parse job id value: %s", v
);
1258 } else if (streq(l
, "job-type")) {
1261 t
= job_type_from_string(v
);
1263 log_debug("Failed to parse job type: %s", v
);
1264 else if (t
>= _JOB_TYPE_MAX_IN_TRANSACTION
)
1265 log_debug("Cannot deserialize job of type: %s", v
);
1269 } else if (streq(l
, "job-state")) {
1272 s
= job_state_from_string(v
);
1274 log_debug("Failed to parse job state: %s", v
);
1276 job_set_state(j
, s
);
1278 } else if (streq(l
, "job-irreversible")) {
1281 b
= parse_boolean(v
);
1283 log_debug("Failed to parse job irreversible flag: %s", v
);
1285 j
->irreversible
= j
->irreversible
|| b
;
1287 } else if (streq(l
, "job-sent-dbus-new-signal")) {
1290 b
= parse_boolean(v
);
1292 log_debug("Failed to parse job sent_dbus_new_signal flag: %s", v
);
1294 j
->sent_dbus_new_signal
= j
->sent_dbus_new_signal
|| b
;
1296 } else if (streq(l
, "job-ignore-order")) {
1299 b
= parse_boolean(v
);
1301 log_debug("Failed to parse job ignore_order flag: %s", v
);
1303 j
->ignore_order
= j
->ignore_order
|| b
;
1305 } else if (streq(l
, "job-begin"))
1306 (void) deserialize_usec(v
, &j
->begin_usec
);
1308 else if (streq(l
, "job-begin-running"))
1309 (void) deserialize_usec(v
, &j
->begin_running_usec
);
1311 else if (streq(l
, "subscribed")) {
1312 if (strv_extend(&j
->deserialized_clients
, v
) < 0)
1315 log_debug("Unknown job serialization key: %s", l
);
1319 int job_coldplug(Job
*j
) {
1321 usec_t timeout_time
= USEC_INFINITY
;
1325 /* After deserialization is complete and the bus connection
1326 * set up again, let's start watching our subscribers again */
1327 (void) bus_job_coldplug_bus_track(j
);
1329 if (j
->state
== JOB_WAITING
)
1330 job_add_to_run_queue(j
);
1332 /* Maybe due to new dependencies we don't actually need this job anymore? */
1333 job_add_to_gc_queue(j
);
1335 /* Create timer only when job began or began running and the respective timeout is finite.
1336 * Follow logic of job_start_timer() if both timeouts are finite */
1337 if (j
->begin_usec
== 0)
1340 if (j
->unit
->job_timeout
!= USEC_INFINITY
)
1341 timeout_time
= usec_add(j
->begin_usec
, j
->unit
->job_timeout
);
1343 if (timestamp_is_set(j
->begin_running_usec
))
1344 timeout_time
= MIN(timeout_time
, usec_add(j
->begin_running_usec
, j
->unit
->job_running_timeout
));
1346 if (timeout_time
== USEC_INFINITY
)
1349 j
->timer_event_source
= sd_event_source_unref(j
->timer_event_source
);
1351 r
= sd_event_add_time(
1353 &j
->timer_event_source
,
1356 job_dispatch_timer
, j
);
1358 log_debug_errno(r
, "Failed to restart timeout for job: %m");
1360 (void) sd_event_source_set_description(j
->timer_event_source
, "job-timeout");
1365 void job_shutdown_magic(Job
*j
) {
1368 /* The shutdown target gets some special treatment here: we
1369 * tell the kernel to begin with flushing its disk caches, to
1370 * optimize shutdown time a bit. Ideally we wouldn't hardcode
1371 * this magic into PID 1. However all other processes aren't
1372 * options either since they'd exit much sooner than PID 1 and
1373 * asynchronous sync() would cause their exit to be
1376 if (j
->type
!= JOB_START
)
1379 if (!MANAGER_IS_SYSTEM(j
->unit
->manager
))
1382 if (!unit_has_name(j
->unit
, SPECIAL_SHUTDOWN_TARGET
))
1385 /* In case messages on console has been disabled on boot */
1386 j
->unit
->manager
->no_console_output
= false;
1388 if (detect_container() > 0)
1391 (void) asynchronous_sync(NULL
);
1394 int job_get_timeout(Job
*j
, usec_t
*timeout
) {
1395 usec_t x
= USEC_INFINITY
, y
= USEC_INFINITY
;
1401 if (j
->timer_event_source
) {
1402 r
= sd_event_source_get_time(j
->timer_event_source
, &x
);
1407 if (UNIT_VTABLE(u
)->get_timeout
) {
1408 r
= UNIT_VTABLE(u
)->get_timeout(u
, &y
);
1413 if (x
== USEC_INFINITY
&& y
== USEC_INFINITY
)
1416 *timeout
= MIN(x
, y
);
1420 bool job_may_gc(Job
*j
) {
1426 /* Checks whether this job should be GC'ed away. We only do this for jobs of units that have no effect on their
1427 * own and just track external state. For now the only unit type that qualifies for this are .device units.
1428 * Returns true if the job can be collected. */
1430 if (!UNIT_VTABLE(j
->unit
)->gc_jobs
)
1433 if (sd_bus_track_count(j
->bus_track
) > 0)
1436 /* FIXME: So this is a bit ugly: for now we don't properly track references made via private bus connections
1437 * (because it's nasty, as sd_bus_track doesn't apply to it). We simply remember that the job was once
1438 * referenced by one, and reset this whenever we notice that no private bus connections are around. This means
1439 * the GC is a bit too conservative when it comes to jobs created by private bus connections. */
1440 if (j
->ref_by_private_bus
) {
1441 if (set_isempty(j
->unit
->manager
->private_buses
))
1442 j
->ref_by_private_bus
= false;
1447 if (j
->type
== JOB_NOP
)
1450 /* The logic is inverse to job_is_runnable, we cannot GC as long as we block any job. */
1451 HASHMAP_FOREACH_KEY(v
, other
, j
->unit
->dependencies
[UNIT_BEFORE
])
1452 if (other
->job
&& job_compare(j
, other
->job
, UNIT_BEFORE
) < 0)
1455 HASHMAP_FOREACH_KEY(v
, other
, j
->unit
->dependencies
[UNIT_AFTER
])
1456 if (other
->job
&& job_compare(j
, other
->job
, UNIT_AFTER
) < 0)
1462 void job_add_to_gc_queue(Job
*j
) {
1471 LIST_PREPEND(gc_queue
, j
->unit
->manager
->gc_job_queue
, j
);
1472 j
->in_gc_queue
= true;
1475 static int job_compare_id(Job
* const *a
, Job
* const *b
) {
1476 return CMP((*a
)->id
, (*b
)->id
);
1479 static size_t sort_job_list(Job
**list
, size_t n
) {
1480 Job
*previous
= NULL
;
1483 /* Order by numeric IDs */
1484 typesafe_qsort(list
, n
, job_compare_id
);
1486 /* Filter out duplicates */
1487 for (a
= 0, b
= 0; a
< n
; a
++) {
1489 if (previous
== list
[a
])
1492 previous
= list
[b
++] = list
[a
];
1498 int job_get_before(Job
*j
, Job
*** ret
) {
1499 _cleanup_free_ Job
** list
= NULL
;
1500 size_t n
= 0, n_allocated
= 0;
1504 /* Returns a list of all pending jobs that need to finish before this job may be started. */
1509 if (j
->ignore_order
) {
1514 HASHMAP_FOREACH_KEY(v
, other
, j
->unit
->dependencies
[UNIT_AFTER
]) {
1517 if (job_compare(j
, other
->job
, UNIT_AFTER
) <= 0)
1520 if (!GREEDY_REALLOC(list
, n_allocated
, n
+1))
1522 list
[n
++] = other
->job
;
1525 HASHMAP_FOREACH_KEY(v
, other
, j
->unit
->dependencies
[UNIT_BEFORE
]) {
1528 if (job_compare(j
, other
->job
, UNIT_BEFORE
) <= 0)
1531 if (!GREEDY_REALLOC(list
, n_allocated
, n
+1))
1533 list
[n
++] = other
->job
;
1536 n
= sort_job_list(list
, n
);
1538 *ret
= TAKE_PTR(list
);
1543 int job_get_after(Job
*j
, Job
*** ret
) {
1544 _cleanup_free_ Job
** list
= NULL
;
1545 size_t n
= 0, n_allocated
= 0;
1552 /* Returns a list of all pending jobs that are waiting for this job to finish. */
1554 HASHMAP_FOREACH_KEY(v
, other
, j
->unit
->dependencies
[UNIT_BEFORE
]) {
1558 if (other
->job
->ignore_order
)
1561 if (job_compare(j
, other
->job
, UNIT_BEFORE
) >= 0)
1564 if (!GREEDY_REALLOC(list
, n_allocated
, n
+1))
1566 list
[n
++] = other
->job
;
1569 HASHMAP_FOREACH_KEY(v
, other
, j
->unit
->dependencies
[UNIT_AFTER
]) {
1573 if (other
->job
->ignore_order
)
1576 if (job_compare(j
, other
->job
, UNIT_AFTER
) >= 0)
1579 if (!GREEDY_REALLOC(list
, n_allocated
, n
+1))
1581 list
[n
++] = other
->job
;
1584 n
= sort_job_list(list
, n
);
1586 *ret
= TAKE_PTR(list
);
1591 static const char* const job_state_table
[_JOB_STATE_MAX
] = {
1592 [JOB_WAITING
] = "waiting",
1593 [JOB_RUNNING
] = "running",
1596 DEFINE_STRING_TABLE_LOOKUP(job_state
, JobState
);
1598 static const char* const job_type_table
[_JOB_TYPE_MAX
] = {
1599 [JOB_START
] = "start",
1600 [JOB_VERIFY_ACTIVE
] = "verify-active",
1601 [JOB_STOP
] = "stop",
1602 [JOB_RELOAD
] = "reload",
1603 [JOB_RELOAD_OR_START
] = "reload-or-start",
1604 [JOB_RESTART
] = "restart",
1605 [JOB_TRY_RESTART
] = "try-restart",
1606 [JOB_TRY_RELOAD
] = "try-reload",
1610 DEFINE_STRING_TABLE_LOOKUP(job_type
, JobType
);
1612 static const char* const job_mode_table
[_JOB_MODE_MAX
] = {
1613 [JOB_FAIL
] = "fail",
1614 [JOB_REPLACE
] = "replace",
1615 [JOB_REPLACE_IRREVERSIBLY
] = "replace-irreversibly",
1616 [JOB_ISOLATE
] = "isolate",
1617 [JOB_FLUSH
] = "flush",
1618 [JOB_IGNORE_DEPENDENCIES
] = "ignore-dependencies",
1619 [JOB_IGNORE_REQUIREMENTS
] = "ignore-requirements",
1620 [JOB_TRIGGERING
] = "triggering",
1623 DEFINE_STRING_TABLE_LOOKUP(job_mode
, JobMode
);
1625 static const char* const job_result_table
[_JOB_RESULT_MAX
] = {
1626 [JOB_DONE
] = "done",
1627 [JOB_CANCELED
] = "canceled",
1628 [JOB_TIMEOUT
] = "timeout",
1629 [JOB_FAILED
] = "failed",
1630 [JOB_DEPENDENCY
] = "dependency",
1631 [JOB_SKIPPED
] = "skipped",
1632 [JOB_INVALID
] = "invalid",
1633 [JOB_ASSERT
] = "assert",
1634 [JOB_UNSUPPORTED
] = "unsupported",
1635 [JOB_COLLECTED
] = "collected",
1636 [JOB_ONCE
] = "once",
1639 DEFINE_STRING_TABLE_LOOKUP(job_result
, JobResult
);
1641 const char* job_type_to_access_method(JobType t
) {
1643 assert(t
< _JOB_TYPE_MAX
);
1645 if (IN_SET(t
, JOB_START
, JOB_RESTART
, JOB_TRY_RESTART
))
1647 else if (t
== JOB_STOP
)
1654 * assume_dep assumed dependency between units (a is before/after b)
1657 * 0 jobs are independent,
1658 * >0 a should run after b,
1659 * <0 a should run before b,
1661 * The logic means that for a service a and a service b where b.After=a:
1663 * start a + start b → 1st step start a, 2nd step start b
1664 * start a + stop b → 1st step stop b, 2nd step start a
1665 * stop a + start b → 1st step stop a, 2nd step start b
1666 * stop a + stop b → 1st step stop b, 2nd step stop a
1668 * This has the side effect that restarts are properly
1671 int job_compare(Job
*a
, Job
*b
, UnitDependency assume_dep
) {
1672 assert(a
->type
< _JOB_TYPE_MAX_IN_TRANSACTION
);
1673 assert(b
->type
< _JOB_TYPE_MAX_IN_TRANSACTION
);
1674 assert(IN_SET(assume_dep
, UNIT_AFTER
, UNIT_BEFORE
));
1676 /* Trivial cases first */
1677 if (a
->type
== JOB_NOP
|| b
->type
== JOB_NOP
)
1680 if (a
->ignore_order
|| b
->ignore_order
)
1683 if (assume_dep
== UNIT_AFTER
)
1684 return -job_compare(b
, a
, UNIT_BEFORE
);
1686 /* Let's make it simple, JOB_STOP goes always first (in case both ua and ub stop,
1687 * then ub's stop goes first anyway).
1688 * JOB_RESTART is JOB_STOP in disguise (before it is patched to JOB_START). */
1689 if (IN_SET(b
->type
, JOB_STOP
, JOB_RESTART
))