mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-03 01:17:45 +03:00
core: unify code that warns about jobs we fail to enqueue
This allows us to shorten our code a bit.
This commit is contained in:
parent
4bd29fe5ce
commit
53f1841669
@ -42,8 +42,6 @@ int failure_action(
|
||||
FailureAction action,
|
||||
const char *reboot_arg) {
|
||||
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(action >= 0);
|
||||
assert(action < _FAILURE_ACTION_MAX);
|
||||
@ -62,18 +60,13 @@ int failure_action(
|
||||
|
||||
switch (action) {
|
||||
|
||||
case FAILURE_ACTION_REBOOT: {
|
||||
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
case FAILURE_ACTION_REBOOT:
|
||||
log_and_status(m, "Rebooting as result of failure.");
|
||||
|
||||
update_reboot_param_file(reboot_arg);
|
||||
r = manager_add_job_by_name(m, JOB_START, SPECIAL_REBOOT_TARGET, JOB_REPLACE, &error, NULL);
|
||||
if (r < 0)
|
||||
log_error("Failed to reboot: %s.", bus_error_message(&error, r));
|
||||
(void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_REBOOT_TARGET, JOB_REPLACE, NULL);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case FAILURE_ACTION_REBOOT_FORCE:
|
||||
log_and_status(m, "Forcibly rebooting as result of failure.");
|
||||
@ -96,17 +89,10 @@ int failure_action(
|
||||
reboot(RB_AUTOBOOT);
|
||||
break;
|
||||
|
||||
case FAILURE_ACTION_POWEROFF: {
|
||||
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
case FAILURE_ACTION_POWEROFF:
|
||||
log_and_status(m, "Powering off as result of failure.");
|
||||
|
||||
r = manager_add_job_by_name(m, JOB_START, SPECIAL_POWEROFF_TARGET, JOB_REPLACE, &error, NULL);
|
||||
if (r < 0)
|
||||
log_error("Failed to poweroff: %s.", bus_error_message(&error, r));
|
||||
|
||||
(void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_POWEROFF_TARGET, JOB_REPLACE, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case FAILURE_ACTION_POWEROFF_FORCE:
|
||||
log_and_status(m, "Forcibly powering off as result of failure.");
|
||||
|
@ -1238,7 +1238,7 @@ tr_abort:
|
||||
return r;
|
||||
}
|
||||
|
||||
int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, sd_bus_error *e, Job **_ret) {
|
||||
int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, sd_bus_error *e, Job **ret) {
|
||||
Unit *unit;
|
||||
int r;
|
||||
|
||||
@ -1251,7 +1251,23 @@ int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return manager_add_job(m, type, unit, mode, e, _ret);
|
||||
return manager_add_job(m, type, unit, mode, e, ret);
|
||||
}
|
||||
|
||||
int manager_add_job_by_name_and_warn(Manager *m, JobType type, const char *name, JobMode mode, Job **ret) {
|
||||
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(type < _JOB_TYPE_MAX);
|
||||
assert(name);
|
||||
assert(mode < _JOB_MODE_MAX);
|
||||
|
||||
r = manager_add_job_by_name(m, type, name, mode, &error, ret);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to enqueue %s job for %s: %s", job_mode_to_string(mode), name, bus_error_message(&error, r));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Job *manager_get_job(Manager *m, uint32_t id) {
|
||||
|
@ -328,6 +328,7 @@ int manager_load_unit_from_dbus_path(Manager *m, const char *s, sd_bus_error *e,
|
||||
|
||||
int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, sd_bus_error *e, Job **_ret);
|
||||
int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, sd_bus_error *e, Job **_ret);
|
||||
int manager_add_job_by_name_and_warn(Manager *m, JobType type, const char *name, JobMode mode, Job **ret);
|
||||
|
||||
void manager_dump_units(Manager *s, FILE *f, const char *prefix);
|
||||
void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
|
||||
|
Loading…
Reference in New Issue
Block a user