X Tutup
Skip to content

Commit eda0cbf

Browse files
authored
Use Finished instead of Started for Type=oneshot services (systemd#14851)
UnitStatusMessageFormats.finished_job, if present, will be called with the same arguments as job_get_done_status_message_format() to provide a format string appropriate for the context This commit replaces "Started" with "Finished" for started oneshot units, as mentioned in the referenced issue Closes systemd#2458.
1 parent 412be51 commit eda0cbf

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/core/job.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,15 @@ _pure_ static const char *job_get_done_status_message_format(Unit *u, JobType t,
797797
assert(t < _JOB_TYPE_MAX);
798798

799799
if (IN_SET(t, JOB_START, JOB_STOP, JOB_RESTART)) {
800+
const UnitStatusMessageFormats *formats = &UNIT_VTABLE(u)->status_message_formats;
801+
if (formats->finished_job) {
802+
format = formats->finished_job(u, t, result);
803+
if (format)
804+
return format;
805+
}
800806
format = t == JOB_START ?
801-
UNIT_VTABLE(u)->status_message_formats.finished_start_job[result] :
802-
UNIT_VTABLE(u)->status_message_formats.finished_stop_job[result];
807+
formats->finished_start_job[result] :
808+
formats->finished_stop_job[result];
803809
if (format)
804810
return format;
805811
}

src/core/service.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4308,6 +4308,18 @@ static int service_can_clean(Unit *u, ExecCleanMask *ret) {
43084308
return exec_context_get_clean_mask(&s->exec_context, ret);
43094309
}
43104310

4311+
static const char *service_finished_job(Unit *u, JobType t, JobResult result) {
4312+
if (t == JOB_START && result == JOB_DONE) {
4313+
Service *s = SERVICE(u);
4314+
4315+
if (s->type == SERVICE_ONESHOT)
4316+
return "Finished %s.";
4317+
}
4318+
4319+
/* Fall back to generic */
4320+
return NULL;
4321+
}
4322+
43114323
static const char* const service_restart_table[_SERVICE_RESTART_MAX] = {
43124324
[SERVICE_RESTART_NO] = "no",
43134325
[SERVICE_RESTART_ON_SUCCESS] = "on-success",
@@ -4455,13 +4467,13 @@ const UnitVTable service_vtable = {
44554467
[1] = "Stopping %s...",
44564468
},
44574469
.finished_start_job = {
4458-
[JOB_DONE] = "Started %s.",
44594470
[JOB_FAILED] = "Failed to start %s.",
44604471
[JOB_SKIPPED] = "Skipped %s.",
44614472
},
44624473
.finished_stop_job = {
44634474
[JOB_DONE] = "Stopped %s.",
44644475
[JOB_FAILED] = "Stopped (with error) %s.",
44654476
},
4477+
.finished_job = service_finished_job,
44664478
},
44674479
};

src/core/unit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ typedef struct UnitStatusMessageFormats {
382382
const char *starting_stopping[2];
383383
const char *finished_start_job[_JOB_RESULT_MAX];
384384
const char *finished_stop_job[_JOB_RESULT_MAX];
385+
/* If this entry is present, it'll be called to provide a context-dependent format string,
386+
* or NULL to fall back to finished_{start,stop}_job; if those are NULL too, fall back to generic. */
387+
const char *(*finished_job)(Unit *u, JobType t, JobResult result);
385388
} UnitStatusMessageFormats;
386389

387390
/* Flags used when writing drop-in files or transient unit files */

0 commit comments

Comments
 (0)
X Tutup