summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2023-12-12 09:33:13 +0100
committerMike Yuan <me@yhndnzj.com>2023-12-12 10:04:30 +0100
commitd8deb18720a494a68251e14e521570c4bf6e2b96 (patch)
treec0007f7d759c859435f8db3a67c5f35cbe036cb3 /src/core
parentcore/device: add stopping job message (diff)
downloadsystemd-d8deb18720a494a68251e14e521570c4bf6e2b96.tar.xz
systemd-d8deb18720a494a68251e14e521570c4bf6e2b96.zip
core/job: emit job start message if we're only waiting for unit state
Currently, start/stop messages for device units are not used, since job_perform_on_unit() does nothing and we simply wait for unit status change. I think we still want some nice log messages explaining what the start jobs for devices are doing, so let's fix this.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/job.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/core/job.c b/src/core/job.c
index e7d1f65dbc..e78c2a70db 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -833,13 +833,12 @@ static int job_perform_on_unit(Job **j) {
Manager *m;
JobType t;
Unit *u;
+ bool wait_only;
int r;
- /* While we execute this operation the job might go away (for
- * example: because it finishes immediately or is replaced by
- * a new, conflicting job.) To make sure we don't access a
- * freed job later on we store the id here, so that we can
- * verify the job is still valid. */
+ /* While we execute this operation the job might go away (for example: because it finishes immediately
+ * or is replaced by a new, conflicting job). To make sure we don't access a freed job later on we
+ * store the id here, so that we can verify the job is still valid. */
assert(j);
assert(*j);
@@ -853,6 +852,7 @@ static int job_perform_on_unit(Job **j) {
switch (t) {
case JOB_START:
r = unit_start(u, a);
+ wait_only = r == -EBADR; /* If the unit type does not support starting, then simply wait. */
break;
case JOB_RESTART:
@@ -860,24 +860,28 @@ static int job_perform_on_unit(Job **j) {
_fallthrough_;
case JOB_STOP:
r = unit_stop(u);
+ wait_only = r == -EBADR; /* If the unit type does not support stopping, then simply wait. */
break;
case JOB_RELOAD:
r = unit_reload(u);
+ wait_only = false; /* A clear error is generated if reload is not supported. */
break;
default:
assert_not_reached();
}
- /* Log if the job still exists and the start/stop/reload function actually did something. Note that this means
- * for units for which there's no 'activating' phase (i.e. because we transition directly from 'inactive' to
- * 'active') we'll possibly skip the "Starting..." message. */
+ /* Log if the job still exists and the start/stop/reload function actually did something or we're
+ * only waiting for unit status change (common for device units). The latter ensures that job start
+ * messages for device units are correctly shown. Note that if the job disappears too quickly, e.g.
+ * for units for which there's no 'activating' phase (i.e. because we transition directly from
+ * 'inactive' to 'active'), we'll possibly skip the "Starting..." message. */
*j = manager_get_job(m, id);
- if (*j && r > 0)
+ if (*j && (r > 0 || wait_only))
job_emit_start_message(u, id, t);
- return r;
+ return wait_only ? 0 : r;
}
int job_run_and_invalidate(Job *j) {
@@ -919,13 +923,6 @@ int job_run_and_invalidate(Job *j) {
case JOB_START:
case JOB_STOP:
case JOB_RESTART:
- r = job_perform_on_unit(&j);
-
- /* If the unit type does not support starting/stopping, then simply wait. */
- if (r == -EBADR)
- r = 0;
- break;
-
case JOB_RELOAD:
r = job_perform_on_unit(&j);
break;