/* If the operation was fully executed by the SysV compat, let's finish early */
if (strv_isempty(names)) {
- if (arg_no_reload || install_client_side())
+ if (arg_no_reload || install_client_side() != INSTALL_CLIENT_SIDE_NO)
return 0;
r = daemon_reload(ACTION_RELOAD, /* graceful= */ false);
if (r < 0)
return r;
- if (install_client_side()) {
- UnitFileFlags flags;
- InstallChange *changes = NULL;
- size_t n_changes = 0;
-
- CLEANUP_ARRAY(changes, n_changes, install_changes_free);
-
- flags = unit_file_flags_from_args();
-
- if (streq(verb, "enable")) {
- r = unit_file_enable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
- carries_install_info = r;
- } else if (streq(verb, "disable")) {
- r = unit_file_disable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
- carries_install_info = r;
- } else if (streq(verb, "reenable")) {
- r = unit_file_reenable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
- carries_install_info = r;
- } else if (streq(verb, "link"))
- r = unit_file_link(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
- else if (streq(verb, "preset"))
- r = unit_file_preset(arg_runtime_scope, flags, arg_root, names, arg_preset_mode, &changes, &n_changes);
- else if (streq(verb, "mask"))
- r = unit_file_mask(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
- else if (streq(verb, "unmask"))
- r = unit_file_unmask(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
- else if (streq(verb, "revert"))
- r = unit_file_revert(arg_runtime_scope, arg_root, names, &changes, &n_changes);
- else
- assert_not_reached();
-
- install_changes_dump(r, verb, changes, n_changes, arg_quiet);
- if (r < 0)
- return r;
- } else {
+ if (install_client_side() == INSTALL_CLIENT_SIDE_NO) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL, *m = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
bool expect_carries_install_info = false;
if (warn_trigger_operation && !arg_quiet && !arg_no_warn)
STRV_FOREACH(unit, names)
warn_triggering_units(bus, *unit, warn_trigger_operation, warn_trigger_ignore_masked);
+ } else {
+ UnitFileFlags flags;
+ InstallChange *changes = NULL;
+ size_t n_changes = 0;
+
+ CLEANUP_ARRAY(changes, n_changes, install_changes_free);
+
+ flags = unit_file_flags_from_args();
+
+ if (streq(verb, "enable")) {
+ r = unit_file_enable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
+ carries_install_info = r;
+ } else if (streq(verb, "disable")) {
+ r = unit_file_disable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
+ carries_install_info = r;
+ } else if (streq(verb, "reenable")) {
+ r = unit_file_reenable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
+ carries_install_info = r;
+ } else if (streq(verb, "link"))
+ r = unit_file_link(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
+ else if (streq(verb, "preset"))
+ r = unit_file_preset(arg_runtime_scope, flags, arg_root, names, arg_preset_mode, &changes, &n_changes);
+ else if (streq(verb, "mask"))
+ r = unit_file_mask(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
+ else if (streq(verb, "unmask"))
+ r = unit_file_unmask(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
+ else if (streq(verb, "revert"))
+ r = unit_file_revert(arg_runtime_scope, arg_root, names, &changes, &n_changes);
+ else
+ assert_not_reached();
+
+ install_changes_dump(r, verb, changes, n_changes, arg_quiet);
+ if (r < 0)
+ return r;
}
if (carries_install_info == 0 && !ignore_carries_install_info)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--now can only be used with verb enable, disable, reenable, or mask.");
- if (install_client_side())
+ if (install_client_side() != INSTALL_CLIENT_SIDE_NO)
return log_error_errno(SYNTHETIC_ERRNO(EREMOTE),
"--now cannot be used when systemd is not running or in conjunction with --root=/--global, refusing.");
/* Go via the bus to acquire the path, unless we are explicitly told not to, or when the unit name is a template */
if (!force_client_side &&
- !install_client_side() &&
+ install_client_side() == INSTALL_CLIENT_SIDE_NO &&
!unit_name_is_valid(unit_name, UNIT_NAME_TEMPLATE)) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *load_state = NULL, *dbus_path = NULL;
return true;
}
-bool install_client_side(void) {
- /* Decides when to execute enable/disable/... operations client-side rather than server-side. */
+InstallClientSide install_client_side(void) {
+ /* Decides whether to execute enable/disable/… client-side offline operation rather than
+ * server-side. */
+
+ /* Unsupported environment variable, mostly for debugging purposes */
+ if (getenv_bool("SYSTEMCTL_INSTALL_CLIENT_SIDE") > 0)
+ return INSTALL_CLIENT_SIDE_OVERRIDE;
+
+ if (!isempty(arg_root))
+ return INSTALL_CLIENT_SIDE_ARG_ROOT;
if (running_in_chroot_or_offline())
- return true;
+ return INSTALL_CLIENT_SIDE_OFFLINE;
if (sd_booted() <= 0)
- return true;
-
- if (!isempty(arg_root))
- return true;
+ return INSTALL_CLIENT_SIDE_NOT_BOOTED;
if (arg_runtime_scope == RUNTIME_SCOPE_GLOBAL)
- return true;
-
- /* Unsupported environment variable, mostly for debugging purposes */
- if (getenv_bool("SYSTEMCTL_INSTALL_CLIENT_SIDE") > 0)
- return true;
+ return INSTALL_CLIENT_SIDE_GLOBAL_SCOPE;
- return false;
+ return INSTALL_CLIENT_SIDE_NO;
}
int output_table(Table *table) {