From: Lennart Poettering Date: Tue, 9 Oct 2018 13:42:19 +0000 (+0200) Subject: core: rename ManagerExitCode → ManagerObjective X-Git-Tag: v240~585^2~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=af41e5086d5ef78b033f639c63f957995eed9370;p=thirdparty%2Fsystemd.git core: rename ManagerExitCode → ManagerObjective "ExitCode" is a bit of a misnomer in two ways: it suggests this was about the "exit code" concept that exit()/waitid() deal with, but really isn't. Moreover, it's not event just about exiting either, but more often about reloading/reexecing or rebooting. Let's hence pick a new name for this that is a bit more correct. I initially thought about naming this the "state", but that'd be a misnomer too, as the value really encodes a "goal" more than a current state. Also we already have the externally visible ManagerState. No actual changes in behaviour, just the rename. --- diff --git a/src/core/automount.c b/src/core/automount.c index 21b3887e67b..70232f358d7 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -85,7 +85,7 @@ static void unmount_autofs(Automount *a) { a->pipe_fd = safe_close(a->pipe_fd); /* If we reload/reexecute things we keep the mount point around */ - if (!IN_SET(UNIT(a)->manager->exit_code, MANAGER_RELOAD, MANAGER_REEXECUTE)) { + if (!IN_SET(UNIT(a)->manager->objective, MANAGER_RELOAD, MANAGER_REEXECUTE)) { automount_send_ready(a, a->tokens, -EHOSTDOWN); automount_send_ready(a, a->expire_tokens, -EHOSTDOWN); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 1d5237614e9..480a1430918 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1334,7 +1334,7 @@ static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error * if (r < 0) return r; - m->exit_code = MANAGER_RELOAD; + m->objective = MANAGER_RELOAD; return 1; } @@ -1363,7 +1363,7 @@ static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_erro /* We don't send a reply back here, the client should * just wait for us disconnecting. */ - m->exit_code = MANAGER_REEXECUTE; + m->objective = MANAGER_REEXECUTE; return 1; } @@ -1383,7 +1383,7 @@ static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *er * systemd-shutdown if it cannot do the exit() because it isn't a * container. */ - m->exit_code = MANAGER_EXIT; + m->objective = MANAGER_EXIT; return sd_bus_reply_method_return(message, NULL); } @@ -1402,7 +1402,7 @@ static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error * if (!MANAGER_IS_SYSTEM(m)) return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers."); - m->exit_code = MANAGER_REBOOT; + m->objective = MANAGER_REBOOT; return sd_bus_reply_method_return(message, NULL); } @@ -1421,7 +1421,7 @@ static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error if (!MANAGER_IS_SYSTEM(m)) return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers."); - m->exit_code = MANAGER_POWEROFF; + m->objective = MANAGER_POWEROFF; return sd_bus_reply_method_return(message, NULL); } @@ -1440,7 +1440,7 @@ static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *er if (!MANAGER_IS_SYSTEM(m)) return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers."); - m->exit_code = MANAGER_HALT; + m->objective = MANAGER_HALT; return sd_bus_reply_method_return(message, NULL); } @@ -1459,7 +1459,7 @@ static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *e if (!MANAGER_IS_SYSTEM(m)) return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers."); - m->exit_code = MANAGER_KEXEC; + m->objective = MANAGER_KEXEC; return sd_bus_reply_method_return(message, NULL); } @@ -1549,7 +1549,7 @@ static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_er free(m->switch_root_init); m->switch_root_init = ri; - m->exit_code = MANAGER_SWITCH_ROOT; + m->objective = MANAGER_SWITCH_ROOT; return sd_bus_reply_method_return(message, NULL); } diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c index 5420db8a87e..6f0b0a8f338 100644 --- a/src/core/emergency-action.c +++ b/src/core/emergency-action.c @@ -41,7 +41,7 @@ int emergency_action( * in user mode */ log_warning("Exiting: %s", reason); - m->exit_code = MANAGER_EXIT; + m->objective = MANAGER_EXIT; return -ECANCELED; } @@ -59,7 +59,7 @@ int emergency_action( log_and_status(m, "Forcibly rebooting", reason); (void) update_reboot_parameter_and_warn(reboot_arg); - m->exit_code = MANAGER_REBOOT; + m->objective = MANAGER_REBOOT; break; @@ -85,7 +85,7 @@ int emergency_action( case EMERGENCY_ACTION_POWEROFF_FORCE: log_and_status(m, "Forcibly powering off", reason); - m->exit_code = MANAGER_POWEROFF; + m->objective = MANAGER_POWEROFF; break; case EMERGENCY_ACTION_POWEROFF_IMMEDIATE: diff --git a/src/core/main.c b/src/core/main.c index 3b06001a8c1..2a2fe89c28d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1673,7 +1673,7 @@ static int invoke_main_loop( return log_emergency_errno(r, "Failed to run main loop: %m"); } - switch (m->exit_code) { + switch (m->objective) { case MANAGER_RELOAD: { LogTarget saved_log_target; @@ -1764,19 +1764,19 @@ static int invoke_main_loop( case MANAGER_POWEROFF: case MANAGER_HALT: case MANAGER_KEXEC: { - static const char * const table[_MANAGER_EXIT_CODE_MAX] = { - [MANAGER_EXIT] = "exit", - [MANAGER_REBOOT] = "reboot", + static const char * const table[_MANAGER_OBJECTIVE_MAX] = { + [MANAGER_EXIT] = "exit", + [MANAGER_REBOOT] = "reboot", [MANAGER_POWEROFF] = "poweroff", - [MANAGER_HALT] = "halt", - [MANAGER_KEXEC] = "kexec" + [MANAGER_HALT] = "halt", + [MANAGER_KEXEC] = "kexec", }; log_notice("Shutting down."); *ret_reexecute = false; *ret_retval = m->return_value; - assert_se(*ret_shutdown_verb = table[m->exit_code]); + assert_se(*ret_shutdown_verb = table[m->objective]); *ret_fds = NULL; *ret_switch_root_dir = *ret_switch_root_init = NULL; @@ -1784,7 +1784,7 @@ static int invoke_main_loop( } default: - assert_not_reached("Unknown exit code."); + assert_not_reached("Unknown or unexpected manager objective."); } } } diff --git a/src/core/manager.c b/src/core/manager.c index c361a1ec076..76a0190cb8d 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -723,7 +723,7 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { return -ENOMEM; m->unit_file_scope = scope; - m->exit_code = _MANAGER_EXIT_CODE_INVALID; + m->objective = _MANAGER_OBJECTIVE_INVALID; m->default_timer_accuracy_usec = USEC_PER_MINUTE; m->default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT; m->default_tasks_accounting = true; @@ -1288,7 +1288,7 @@ Manager* manager_free(Manager *m) { unit_vtable[c]->shutdown(m); /* If we reexecute ourselves, we keep the root cgroup around */ - manager_shutdown_cgroup(m, m->exit_code != MANAGER_REEXECUTE); + manager_shutdown_cgroup(m, m->objective != MANAGER_REEXECUTE); lookup_paths_flush_generator(&m->lookup_paths); @@ -2545,7 +2545,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t /* This is for compatibility with the original sysvinit */ r = verify_run_space_and_log("Refusing to reexecute"); if (r >= 0) - m->exit_code = MANAGER_REEXECUTE; + m->objective = MANAGER_REEXECUTE; break; } @@ -2603,7 +2603,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t case SIGHUP: r = verify_run_space_and_log("Refusing to reload"); if (r >= 0) - m->exit_code = MANAGER_RELOAD; + m->objective = MANAGER_RELOAD; break; default: { @@ -2623,7 +2623,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t }; /* Starting SIGRTMIN+13, so that target halt and system halt are 10 apart */ - static const ManagerExitCode code_table[] = { + static const ManagerObjective objective_table[] = { [0] = MANAGER_HALT, [1] = MANAGER_POWEROFF, [2] = MANAGER_REBOOT, @@ -2639,8 +2639,8 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t } if ((int) sfsi.ssi_signo >= SIGRTMIN+13 && - (int) sfsi.ssi_signo < SIGRTMIN+13+(int) ELEMENTSOF(code_table)) { - m->exit_code = code_table[sfsi.ssi_signo - SIGRTMIN - 13]; + (int) sfsi.ssi_signo < SIGRTMIN+13+(int) ELEMENTSOF(objective_table)) { + m->objective = objective_table[sfsi.ssi_signo - SIGRTMIN - 13]; break; } @@ -2664,7 +2664,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t case 24: if (MANAGER_IS_USER(m)) { - m->exit_code = MANAGER_EXIT; + m->objective = MANAGER_EXIT; return 0; } @@ -2793,7 +2793,7 @@ int manager_loop(Manager *m) { RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000); assert(m); - m->exit_code = MANAGER_OK; + m->objective = MANAGER_OK; /* Release the path cache */ m->unit_path_cache = set_free_free(m->unit_path_cache); @@ -2805,7 +2805,7 @@ int manager_loop(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to enable SIGCHLD event source: %m"); - while (m->exit_code == MANAGER_OK) { + while (m->objective == MANAGER_OK) { usec_t wait_usec; if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && MANAGER_IS_SYSTEM(m)) @@ -2851,7 +2851,7 @@ int manager_loop(Manager *m) { return log_error_errno(r, "Failed to run event loop: %m"); } - return m->exit_code; + return m->objective; } int manager_load_unit_from_dbus_path(Manager *m, const char *s, sd_bus_error *e, Unit **_u) { diff --git a/src/core/manager.h b/src/core/manager.h index 81ff52aa4ba..a26ffda3a57 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -36,7 +36,7 @@ typedef enum ManagerState { _MANAGER_STATE_INVALID = -1 } ManagerState; -typedef enum ManagerExitCode { +typedef enum ManagerObjective { MANAGER_OK, MANAGER_EXIT, MANAGER_RELOAD, @@ -46,9 +46,9 @@ typedef enum ManagerExitCode { MANAGER_HALT, MANAGER_KEXEC, MANAGER_SWITCH_ROOT, - _MANAGER_EXIT_CODE_MAX, - _MANAGER_EXIT_CODE_INVALID = -1 -} ManagerExitCode; + _MANAGER_OBJECTIVE_MAX, + _MANAGER_OBJECTIVE_INVALID = -1 +} ManagerObjective; typedef enum StatusType { STATUS_TYPE_EPHEMERAL, @@ -282,9 +282,9 @@ struct Manager { usec_t etc_localtime_mtime; bool etc_localtime_accessible:1; - /* Flags */ - ManagerExitCode exit_code:5; + ManagerObjective objective:5; + /* Flags */ bool dispatching_load_queue:1; bool dispatching_dbus_queue:1; @@ -407,8 +407,8 @@ struct Manager { #define MANAGER_IS_FINISHED(m) (dual_timestamp_is_set((m)->timestamps + MANAGER_TIMESTAMP_FINISH)) -/* The exit code is set to OK as soon as we enter the main loop, and set otherwise as soon as we are done with it */ -#define MANAGER_IS_RUNNING(m) ((m)->exit_code == MANAGER_OK) +/* The objective is set to OK as soon as we enter the main loop, and set otherwise as soon as we are done with it */ +#define MANAGER_IS_RUNNING(m) ((m)->objective == MANAGER_OK) int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **m); Manager* manager_free(Manager *m);