| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-bus.h" |
| 4 |
|
| 5 |
#include "bus-error.h" |
| 6 |
#include "bus-locator.h" |
| 7 |
#include "bus-unit-util.h" |
| 8 |
#include "install.h" |
| 9 |
#include "log.h" |
| 10 |
#include "systemctl.h" |
| 11 |
#include "systemctl-daemon-reload.h" |
| 12 |
#include "systemctl-preset-all.h" |
| 13 |
#include "systemctl-util.h" |
| 14 |
#include "verbs.h" |
| 15 |
|
| 16 |
int verb_preset_all(int argc, char *argv[], uintptr_t _data, void *userdata) { |
| 17 |
int r; |
| 18 |
|
| 19 |
if (should_bypass("SYSTEMD_PRESET")) |
| 20 |
return 0; |
| 21 |
|
| 22 |
if (install_client_side() != INSTALL_CLIENT_SIDE_NO) { |
| 23 |
InstallChange *changes = NULL; |
| 24 |
size_t n_changes = 0; |
| 25 |
|
| 26 |
CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
| 27 |
|
| 28 |
r = unit_file_preset_all(arg_runtime_scope, unit_file_flags_from_args(), arg_root, arg_preset_mode, &changes, &n_changes); |
| 29 |
/* We do not propagate failure for individual units here. */ |
| 30 |
(void) install_changes_dump(r, "preset all", changes, n_changes, arg_quiet); |
| 31 |
if (r < 0) |
| 32 |
return r; |
| 33 |
} else { |
| 34 |
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
| 35 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 36 |
sd_bus *bus; |
| 37 |
|
| 38 |
r = acquire_bus(BUS_MANAGER, &bus); |
| 39 |
if (r < 0) |
| 40 |
return r; |
| 41 |
|
| 42 |
polkit_agent_open_maybe(); |
| 43 |
|
| 44 |
r = bus_call_method( |
| 45 |
bus, |
| 46 |
bus_systemd_mgr, |
| 47 |
"PresetAllUnitFiles", |
| 48 |
&error, |
| 49 |
&reply, |
| 50 |
"sbb", |
| 51 |
unit_file_preset_mode_to_string(arg_preset_mode), |
| 52 |
arg_runtime, |
| 53 |
arg_force); |
| 54 |
if (r < 0) |
| 55 |
return log_error_errno(r, "Failed to preset all units: %s", bus_error_message(&error, r)); |
| 56 |
|
| 57 |
r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet); |
| 58 |
if (r < 0) |
| 59 |
return r; |
| 60 |
|
| 61 |
if (!arg_no_reload) { |
| 62 |
r = daemon_reload(ACTION_RELOAD, /* graceful= */ false); |
| 63 |
if (r < 0) |
| 64 |
return r; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return 0; |
| 69 |
} |