From 0f87041f9404564fac77ab3b6afcef0cab5f3936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 24 Aug 2022 17:23:40 +0200 Subject: [PATCH 1/8] shared/install: rename 'files' param to 'names' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … or 'name_or_path' or 'names_or_paths' as appropriate. Those functions are generally called with unit names as arguments. --- src/shared/install.c | 97 +++++++++++++++++++++++--------------------- src/shared/install.h | 16 ++++---- 2 files changed, 58 insertions(+), 55 deletions(-) diff --git a/src/shared/install.c b/src/shared/install.c index 1a0a536080..5da26eeb21 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1728,7 +1728,7 @@ static int install_info_add_auto( static int install_info_discover( InstallContext *ctx, const LookupPaths *lp, - const char *name, + const char *name_or_path, SearchFlags flags, UnitFileInstallInfo **ret, UnitFileChange **changes, @@ -1739,21 +1739,21 @@ static int install_info_discover( assert(ctx); assert(lp); - assert(name); + assert(name_or_path); - r = install_info_add_auto(ctx, lp, name, &info); + r = install_info_add_auto(ctx, lp, name_or_path, &info); if (r >= 0) r = install_info_traverse(ctx, lp, info, flags, ret); if (r < 0) - unit_file_changes_add(changes, n_changes, r, name, NULL); + unit_file_changes_add(changes, n_changes, r, name_or_path, NULL); return r; } static int install_info_discover_and_check( InstallContext *ctx, const LookupPaths *lp, - const char *name, + const char *name_or_path, SearchFlags flags, UnitFileInstallInfo **ret, UnitFileChange **changes, @@ -1761,7 +1761,7 @@ static int install_info_discover_and_check( int r; - r = install_info_discover(ctx, lp, name, flags, ret, changes, n_changes); + r = install_info_discover(ctx, lp, name_or_path, flags, ret, changes, n_changes); if (r < 0) return r; @@ -2226,7 +2226,7 @@ int unit_file_mask( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names, UnitFileChange **changes, size_t *n_changes) { @@ -2245,17 +2245,17 @@ int unit_file_mask( if (!config_path) return -ENXIO; - STRV_FOREACH(i, files) { + STRV_FOREACH(name, names) { _cleanup_free_ char *path = NULL; int q; - if (!unit_name_is_valid(*i, UNIT_NAME_ANY)) { + if (!unit_name_is_valid(*name, UNIT_NAME_ANY)) { if (r == 0) r = -EINVAL; continue; } - path = path_make_absolute(*i, config_path); + path = path_make_absolute(*name, config_path); if (!path) return -ENOMEM; @@ -2271,7 +2271,7 @@ int unit_file_unmask( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names, UnitFileChange **changes, size_t *n_changes) { @@ -2295,13 +2295,13 @@ int unit_file_unmask( bool dry_run = flags & UNIT_FILE_DRY_RUN; - STRV_FOREACH(i, files) { + STRV_FOREACH(name, names) { _cleanup_free_ char *path = NULL; - if (!unit_name_is_valid(*i, UNIT_NAME_ANY)) + if (!unit_name_is_valid(*name, UNIT_NAME_ANY)) return -EINVAL; - path = path_make_absolute(*i, config_path); + path = path_make_absolute(*name, config_path); if (!path) return -ENOMEM; @@ -2316,7 +2316,7 @@ int unit_file_unmask( if (!GREEDY_REALLOC0(todo, n_todo + 2)) return -ENOMEM; - todo[n_todo] = strdup(*i); + todo[n_todo] = strdup(*name); if (!todo[n_todo]) return -ENOMEM; @@ -2384,19 +2384,19 @@ int unit_file_link( if (!config_path) return -ENXIO; - STRV_FOREACH(i, files) { + STRV_FOREACH(file, files) { _cleanup_free_ char *full = NULL; struct stat st; char *fn; - if (!path_is_absolute(*i)) + if (!path_is_absolute(*file)) return -EINVAL; - fn = basename(*i); + fn = basename(*file); if (!unit_name_is_valid(fn, UNIT_NAME_ANY)) return -EINVAL; - full = path_join(lp.root_dir, *i); + full = path_join(lp.root_dir, *file); if (!full) return -ENOMEM; @@ -2406,7 +2406,7 @@ int unit_file_link( if (r < 0) return r; - q = in_search_path(&lp, *i); + q = in_search_path(&lp, *file); if (q < 0) return q; if (q > 0) @@ -2415,7 +2415,7 @@ int unit_file_link( if (!GREEDY_REALLOC0(todo, n_todo + 2)) return -ENOMEM; - todo[n_todo] = strdup(*i); + todo[n_todo] = strdup(*file); if (!todo[n_todo]) return -ENOMEM; @@ -2462,7 +2462,7 @@ static int path_shall_revert(const LookupPaths *lp, const char *path) { int unit_file_revert( LookupScope scope, const char *root_dir, - char **files, + char **names, UnitFileChange **changes, size_t *n_changes) { @@ -2474,11 +2474,12 @@ int unit_file_revert( /* Puts a unit file back into vendor state. This means: * - * a) we remove all drop-in snippets added by the user ("config"), add to transient units ("transient"), and - * added via "systemctl set-property" ("control"), but not if the drop-in is generated ("generated"). + * a) we remove all drop-in snippets added by the user ("config"), add to transient units + * ("transient"), and added via "systemctl set-property" ("control"), but not if the drop-in is + * generated ("generated"). * - * c) if there's a vendor unit file (i.e. one in /usr) we remove any configured overriding unit files (i.e. in - * "config", but not in "transient" or "control" or even "generated"). + * c) if there's a vendor unit file (i.e. one in /usr) we remove any configured overriding unit files + * (i.e. in "config", but not in "transient" or "control" or even "generated"). * * We remove all that in both the runtime and the persistent directories, if that applies. */ @@ -2487,17 +2488,17 @@ int unit_file_revert( if (r < 0) return r; - STRV_FOREACH(i, files) { + STRV_FOREACH(name, names) { bool has_vendor = false; - if (!unit_name_is_valid(*i, UNIT_NAME_ANY)) + if (!unit_name_is_valid(*name, UNIT_NAME_ANY)) return -EINVAL; STRV_FOREACH(p, lp.search_path) { _cleanup_free_ char *path = NULL, *dropin = NULL; struct stat st; - path = path_make_absolute(*i, *p); + path = path_make_absolute(*name, *p); if (!path) return -ENOMEM; @@ -2544,7 +2545,7 @@ int unit_file_revert( _cleanup_free_ char *path = NULL; struct stat st; - path = path_make_absolute(*i, *p); + path = path_make_absolute(*name, *p); if (!path) return -ENOMEM; @@ -2614,7 +2615,7 @@ int unit_file_add_dependency( LookupScope scope, UnitFileFlags file_flags, const char *root_dir, - char **files, + char **names, const char *target, UnitDependency dep, UnitFileChange **changes, @@ -2651,10 +2652,11 @@ int unit_file_add_dependency( assert(target_info->type == UNIT_FILE_TYPE_REGULAR); - STRV_FOREACH(f, files) { + STRV_FOREACH(name, names) { char ***l; - r = install_info_discover_and_check(&ctx, &lp, *f, SEARCH_FOLLOW_CONFIG_SYMLINKS, + r = install_info_discover_and_check(&ctx, &lp, *name, + SEARCH_FOLLOW_CONFIG_SYMLINKS, &info, changes, n_changes); if (r < 0) return r; @@ -2685,7 +2687,7 @@ static int do_unit_file_enable( LookupScope scope, UnitFileFlags flags, const char *config_path, - char **files, + char **names_or_paths, UnitFileChange **changes, size_t *n_changes) { @@ -2693,8 +2695,9 @@ static int do_unit_file_enable( UnitFileInstallInfo *info; int r; - STRV_FOREACH(f, files) { - r = install_info_discover_and_check(&ctx, lp, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, + STRV_FOREACH(name, names_or_paths) { + r = install_info_discover_and_check(&ctx, lp, *name, + SEARCH_LOAD | SEARCH_FOLLOW_CONFIG_SYMLINKS, &info, changes, n_changes); if (r < 0) return r; @@ -2704,7 +2707,7 @@ static int do_unit_file_enable( /* This will return the number of symlink rules that were supposed to be created, not the ones actually created. This - is useful to determine whether the passed files had any + is useful to determine whether the passed units had any installation data at all. */ return install_context_apply(&ctx, lp, flags, config_path, @@ -2715,7 +2718,7 @@ int unit_file_enable( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names_or_paths, UnitFileChange **changes, size_t *n_changes) { @@ -2733,7 +2736,7 @@ int unit_file_enable( if (!config_path) return -ENXIO; - return do_unit_file_enable(&lp, scope, flags, config_path, files, changes, n_changes); + return do_unit_file_enable(&lp, scope, flags, config_path, names_or_paths, changes, n_changes); } static int do_unit_file_disable( @@ -2741,7 +2744,7 @@ static int do_unit_file_disable( LookupScope scope, UnitFileFlags flags, const char *config_path, - char **files, + char **names, UnitFileChange **changes, size_t *n_changes) { @@ -2749,11 +2752,11 @@ static int do_unit_file_disable( _cleanup_set_free_free_ Set *remove_symlinks_to = NULL; int r; - STRV_FOREACH(i, files) { - if (!unit_name_is_valid(*i, UNIT_NAME_ANY)) + STRV_FOREACH(name, names) { + if (!unit_name_is_valid(*name, UNIT_NAME_ANY)) return -EINVAL; - r = install_info_add(&ctx, *i, NULL, lp->root_dir, /* auxiliary= */ false, NULL); + r = install_info_add(&ctx, *name, NULL, lp->root_dir, /* auxiliary= */ false, NULL); if (r < 0) return r; } @@ -3443,7 +3446,7 @@ int unit_file_preset( LookupScope scope, UnitFileFlags file_flags, const char *root_dir, - char **files, + char **names, UnitFilePresetMode mode, UnitFileChange **changes, size_t *n_changes) { @@ -3470,13 +3473,13 @@ int unit_file_preset( if (r < 0) return r; - STRV_FOREACH(i, files) { - r = preset_prepare_one(scope, &plus, &minus, &lp, *i, &presets, changes, n_changes); + STRV_FOREACH(name, names) { + r = preset_prepare_one(scope, &plus, &minus, &lp, *name, &presets, changes, n_changes); if (r < 0) return r; } - return execute_preset(file_flags, &plus, &minus, &lp, config_path, files, mode, changes, n_changes); + return execute_preset(file_flags, &plus, &minus, &lp, config_path, names, mode, changes, n_changes); } int unit_file_preset_all( diff --git a/src/shared/install.h b/src/shared/install.h index 2ba7e8aea0..bc107e03ae 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -99,14 +99,14 @@ int unit_file_enable( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names_or_paths, UnitFileChange **changes, size_t *n_changes); int unit_file_disable( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names, UnitFileChange **changes, size_t *n_changes); int unit_file_reenable( @@ -120,7 +120,7 @@ int unit_file_preset( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names, UnitFilePresetMode mode, UnitFileChange **changes, size_t *n_changes); @@ -135,14 +135,14 @@ int unit_file_mask( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names, UnitFileChange **changes, size_t *n_changes); int unit_file_unmask( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names, UnitFileChange **changes, size_t *n_changes); int unit_file_link( @@ -155,14 +155,14 @@ int unit_file_link( int unit_file_revert( LookupScope scope, const char *root_dir, - char **files, + char **names, UnitFileChange **changes, size_t *n_changes); int unit_file_set_default( LookupScope scope, UnitFileFlags flags, const char *root_dir, - const char *file, + const char *name, UnitFileChange **changes, size_t *n_changes); int unit_file_get_default( @@ -173,7 +173,7 @@ int unit_file_add_dependency( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names, const char *target, UnitDependency dep, UnitFileChange **changes, From cd44ec5a92e594bc286a731ff9be75f8554c2c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 26 Aug 2022 09:30:01 +0200 Subject: [PATCH 2/8] shared/install: rename UnitFileChange to InstallChange It's shorter and more generic. The struct can contain info about changes to unit files, but also symlinks and errors. --- src/core/dbus-manager.c | 52 ++++----- src/machine/machinectl.c | 4 +- src/portable/portablectl.c | 4 +- src/shared/bus-unit-util.c | 8 +- src/shared/bus-unit-util.h | 2 +- src/shared/install.c | 142 +++++++++++------------ src/shared/install.h | 38 +++--- src/systemctl/systemctl-add-dependency.c | 6 +- src/systemctl/systemctl-enable.c | 6 +- src/systemctl/systemctl-is-enabled.c | 2 +- src/systemctl/systemctl-preset-all.c | 6 +- src/systemctl/systemctl-set-default.c | 6 +- src/test/test-install-root.c | 114 +++++++++--------- src/test/test-install.c | 34 +++--- test/test-exec-deserialization.py | 29 +++-- 15 files changed, 226 insertions(+), 227 deletions(-) diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 73f739b12d..73810833ca 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -2122,12 +2122,12 @@ static int send_unit_files_changed(sd_bus *bus, void *userdata) { * if possible, and fall back to generating an error from error code c. * The error message only describes the first error. * - * Coordinate with unit_file_dump_changes() in install.c. + * Coordinate with install_changes_dump() in install.c. */ static int install_error( sd_bus_error *error, int c, - UnitFileChange *changes, + InstallChange *changes, size_t n_changes) { int r; @@ -2186,15 +2186,15 @@ static int install_error( r = c < 0 ? c : -EINVAL; found: - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return r; } -static int reply_unit_file_changes_and_free( +static int reply_install_changes_and_free( Manager *m, sd_bus_message *message, int carries_install_info, - UnitFileChange *changes, + InstallChange *changes, size_t n_changes, sd_bus_error *error) { @@ -2202,7 +2202,7 @@ static int reply_unit_file_changes_and_free( bool bad = false, good = false; int r; - if (unit_file_changes_have_modification(changes, n_changes)) { + if (install_changes_have_modification(changes, n_changes)) { r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL); if (r < 0) log_debug_errno(r, "Failed to send UnitFilesChanged signal: %m"); @@ -2249,23 +2249,23 @@ static int reply_unit_file_changes_and_free( if (r < 0) goto fail; - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return sd_bus_send(NULL, reply, NULL); fail: - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return r; } static int method_enable_unit_files_generic( sd_bus_message *message, Manager *m, - int (*call)(LookupScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), + int (*call)(LookupScope scope, UnitFileFlags flags, const char *root_dir, char *files[], InstallChange **changes, size_t *n_changes), bool carries_install_info, sd_bus_error *error) { _cleanup_strv_free_ char **l = NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; UnitFileFlags flags; int r; @@ -2305,7 +2305,7 @@ static int method_enable_unit_files_generic( if (r < 0) return install_error(error, r, changes, n_changes); - return reply_unit_file_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); + return reply_install_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, error); } static int method_enable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { @@ -2324,7 +2324,7 @@ static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bu return method_enable_unit_files_generic(message, userdata, unit_file_link, false, error); } -static int unit_file_preset_without_mode(LookupScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, size_t *n_changes) { +static int unit_file_preset_without_mode(LookupScope scope, UnitFileFlags flags, const char *root_dir, char **files, InstallChange **changes, size_t *n_changes) { return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes); } @@ -2339,7 +2339,7 @@ static int method_mask_unit_files(sd_bus_message *message, void *userdata, sd_bu static int method_preset_unit_files_with_mode(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_strv_free_ char **l = NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; Manager *m = ASSERT_PTR(userdata); UnitFilePresetMode preset_mode; @@ -2377,17 +2377,17 @@ static int method_preset_unit_files_with_mode(sd_bus_message *message, void *use if (r < 0) return install_error(error, r, changes, n_changes); - return reply_unit_file_changes_and_free(m, message, r, changes, n_changes, error); + return reply_install_changes_and_free(m, message, r, changes, n_changes, error); } static int method_disable_unit_files_generic( sd_bus_message *message, Manager *m, - int (*call)(LookupScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), + int (*call)(LookupScope scope, UnitFileFlags flags, const char *root_dir, char *files[], InstallChange **changes, size_t *n_changes), sd_bus_error *error) { _cleanup_strv_free_ char **l = NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; UnitFileFlags flags; size_t n_changes = 0; int r; @@ -2428,7 +2428,7 @@ static int method_disable_unit_files_generic( if (r < 0) return install_error(error, r, changes, n_changes); - return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); + return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); } static int method_disable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *error) { @@ -2445,7 +2445,7 @@ static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_ static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_strv_free_ char **l = NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; Manager *m = ASSERT_PTR(userdata); int r; @@ -2466,11 +2466,11 @@ static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_ if (r < 0) return install_error(error, r, changes, n_changes); - return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); + return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); } static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; Manager *m = ASSERT_PTR(userdata); const char *name; @@ -2496,11 +2496,11 @@ static int method_set_default_target(sd_bus_message *message, void *userdata, sd if (r < 0) return install_error(error, r, changes, n_changes); - return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); + return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); } static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; Manager *m = ASSERT_PTR(userdata); UnitFilePresetMode preset_mode; @@ -2538,13 +2538,13 @@ static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, if (r < 0) return install_error(error, r, changes, n_changes); - return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); + return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); } static int method_add_dependency_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_strv_free_ char **l = NULL; Manager *m = ASSERT_PTR(userdata); - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; int runtime, force, r; char *target, *type; @@ -2577,12 +2577,12 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd if (r < 0) return install_error(error, r, changes, n_changes); - return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes, error); + return reply_install_changes_and_free(m, message, -1, changes, n_changes, error); } static int method_get_unit_file_links(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0, i; UnitFileFlags flags; const char *name; diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index db29e3092b..eac26bc4d3 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1599,7 +1599,7 @@ static int start_machine(int argc, char *argv[], void *userdata) { static int enable_machine(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; const char *method = NULL; sd_bus *bus = ASSERT_PTR(userdata); @@ -1671,7 +1671,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) { r = 0; finish: - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return r; } diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c index 6ee9ee8f43..341e70621f 100644 --- a/src/portable/portablectl.c +++ b/src/portable/portablectl.c @@ -540,7 +540,7 @@ static int maybe_enable_disable(sd_bus *bus, const char *path, bool enable) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_strv_free_ char **names = NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; const uint64_t flags = UNIT_FILE_PORTABLE | (arg_runtime ? UNIT_FILE_RUNTIME : 0); size_t n_changes = 0; int r; @@ -582,7 +582,7 @@ static int maybe_enable_disable(sd_bus *bus, const char *path, bool enable) { } (void) bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet, &changes, &n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return 0; } diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 2bf0d855b1..9b46b732ff 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -2668,11 +2668,11 @@ int bus_append_unit_property_assignment_many(sd_bus_message *m, UnitType t, char return 0; } -int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, size_t *n_changes) { +int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, InstallChange **changes, size_t *n_changes) { const char *type, *path, *source; int r; - /* changes is dereferenced when calling unit_file_dump_changes() later, + /* changes is dereferenced when calling install_changes_dump() later, * so we have to make sure this is not NULL. */ assert(changes); assert(n_changes); @@ -2691,7 +2691,7 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un continue; } - r = unit_file_changes_add(changes, n_changes, ch, path, source); + r = install_changes_add(changes, n_changes, ch, path, source); if (r < 0) return r; } @@ -2702,7 +2702,7 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un if (r < 0) return bus_log_parse_error(r); - unit_file_dump_changes(0, NULL, *changes, *n_changes, quiet); + install_changes_dump(0, NULL, *changes, *n_changes, quiet); return 0; } diff --git a/src/shared/bus-unit-util.h b/src/shared/bus-unit-util.h index 999caf65cd..789a142e1d 100644 --- a/src/shared/bus-unit-util.h +++ b/src/shared/bus-unit-util.h @@ -25,7 +25,7 @@ int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u); int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const char *assignment); int bus_append_unit_property_assignment_many(sd_bus_message *m, UnitType t, char **l); -int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, size_t *n_changes); +int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, InstallChange **changes, size_t *n_changes); int unit_load_state(sd_bus *bus, const char *name, char **load_state); diff --git a/src/shared/install.c b/src/shared/install.c index 5da26eeb21..3d74a9ba79 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -265,15 +265,15 @@ static const char* config_path_from_flags(const LookupPaths *lp, UnitFileFlags f return FLAGS_SET(flags, UNIT_FILE_RUNTIME) ? lp->runtime_config : lp->persistent_config; } -int unit_file_changes_add( - UnitFileChange **changes, +int install_changes_add( + InstallChange **changes, size_t *n_changes, int type_or_errno, /* UNIT_FILE_SYMLINK, _UNLINK, _IS_MASKED, _IS_DANGLING if positive or errno if negative */ const char *path, const char *source) { _cleanup_free_ char *p = NULL, *s = NULL; - UnitFileChange *c; + InstallChange *c; assert(!changes == !n_changes); @@ -285,7 +285,7 @@ int unit_file_changes_add( if (!changes) return 0; - c = reallocarray(*changes, *n_changes + 1, sizeof(UnitFileChange)); + c = reallocarray(*changes, *n_changes + 1, sizeof(InstallChange)); if (!c) return -ENOMEM; *changes = c; @@ -306,7 +306,7 @@ int unit_file_changes_add( path_simplify(s); } - c[(*n_changes)++] = (UnitFileChange) { + c[(*n_changes)++] = (InstallChange) { .type_or_errno = type_or_errno, .path = TAKE_PTR(p), .source = TAKE_PTR(s), @@ -315,7 +315,7 @@ int unit_file_changes_add( return 0; } -void unit_file_changes_free(UnitFileChange *changes, size_t n_changes) { +void install_changes_free(InstallChange *changes, size_t n_changes) { assert(changes || n_changes == 0); for (size_t i = 0; i < n_changes; i++) { @@ -326,7 +326,7 @@ void unit_file_changes_free(UnitFileChange *changes, size_t n_changes) { free(changes); } -void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet) { +void install_changes_dump(int r, const char *verb, const InstallChange *changes, size_t n_changes, bool quiet) { int err = 0; assert(changes || n_changes == 0); @@ -484,7 +484,7 @@ static int create_symlink( const char *old_path, const char *new_path, bool force, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_free_ char *dest = NULL; @@ -508,12 +508,12 @@ static int create_symlink( (void) mkdir_parents_label(new_path, 0755); if (symlink(old_path, new_path) >= 0) { - unit_file_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path); + install_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path); return 1; } if (errno != EEXIST) { - unit_file_changes_add(changes, n_changes, -errno, new_path, NULL); + install_changes_add(changes, n_changes, -errno, new_path, NULL); return -errno; } @@ -523,7 +523,7 @@ static int create_symlink( if (r == -EINVAL) r = -EEXIST; - unit_file_changes_add(changes, n_changes, r, new_path, NULL); + install_changes_add(changes, n_changes, r, new_path, NULL); return r; } @@ -534,18 +534,18 @@ static int create_symlink( } if (!force) { - unit_file_changes_add(changes, n_changes, -EEXIST, new_path, dest); + install_changes_add(changes, n_changes, -EEXIST, new_path, dest); return -EEXIST; } r = symlink_atomic(old_path, new_path); if (r < 0) { - unit_file_changes_add(changes, n_changes, r, new_path, NULL); + install_changes_add(changes, n_changes, r, new_path, NULL); return r; } - unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, new_path, NULL); - unit_file_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path); + install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, new_path, NULL); + install_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path); return 1; } @@ -586,7 +586,7 @@ static int remove_marked_symlinks_fd( const LookupPaths *lp, bool dry_run, bool *restart, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_closedir_ DIR *d = NULL; @@ -671,7 +671,7 @@ static int remove_marked_symlinks_fd( continue; if (q < 0) { log_debug_errno(q, "Failed to resolve symlink \"%s\": %m", p); - unit_file_changes_add(changes, n_changes, q, p, NULL); + install_changes_add(changes, n_changes, q, p, NULL); if (r == 0) r = q; @@ -691,14 +691,14 @@ static int remove_marked_symlinks_fd( if (unlinkat(fd, de->d_name, 0) < 0 && errno != ENOENT) { if (r == 0) r = -errno; - unit_file_changes_add(changes, n_changes, -errno, p, NULL); + install_changes_add(changes, n_changes, -errno, p, NULL); continue; } (void) rmdir_parents(p, config_path); } - unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, p, NULL); + install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, p, NULL); /* Now, remember the full path (but with the root prefix removed) of * the symlink we just removed, and remove any symlinks to it, too. */ @@ -719,7 +719,7 @@ static int remove_marked_symlinks( const char *config_path, const LookupPaths *lp, bool dry_run, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_close_ int fd = -1; @@ -1076,7 +1076,7 @@ static UnitFileInstallInfo *install_info_find(InstallContext *ctx, const char *n static int install_info_may_process( const UnitFileInstallInfo *i, const LookupPaths *lp, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { assert(i); assert(lp); @@ -1085,12 +1085,12 @@ static int install_info_may_process( * transient or generated and thus not subject to enable/disable operations. */ if (i->type == UNIT_FILE_TYPE_MASKED) { - unit_file_changes_add(changes, n_changes, -ERFKILL, i->path, NULL); + install_changes_add(changes, n_changes, -ERFKILL, i->path, NULL); return -ERFKILL; } if (path_is_generator(lp, i->path) || path_is_transient(lp, i->path)) { - unit_file_changes_add(changes, n_changes, -EADDRNOTAVAIL, i->path, NULL); + install_changes_add(changes, n_changes, -EADDRNOTAVAIL, i->path, NULL); return -EADDRNOTAVAIL; } @@ -1731,7 +1731,7 @@ static int install_info_discover( const char *name_or_path, SearchFlags flags, UnitFileInstallInfo **ret, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { UnitFileInstallInfo *info; @@ -1746,7 +1746,7 @@ static int install_info_discover( r = install_info_traverse(ctx, lp, info, flags, ret); if (r < 0) - unit_file_changes_add(changes, n_changes, r, name_or_path, NULL); + install_changes_add(changes, n_changes, r, name_or_path, NULL); return r; } @@ -1756,7 +1756,7 @@ static int install_info_discover_and_check( const char *name_or_path, SearchFlags flags, UnitFileInstallInfo **ret, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { int r; @@ -1772,7 +1772,7 @@ int unit_file_verify_alias( const UnitFileInstallInfo *info, const char *dst, char **ret_dst, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_free_ char *dst_updated = NULL; @@ -1807,7 +1807,7 @@ int unit_file_verify_alias( if (!p) p = endswith(dir, ".requires"); if (!p) { - unit_file_changes_add(changes, n_changes, -EXDEV, dst, NULL); + install_changes_add(changes, n_changes, -EXDEV, dst, NULL); return log_debug_errno(SYNTHETIC_ERRNO(EXDEV), "Invalid path \"%s\" in alias.", dir); } @@ -1815,7 +1815,7 @@ int unit_file_verify_alias( UnitNameFlags type = unit_name_classify(dir); if (type < 0) { - unit_file_changes_add(changes, n_changes, -EXDEV, dst, NULL); + install_changes_add(changes, n_changes, -EXDEV, dst, NULL); return log_debug_errno(SYNTHETIC_ERRNO(EXDEV), "Invalid unit name component \"%s\" in alias.", dir); } @@ -1827,7 +1827,7 @@ int unit_file_verify_alias( if (r < 0) return log_error_errno(r, "Failed to verify alias validity: %m"); if (r == 0) { - unit_file_changes_add(changes, n_changes, -EXDEV, dst, info->name); + install_changes_add(changes, n_changes, -EXDEV, dst, info->name); return log_debug_errno(SYNTHETIC_ERRNO(EXDEV), "Invalid unit \"%s\" symlink \"%s\".", info->name, dst); @@ -1841,7 +1841,7 @@ int unit_file_verify_alias( UnitNameFlags type = unit_name_to_instance(info->name, &inst); if (type < 0) { - unit_file_changes_add(changes, n_changes, -EUCLEAN, info->name, NULL); + install_changes_add(changes, n_changes, -EUCLEAN, info->name, NULL); return log_debug_errno(type, "Failed to extract instance name from \"%s\": %m", info->name); } @@ -1857,7 +1857,7 @@ int unit_file_verify_alias( if (r == -ELOOP) /* -ELOOP means self-alias, which we (quietly) ignore */ return r; if (r < 0) { - unit_file_changes_add(changes, n_changes, + install_changes_add(changes, n_changes, r == -EINVAL ? -EXDEV : r, dst_updated ?: dst, info->name); @@ -1875,7 +1875,7 @@ static int install_info_symlink_alias( const LookupPaths *lp, const char *config_path, bool force, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { int r = 0, q; @@ -1889,7 +1889,7 @@ static int install_info_symlink_alias( q = install_name_printf(scope, info, *s, &dst); if (q < 0) { - unit_file_changes_add(changes, n_changes, q, *s, NULL); + install_changes_add(changes, n_changes, q, *s, NULL); r = r < 0 ? r : q; continue; } @@ -1921,7 +1921,7 @@ static int install_info_symlink_wants( const char *config_path, char **list, const char *suffix, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_free_ char *buf = NULL; @@ -1960,7 +1960,7 @@ static int install_info_symlink_wants( path = TAKE_PTR(instance.path); if (instance.type == UNIT_FILE_TYPE_MASKED) { - unit_file_changes_add(changes, n_changes, -ERFKILL, path, NULL); + install_changes_add(changes, n_changes, -ERFKILL, path, NULL); return -ERFKILL; } @@ -1979,7 +1979,7 @@ static int install_info_symlink_wants( q = install_name_printf(scope, info, *s, &dst); if (q < 0) { - unit_file_changes_add(changes, n_changes, q, *s, NULL); + install_changes_add(changes, n_changes, q, *s, NULL); return q; } @@ -1995,10 +1995,10 @@ static int install_info_symlink_wants( continue; if (unit_name_is_valid(dst, UNIT_NAME_ANY)) { - unit_file_changes_add(changes, n_changes, -EIDRM, dst, n); + install_changes_add(changes, n_changes, -EIDRM, dst, n); r = -EIDRM; } else { - unit_file_changes_add(changes, n_changes, -EUCLEAN, dst, NULL); + install_changes_add(changes, n_changes, -EUCLEAN, dst, NULL); r = -EUCLEAN; } @@ -2014,7 +2014,7 @@ static int install_info_symlink_wants( r = q; if (unit_file_exists(scope, lp, dst) == 0) - unit_file_changes_add(changes, n_changes, UNIT_FILE_DESTINATION_NOT_PRESENT, dst, info->path); + install_changes_add(changes, n_changes, UNIT_FILE_DESTINATION_NOT_PRESENT, dst, info->path); } return r; @@ -2025,7 +2025,7 @@ static int install_info_symlink_link( const LookupPaths *lp, const char *config_path, bool force, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_free_ char *path = NULL; @@ -2055,7 +2055,7 @@ static int install_info_apply( UnitFileInstallInfo *info, const LookupPaths *lp, const char *config_path, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { int r, q; @@ -2095,7 +2095,7 @@ static int install_context_apply( UnitFileFlags file_flags, const char *config_path, SearchFlags flags, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { UnitFileInstallInfo *i; @@ -2123,20 +2123,20 @@ static int install_context_apply( q = install_info_traverse(ctx, lp, i, flags, NULL); if (q < 0) { if (i->auxiliary) { - q = unit_file_changes_add(changes, n_changes, UNIT_FILE_AUXILIARY_FAILED, NULL, i->name); + q = install_changes_add(changes, n_changes, UNIT_FILE_AUXILIARY_FAILED, NULL, i->name); if (q < 0) return q; continue; } - unit_file_changes_add(changes, n_changes, q, i->name, NULL); + install_changes_add(changes, n_changes, q, i->name, NULL); return q; } /* We can attempt to process a masked unit when a different unit * that we were processing specifies it in Also=. */ if (i->type == UNIT_FILE_TYPE_MASKED) { - unit_file_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path, NULL); + install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path, NULL); if (r >= 0) /* Assume that something *could* have been enabled here, * avoid "empty [Install] section" warning. */ @@ -2164,7 +2164,7 @@ static int install_context_mark_for_removal( const LookupPaths *lp, Set **remove_symlinks_to, const char *config_path, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { UnitFileInstallInfo *i; @@ -2192,22 +2192,22 @@ static int install_context_mark_for_removal( r = install_info_traverse(ctx, lp, i, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, NULL); if (r == -ENOLINK) { log_debug_errno(r, "Name %s leads to a dangling symlink, removing name.", i->name); - unit_file_changes_add(changes, n_changes, UNIT_FILE_IS_DANGLING, i->path ?: i->name, NULL); + install_changes_add(changes, n_changes, UNIT_FILE_IS_DANGLING, i->path ?: i->name, NULL); } else if (r == -ENOENT) { if (i->auxiliary) /* some unit specified in Also= or similar is missing */ log_debug_errno(r, "Auxiliary unit of %s not found, removing name.", i->name); else { log_debug_errno(r, "Unit %s not found, removing name.", i->name); - unit_file_changes_add(changes, n_changes, r, i->path ?: i->name, NULL); + install_changes_add(changes, n_changes, r, i->path ?: i->name, NULL); } } else if (r < 0) { log_debug_errno(r, "Failed to find unit %s, removing name: %m", i->name); - unit_file_changes_add(changes, n_changes, r, i->path ?: i->name, NULL); + install_changes_add(changes, n_changes, r, i->path ?: i->name, NULL); } else if (i->type == UNIT_FILE_TYPE_MASKED) { log_debug("Unit file %s is masked, ignoring.", i->name); - unit_file_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path ?: i->name, NULL); + install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path ?: i->name, NULL); continue; } else if (i->type != UNIT_FILE_TYPE_REGULAR) { log_debug("Unit %s has type %s, ignoring.", i->name, unit_file_type_to_string(i->type) ?: "invalid"); @@ -2227,7 +2227,7 @@ int unit_file_mask( UnitFileFlags flags, const char *root_dir, char **names, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2272,7 +2272,7 @@ int unit_file_unmask( UnitFileFlags flags, const char *root_dir, char **names, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2338,13 +2338,13 @@ int unit_file_unmask( if (errno != ENOENT) { if (r >= 0) r = -errno; - unit_file_changes_add(changes, n_changes, -errno, path, NULL); + install_changes_add(changes, n_changes, -errno, path, NULL); } continue; } - unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, path, NULL); + install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, path, NULL); rp = skip_root(lp.root_dir, path); q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: path); @@ -2364,7 +2364,7 @@ int unit_file_link( UnitFileFlags flags, const char *root_dir, char **files, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2463,7 +2463,7 @@ int unit_file_revert( LookupScope scope, const char *root_dir, char **names, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_set_free_free_ Set *remove_symlinks_to = NULL; @@ -2589,10 +2589,10 @@ int unit_file_revert( if (!t) return -ENOMEM; - unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, t, NULL); + install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, t, NULL); } - unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, *i, NULL); + install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, *i, NULL); rp = skip_root(lp.root_dir, *i); q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: *i); @@ -2618,7 +2618,7 @@ int unit_file_add_dependency( char **names, const char *target, UnitDependency dep, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2688,7 +2688,7 @@ static int do_unit_file_enable( UnitFileFlags flags, const char *config_path, char **names_or_paths, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; @@ -2719,7 +2719,7 @@ int unit_file_enable( UnitFileFlags flags, const char *root_dir, char **names_or_paths, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2745,7 +2745,7 @@ static int do_unit_file_disable( UnitFileFlags flags, const char *config_path, char **names, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; @@ -2774,7 +2774,7 @@ int unit_file_disable( UnitFileFlags flags, const char *root_dir, char **files, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2857,7 +2857,7 @@ int unit_file_reenable( UnitFileFlags flags, const char *root_dir, char **names_or_paths, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2893,7 +2893,7 @@ int unit_file_set_default( UnitFileFlags flags, const char *root_dir, const char *name, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -3349,7 +3349,7 @@ static int execute_preset( const char *config_path, char **files, UnitFilePresetMode mode, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { int r; @@ -3396,7 +3396,7 @@ static int preset_prepare_one( LookupPaths *lp, const char *name, const UnitFilePresets *presets, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(install_context_done) InstallContext tmp = { .scope = scope }; @@ -3448,7 +3448,7 @@ int unit_file_preset( const char *root_dir, char **names, UnitFilePresetMode mode, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(install_context_done) InstallContext plus = {}, minus = {}; @@ -3487,7 +3487,7 @@ int unit_file_preset_all( UnitFileFlags file_flags, const char *root_dir, UnitFilePresetMode mode, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(install_context_done) InstallContext plus = {}, minus = {}; @@ -3535,7 +3535,7 @@ int unit_file_preset_all( if (r < 0 && !IN_SET(r, -EEXIST, -ERFKILL, -EADDRNOTAVAIL, -EBADSLT, -EIDRM, -EUCLEAN, -ELOOP, -ENOENT, -EUNATCH, -EXDEV)) /* Ignore generated/transient/missing/invalid units when applying preset, propagate other errors. - * Coordinate with unit_file_dump_changes() above. */ + * Coordinate with install_changes_dump() above. */ return r; } } diff --git a/src/shared/install.h b/src/shared/install.h index bc107e03ae..6e70e751e0 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -4,10 +4,10 @@ #include typedef enum UnitFilePresetMode UnitFilePresetMode; -typedef enum UnitFileChangeType UnitFileChangeType; +typedef enum InstallChangeType InstallChangeType; typedef enum UnitFileFlags UnitFileFlags; typedef enum UnitFileType UnitFileType; -typedef struct UnitFileChange UnitFileChange; +typedef struct InstallChange InstallChange; typedef struct UnitFileList UnitFileList; typedef struct UnitFileInstallInfo UnitFileInstallInfo; @@ -51,13 +51,13 @@ enum UnitFileFlags { /* type can either one of the UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK, … listed above, or a negative errno value. * If source is specified, it should be the contents of the path symlink. In case of an error, source should * be the existing symlink contents or NULL. */ -struct UnitFileChange { +struct InstallChange { int type_or_errno; /* UNIT_FILE_SYMLINK, … if positive, errno if negative */ char *path; char *source; }; -static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) { +static inline bool install_changes_have_modification(const InstallChange* changes, size_t n_changes) { for (size_t i = 0; i < n_changes; i++) if (IN_SET(changes[i].type_or_errno, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) return true; @@ -100,21 +100,21 @@ int unit_file_enable( UnitFileFlags flags, const char *root_dir, char **names_or_paths, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_disable( LookupScope scope, UnitFileFlags flags, const char *root_dir, char **names, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_reenable( LookupScope scope, UnitFileFlags flags, const char *root_dir, char **names_or_paths, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_preset( LookupScope scope, @@ -122,48 +122,48 @@ int unit_file_preset( const char *root_dir, char **names, UnitFilePresetMode mode, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_preset_all( LookupScope scope, UnitFileFlags flags, const char *root_dir, UnitFilePresetMode mode, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_mask( LookupScope scope, UnitFileFlags flags, const char *root_dir, char **names, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_unmask( LookupScope scope, UnitFileFlags flags, const char *root_dir, char **names, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_link( LookupScope scope, UnitFileFlags flags, const char *root_dir, char **files, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_revert( LookupScope scope, const char *root_dir, char **names, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_set_default( LookupScope scope, UnitFileFlags flags, const char *root_dir, const char *name, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_get_default( LookupScope scope, @@ -176,7 +176,7 @@ int unit_file_add_dependency( char **names, const char *target, UnitDependency dep, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_lookup_state( @@ -191,15 +191,15 @@ int unit_file_exists(LookupScope scope, const LookupPaths *paths, const char *na int unit_file_get_list(LookupScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); Hashmap* unit_file_list_free(Hashmap *h); -int unit_file_changes_add(UnitFileChange **changes, size_t *n_changes, int type, const char *path, const char *source); -void unit_file_changes_free(UnitFileChange *changes, size_t n_changes); -void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet); +int install_changes_add(InstallChange **changes, size_t *n_changes, int type, const char *path, const char *source); +void install_changes_free(InstallChange *changes, size_t n_changes); +void install_changes_dump(int r, const char *verb, const InstallChange *changes, size_t n_changes, bool quiet); int unit_file_verify_alias( const UnitFileInstallInfo *info, const char *dst, char **ret_dst, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); typedef struct UnitFilePresetRule UnitFilePresetRule; diff --git a/src/systemctl/systemctl-add-dependency.c b/src/systemctl/systemctl-add-dependency.c index 120798b33f..68968a783c 100644 --- a/src/systemctl/systemctl-add-dependency.c +++ b/src/systemctl/systemctl-add-dependency.c @@ -11,7 +11,7 @@ int verb_add_dependency(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **names = NULL; _cleanup_free_ char *target = NULL; const char *verb = argv[0]; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; UnitDependency dep; int r; @@ -38,7 +38,7 @@ int verb_add_dependency(int argc, char *argv[], void *userdata) { if (install_client_side()) { r = unit_file_add_dependency(arg_scope, unit_file_flags_from_args(), arg_root, names, target, dep, &changes, &n_changes); - unit_file_dump_changes(r, "add dependency on", changes, n_changes, arg_quiet); + install_changes_dump(r, "add dependency on", changes, n_changes, arg_quiet); if (r > 0) r = 0; @@ -84,7 +84,7 @@ int verb_add_dependency(int argc, char *argv[], void *userdata) { } finish: - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return r; } diff --git a/src/systemctl/systemctl-enable.c b/src/systemctl/systemctl-enable.c index 7014f92736..5be4c0c725 100644 --- a/src/systemctl/systemctl-enable.c +++ b/src/systemctl/systemctl-enable.c @@ -64,7 +64,7 @@ static int normalize_names(char **names) { int verb_enable(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **names = NULL; const char *verb = argv[0]; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; int carries_install_info = -1; bool ignore_carries_install_info = arg_quiet; @@ -127,7 +127,7 @@ int verb_enable(int argc, char *argv[], void *userdata) { else assert_not_reached(); - unit_file_dump_changes(r, verb, changes, n_changes, arg_quiet); + install_changes_dump(r, verb, changes, n_changes, arg_quiet); if (r < 0) goto finish; r = 0; @@ -280,7 +280,7 @@ int verb_enable(int argc, char *argv[], void *userdata) { } finish: - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return r; } diff --git a/src/systemctl/systemctl-is-enabled.c b/src/systemctl/systemctl-is-enabled.c index 6f3d0b6eaa..074d5084f2 100644 --- a/src/systemctl/systemctl-is-enabled.c +++ b/src/systemctl/systemctl-is-enabled.c @@ -8,7 +8,7 @@ #include "systemctl.h" static int show_installation_targets_client_side(const char *name) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; UnitFileFlags flags; char **p; diff --git a/src/systemctl/systemctl-preset-all.c b/src/systemctl/systemctl-preset-all.c index 8e36ddc0c0..68dbff5048 100644 --- a/src/systemctl/systemctl-preset-all.c +++ b/src/systemctl/systemctl-preset-all.c @@ -8,13 +8,13 @@ #include "systemctl.h" int verb_preset_all(int argc, char *argv[], void *userdata) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; int r; if (install_client_side()) { r = unit_file_preset_all(arg_scope, unit_file_flags_from_args(), arg_root, arg_preset_mode, &changes, &n_changes); - unit_file_dump_changes(r, "preset", changes, n_changes, arg_quiet); + install_changes_dump(r, "preset", changes, n_changes, arg_quiet); if (r > 0) r = 0; @@ -57,7 +57,7 @@ int verb_preset_all(int argc, char *argv[], void *userdata) { } finish: - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return r; } diff --git a/src/systemctl/systemctl-set-default.c b/src/systemctl/systemctl-set-default.c index 5f9186aa38..06845be401 100644 --- a/src/systemctl/systemctl-set-default.c +++ b/src/systemctl/systemctl-set-default.c @@ -93,7 +93,7 @@ int verb_get_default(int argc, char *argv[], void *userdata) { int verb_set_default(int argc, char *argv[], void *userdata) { _cleanup_free_ char *unit = NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; int r; @@ -108,7 +108,7 @@ int verb_set_default(int argc, char *argv[], void *userdata) { if (install_client_side()) { r = unit_file_set_default(arg_scope, UNIT_FILE_FORCE, arg_root, unit, &changes, &n_changes); - unit_file_dump_changes(r, "set default", changes, n_changes, arg_quiet); + install_changes_dump(r, "set default", changes, n_changes, arg_quiet); if (r > 0) r = 0; @@ -154,7 +154,7 @@ int verb_set_default(int argc, char *argv[], void *userdata) { } finish: - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); return r; } diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c index c2980ccbbd..897061519f 100644 --- a/src/test/test-install-root.c +++ b/src/test/test-install-root.c @@ -20,7 +20,7 @@ STATIC_DESTRUCTOR_REGISTER(root, rm_rf_physical_and_freep); TEST(basic_mask_and_enable) { const char *p; UnitFileState state; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "a.service", NULL) == -ENOENT); @@ -64,7 +64,7 @@ TEST(basic_mask_and_enable) { p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_MASKED); @@ -74,7 +74,7 @@ TEST(basic_mask_and_enable) { /* Enabling a masked unit should fail! */ assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) == -ERFKILL); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_unmask(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); @@ -82,7 +82,7 @@ TEST(basic_mask_and_enable) { assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) == 1); @@ -91,7 +91,7 @@ TEST(basic_mask_and_enable) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -102,7 +102,7 @@ TEST(basic_mask_and_enable) { /* Enabling it again should succeed but be a NOP */ assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 0); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); @@ -110,7 +110,7 @@ TEST(basic_mask_and_enable) { assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_DISABLED); @@ -121,7 +121,7 @@ TEST(basic_mask_and_enable) { /* Disabling a disabled unit must succeed but be a NOP */ assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 0); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; /* Let's enable this indirectly via a symlink */ @@ -131,7 +131,7 @@ TEST(basic_mask_and_enable) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -149,7 +149,7 @@ TEST(basic_mask_and_enable) { assert_se(changes[1].type_or_errno == UNIT_FILE_SYMLINK); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/a.service")); assert_se(streq(changes[1].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -193,7 +193,7 @@ TEST(basic_mask_and_enable) { p = strjoina(root, "/usr/lib/systemd/system/f.service"); assert_se(streq(changes[1].source, p)); assert_se(streq(changes[1].path, "x.target")); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "f.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -202,7 +202,7 @@ TEST(basic_mask_and_enable) { TEST(linked_units) { const char *p, *q; UnitFileState state; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0, i; /* @@ -257,7 +257,7 @@ TEST(linked_units) { assert_se(streq(changes[0].source, "/opt/linked.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "linked.service", &state) >= 0 && state == UNIT_FILE_LINKED); @@ -268,7 +268,7 @@ TEST(linked_units) { assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "linked.service", NULL) == -ENOENT); @@ -290,7 +290,7 @@ TEST(linked_units) { assert_not_reached(); } assert_se(!p && !q); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "linked.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -311,7 +311,7 @@ TEST(linked_units) { assert_not_reached(); } assert_se(!p && !q); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "linked.service", NULL) == -ENOENT); @@ -332,7 +332,7 @@ TEST(linked_units) { assert_not_reached(); } assert_se(!p && !q); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("linked3.service"), &changes, &n_changes) >= 0); @@ -341,13 +341,13 @@ TEST(linked_units) { assert_se(startswith(changes[0].path, root)); assert_se(endswith(changes[0].path, "linked3.service")); assert_se(streq(changes[0].source, "/opt/linked3.service")); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; } TEST(default) { _cleanup_free_ char *def = NULL; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; const char *p; @@ -363,7 +363,7 @@ TEST(default) { assert_se(n_changes == 1); assert_se(changes[0].type_or_errno == -ENOENT); assert_se(streq_ptr(changes[0].path, "idontexist.target")); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_default(LOOKUP_SCOPE_SYSTEM, root, &def) == -ENOENT); @@ -374,7 +374,7 @@ TEST(default) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR "/" SPECIAL_DEFAULT_TARGET); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_default(LOOKUP_SCOPE_SYSTEM, root, &def) >= 0); @@ -382,7 +382,7 @@ TEST(default) { } TEST(add_dependency) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; const char *p; @@ -404,12 +404,12 @@ TEST(add_dependency) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; } TEST(template_enable) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; UnitFileState state; const char *p; @@ -445,7 +445,7 @@ TEST(template_enable) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@def.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -459,7 +459,7 @@ TEST(template_enable) { assert_se(n_changes == 1); assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_DISABLED); @@ -476,7 +476,7 @@ TEST(template_enable) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@foo.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_INDIRECT); @@ -490,7 +490,7 @@ TEST(template_enable) { assert_se(n_changes == 1); assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_DISABLED); @@ -509,7 +509,7 @@ TEST(template_enable) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@quux.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_INDIRECT); @@ -523,7 +523,7 @@ TEST(template_enable) { } TEST(indirect) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; UnitFileState state; const char *p; @@ -555,7 +555,7 @@ TEST(indirect) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "indirecta.service", &state) >= 0 && state == UNIT_FILE_INDIRECT); @@ -567,12 +567,12 @@ TEST(indirect) { assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; } TEST(preset_and_list) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0, i; const char *p, *q; UnitFileState state; @@ -607,7 +607,7 @@ TEST(preset_and_list) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/preset-yes.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -618,7 +618,7 @@ TEST(preset_and_list) { assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_DISABLED); @@ -626,7 +626,7 @@ TEST(preset_and_list) { assert_se(unit_file_preset(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("preset-no.service"), UNIT_FILE_PRESET_FULL, &changes, &n_changes) >= 0); assert_se(n_changes == 0); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_DISABLED); @@ -647,7 +647,7 @@ TEST(preset_and_list) { assert_se(changes[i].type_or_errno == UNIT_FILE_UNLINK); } - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -681,7 +681,7 @@ TEST(preset_and_list) { TEST(revert) { const char *p; UnitFileState state; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "xx.service", NULL) == -ENOENT); @@ -696,7 +696,7 @@ TEST(revert) { /* Initially there's nothing to revert */ assert_se(unit_file_revert(LOOKUP_SCOPE_SYSTEM, root, STRV_MAKE("xx.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 0); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service"); @@ -707,7 +707,7 @@ TEST(revert) { assert_se(n_changes == 1); assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service.d/dropin.conf"); @@ -722,12 +722,12 @@ TEST(revert) { p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service.d"); assert_se(changes[1].type_or_errno == UNIT_FILE_UNLINK); assert_se(streq(changes[1].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; } TEST(preset_order) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; const char *p; UnitFileState state; @@ -760,7 +760,7 @@ TEST(preset_order) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/prefix-1.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/prefix-1.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "prefix-1.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -798,7 +798,7 @@ TEST(static_instance) { TEST(with_dropin) { const char *p; UnitFileState state; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-1.service", &state) == -ENOENT); @@ -872,7 +872,7 @@ TEST(with_dropin) { assert_se(streq(changes[0].path, p)); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-1.service"); assert_se(streq(changes[1].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2.service"), &changes, &n_changes) == 1); @@ -886,7 +886,7 @@ TEST(with_dropin) { assert_se(streq(changes[0].path, p)); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-2.service"); assert_se(streq(changes[1].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-3.service"), &changes, &n_changes) == 1); @@ -900,7 +900,7 @@ TEST(with_dropin) { assert_se(streq(changes[0].path, p)); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-3.service"); assert_se(streq(changes[1].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-4a.service"), &changes, &n_changes) == 2); @@ -914,7 +914,7 @@ TEST(with_dropin) { assert_se(streq(changes[0].path, p)); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-4b.service"); assert_se(streq(changes[1].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-1.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -927,7 +927,7 @@ TEST(with_dropin) { TEST(with_dropin_template) { const char *p; UnitFileState state; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-1@.service", &state) == -ENOENT); @@ -981,7 +981,7 @@ TEST(with_dropin_template) { assert_se(streq(changes[0].path, p)); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-1@instance-1.service"); assert_se(streq(changes[1].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2@instance-1.service"), &changes, &n_changes) == 1); @@ -994,7 +994,7 @@ TEST(with_dropin_template) { assert_se(streq(changes[0].path, p)); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-2@instance-1.service"); assert_se(streq(changes[1].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2@instance-2.service"), &changes, &n_changes) == 1); @@ -1003,7 +1003,7 @@ TEST(with_dropin_template) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-2.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-3@.service"), &changes, &n_changes) == 1); @@ -1012,7 +1012,7 @@ TEST(with_dropin_template) { assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3@instance-2.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-1@instance-1.service", &state) >= 0 && state == UNIT_FILE_ENABLED); @@ -1023,7 +1023,7 @@ TEST(with_dropin_template) { } TEST(preset_multiple_instances) { - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; const char *p; UnitFileState state; @@ -1052,7 +1052,7 @@ TEST(preset_multiple_instances) { assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("foo@bar0.service"), &changes, &n_changes) >= 0); @@ -1060,7 +1060,7 @@ TEST(preset_multiple_instances) { assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service"); assert_se(streq(changes[0].path, p)); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; /* Check for preset-all case, only instances on the list should be enabled, not including the default instance */ @@ -1076,7 +1076,7 @@ TEST(preset_multiple_instances) { assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "foo@bar1.service", &state) >= 0 && state == UNIT_FILE_ENABLED); assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "foo@bartest.service", &state) >= 0 && state == UNIT_FILE_ENABLED); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); } static void verify_one( diff --git a/src/test/test-install.c b/src/test/test-install.c index 6c5a036465..95aeb77183 100644 --- a/src/test/test-install.c +++ b/src/test/test-install.c @@ -6,7 +6,7 @@ #include "install.h" #include "tests.h" -static void dump_changes(UnitFileChange *c, unsigned n) { +static void dump_changes(InstallChange *c, unsigned n) { unsigned i; assert_se(n == 0 || c); @@ -25,7 +25,7 @@ int main(int argc, char* argv[]) { int r; const char *const files[] = { "avahi-daemon.service", NULL }; const char *const files2[] = { "/home/lennart/test.service", NULL }; - UnitFileChange *changes = NULL; + InstallChange *changes = NULL; size_t n_changes = 0; UnitFileState state = 0; @@ -61,7 +61,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, files[0], &state); assert_se(r >= 0); @@ -75,7 +75,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, files[0], &state); assert_se(r >= 0); @@ -92,7 +92,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, files[0], &state); assert_se(r >= 0); @@ -109,7 +109,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, files[0], &state); assert_se(r >= 0); @@ -123,7 +123,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, files[0], &state); assert_se(r >= 0); @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, files[0], &state); assert_se(r >= 0); @@ -154,7 +154,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, files[0], &state); assert_se(r >= 0); @@ -168,7 +168,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, basename(files2[0]), &state); assert_se(r >= 0); @@ -182,7 +182,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, basename(files2[0]), &state); assert_se(r < 0); @@ -195,7 +195,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, basename(files2[0]), &state); assert_se(r >= 0); @@ -209,7 +209,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, basename(files2[0]), &state); assert_se(r < 0); @@ -222,7 +222,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, basename(files2[0]), &state); assert_se(r >= 0); @@ -236,7 +236,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, basename(files2[0]), &state); assert_se(r >= 0); @@ -250,7 +250,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, basename(files2[0]), &state); assert_se(r < 0); @@ -262,7 +262,7 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); dump_changes(changes, n_changes); - unit_file_changes_free(changes, n_changes); + install_changes_free(changes, n_changes); r = unit_file_get_state(LOOKUP_SCOPE_SYSTEM, NULL, basename(files[0]), &state); assert_se(r >= 0); diff --git a/test/test-exec-deserialization.py b/test/test-exec-deserialization.py index 08307b18d7..8ad343f73d 100755 --- a/test/test-exec-deserialization.py +++ b/test/test-exec-deserialization.py @@ -17,8 +17,7 @@ import unittest import uuid from enum import Enum - -class UnitFileChange(Enum): +class InstallChange(Enum): NO_CHANGE = 0 LINES_SWAPPED = 1 COMMAND_ADDED_BEFORE = 2 @@ -39,7 +38,7 @@ class ExecutionResumeTest(unittest.TestCase): ExecStart=/bin/sleep 3 ExecStart=/bin/bash -c "echo foo >> {self.output_file}" ''' - self.unit_files[UnitFileChange.NO_CHANGE] = unit_file_content + self.unit_files[InstallChange.NO_CHANGE] = unit_file_content unit_file_content = f''' [Service] @@ -47,7 +46,7 @@ class ExecutionResumeTest(unittest.TestCase): ExecStart=/bin/bash -c "echo foo >> {self.output_file}" ExecStart=/bin/sleep 3 ''' - self.unit_files[UnitFileChange.LINES_SWAPPED] = unit_file_content + self.unit_files[InstallChange.LINES_SWAPPED] = unit_file_content unit_file_content = f''' [Service] @@ -56,7 +55,7 @@ class ExecutionResumeTest(unittest.TestCase): ExecStart=/bin/sleep 3 ExecStart=/bin/bash -c "echo foo >> {self.output_file}" ''' - self.unit_files[UnitFileChange.COMMAND_ADDED_BEFORE] = unit_file_content + self.unit_files[InstallChange.COMMAND_ADDED_BEFORE] = unit_file_content unit_file_content = f''' [Service] @@ -65,7 +64,7 @@ class ExecutionResumeTest(unittest.TestCase): ExecStart=/bin/bash -c "echo foo >> {self.output_file}" ExecStart=/bin/bash -c "echo bar >> {self.output_file}" ''' - self.unit_files[UnitFileChange.COMMAND_ADDED_AFTER] = unit_file_content + self.unit_files[InstallChange.COMMAND_ADDED_AFTER] = unit_file_content unit_file_content = f''' [Service] @@ -75,7 +74,7 @@ class ExecutionResumeTest(unittest.TestCase): ExecStart=/bin/bash -c "echo foo >> {self.output_file}" ExecStart=/bin/bash -c "echo bar >> {self.output_file}" ''' - self.unit_files[UnitFileChange.COMMAND_INTERLEAVED] = unit_file_content + self.unit_files[InstallChange.COMMAND_INTERLEAVED] = unit_file_content unit_file_content = f''' [Service] @@ -83,13 +82,13 @@ class ExecutionResumeTest(unittest.TestCase): ExecStart=/bin/bash -c "echo bar >> {self.output_file}" ExecStart=/bin/bash -c "echo baz >> {self.output_file}" ''' - self.unit_files[UnitFileChange.REMOVAL] = unit_file_content + self.unit_files[InstallChange.REMOVAL] = unit_file_content def reload(self): subprocess.check_call(['systemctl', 'daemon-reload']) def write_unit_file(self, unit_file_change): - if not isinstance(unit_file_change, UnitFileChange): + if not isinstance(unit_file_change, InstallChange): raise ValueError('Unknown unit file change') content = self.unit_files[unit_file_change] @@ -118,7 +117,7 @@ class ExecutionResumeTest(unittest.TestCase): self.fail(f'Timed out while waiting for the output file {self.output_file} to appear') def setup_unit(self): - self.write_unit_file(UnitFileChange.NO_CHANGE) + self.write_unit_file(InstallChange.NO_CHANGE) subprocess.check_call(['systemctl', '--job-mode=replace', '--no-block', 'start', self.unit]) time.sleep(1) @@ -132,7 +131,7 @@ class ExecutionResumeTest(unittest.TestCase): def test_swapped(self): self.setup_unit() - self.write_unit_file(UnitFileChange.LINES_SWAPPED) + self.write_unit_file(InstallChange.LINES_SWAPPED) self.reload() self.assertTrue(not os.path.exists(self.output_file)) @@ -141,7 +140,7 @@ class ExecutionResumeTest(unittest.TestCase): expected_output = 'foo\n' self.setup_unit() - self.write_unit_file(UnitFileChange.COMMAND_ADDED_BEFORE) + self.write_unit_file(InstallChange.COMMAND_ADDED_BEFORE) self.reload() self.check_output(expected_output) @@ -150,7 +149,7 @@ class ExecutionResumeTest(unittest.TestCase): expected_output = 'foo\nbar\n' self.setup_unit() - self.write_unit_file(UnitFileChange.COMMAND_ADDED_AFTER) + self.write_unit_file(InstallChange.COMMAND_ADDED_AFTER) self.reload() self.check_output(expected_output) @@ -159,14 +158,14 @@ class ExecutionResumeTest(unittest.TestCase): expected_output = 'foo\nbar\n' self.setup_unit() - self.write_unit_file(UnitFileChange.COMMAND_INTERLEAVED) + self.write_unit_file(InstallChange.COMMAND_INTERLEAVED) self.reload() self.check_output(expected_output) def test_removal(self): self.setup_unit() - self.write_unit_file(UnitFileChange.REMOVAL) + self.write_unit_file(InstallChange.REMOVAL) self.reload() self.assertTrue(not os.path.exists(self.output_file)) From 318031fdb2ef0d74bc526b245bdade7e92e1c39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 26 Aug 2022 09:52:59 +0200 Subject: [PATCH 3/8] shared/install: rename 'unit file type' to 'install mode' git grep -l -nwi 'UnitFileType|UNIT_FILE_TYPE' | \ xargs sed -r -i 's/UnitFileType/InstallMode/g; s/UNIT_FILE_TYPE/INSTALL_MODE/g; s/unit_file_type/install_mode/g' --- src/shared/install.c | 72 ++++++++++++++++++++++---------------------- src/shared/install.h | 18 +++++------ 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/shared/install.c b/src/shared/install.c index 3d74a9ba79..8375d99735 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -91,14 +91,14 @@ void unit_file_presets_freep(UnitFilePresets *p) { p->n_rules = 0; } -static const char *const unit_file_type_table[_UNIT_FILE_TYPE_MAX] = { - [UNIT_FILE_TYPE_REGULAR] = "regular", - [UNIT_FILE_TYPE_LINKED] = "linked", - [UNIT_FILE_TYPE_ALIAS] = "alias", - [UNIT_FILE_TYPE_MASKED] = "masked", +static const char *const install_mode_table[_INSTALL_MODE_MAX] = { + [INSTALL_MODE_REGULAR] = "regular", + [INSTALL_MODE_LINKED] = "linked", + [INSTALL_MODE_ALIAS] = "alias", + [INSTALL_MODE_MASKED] = "masked", }; -DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(unit_file_type, UnitFileType); +DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(install_mode, InstallMode); static int in_search_path(const LookupPaths *lp, const char *path) { _cleanup_free_ char *parent = NULL; @@ -1084,7 +1084,7 @@ static int install_info_may_process( /* Checks whether the loaded unit file is one we should process, or is masked, * transient or generated and thus not subject to enable/disable operations. */ - if (i->type == UNIT_FILE_TYPE_MASKED) { + if (i->type == INSTALL_MODE_MASKED) { install_changes_add(changes, n_changes, -ERFKILL, i->path, NULL); return -ERFKILL; } @@ -1141,7 +1141,7 @@ static int install_info_add( return -ENOMEM; *i = (UnitFileInstallInfo) { - .type = _UNIT_FILE_TYPE_INVALID, + .type = _INSTALL_MODE_INVALID, .auxiliary = auxiliary, }; @@ -1344,9 +1344,9 @@ static int unit_file_load( return -errno; if (null_or_empty(&st)) - info->type = UNIT_FILE_TYPE_MASKED; + info->type = INSTALL_MODE_MASKED; else if (S_ISREG(st.st_mode)) - info->type = UNIT_FILE_TYPE_REGULAR; + info->type = INSTALL_MODE_REGULAR; else if (S_ISLNK(st.st_mode)) return -ELOOP; else if (S_ISDIR(st.st_mode)) @@ -1376,7 +1376,7 @@ static int unit_file_load( if (null_or_empty(&st)) { if ((flags & SEARCH_DROPIN) == 0) - info->type = UNIT_FILE_TYPE_MASKED; + info->type = INSTALL_MODE_MASKED; return 0; } @@ -1413,7 +1413,7 @@ static int unit_file_load( return log_debug_errno(r, "Failed to parse \"%s\": %m", info->name); if ((flags & SEARCH_DROPIN) == 0) - info->type = UNIT_FILE_TYPE_REGULAR; + info->type = INSTALL_MODE_REGULAR; return (int) strv_length(info->aliases) + @@ -1445,11 +1445,11 @@ static int unit_file_load_or_readlink( if (r < 0 && r != -ENOENT) return log_debug_errno(r, "Failed to stat %s: %m", info->symlink_target); if (r > 0) - info->type = UNIT_FILE_TYPE_MASKED; + info->type = INSTALL_MODE_MASKED; else if (outside_search_path) - info->type = UNIT_FILE_TYPE_LINKED; + info->type = INSTALL_MODE_LINKED; else - info->type = UNIT_FILE_TYPE_ALIAS; + info->type = INSTALL_MODE_ALIAS; return 0; } @@ -1470,7 +1470,7 @@ static int unit_file_search( assert(lp); /* Was this unit already loaded? */ - if (info->type != _UNIT_FILE_TYPE_INVALID) + if (info->type != _INSTALL_MODE_INVALID) return 0; if (info->path) @@ -1530,7 +1530,7 @@ static int unit_file_search( "Cannot find unit %s%s%s.", info->name, template ? " or " : "", strempty(template)); - if (info->type == UNIT_FILE_TYPE_MASKED) + if (info->type == INSTALL_MODE_MASKED) return result; /* Search for drop-in directories */ @@ -1588,7 +1588,7 @@ static int install_info_follow( assert(ctx); assert(info); - if (!IN_SET(info->type, UNIT_FILE_TYPE_ALIAS, UNIT_FILE_TYPE_LINKED)) + if (!IN_SET(info->type, INSTALL_MODE_ALIAS, INSTALL_MODE_LINKED)) return -EINVAL; if (!info->symlink_target) return -EINVAL; @@ -1599,7 +1599,7 @@ static int install_info_follow( return -EXDEV; free_and_replace(info->path, info->symlink_target); - info->type = _UNIT_FILE_TYPE_INVALID; + info->type = _INSTALL_MODE_INVALID; return unit_file_load_or_readlink(ctx, info, info->path, lp, flags); } @@ -1628,7 +1628,7 @@ static int install_info_traverse( return r; i = start; - while (IN_SET(i->type, UNIT_FILE_TYPE_ALIAS, UNIT_FILE_TYPE_LINKED)) { + while (IN_SET(i->type, INSTALL_MODE_ALIAS, INSTALL_MODE_LINKED)) { /* Follow the symlink */ if (++k > UNIT_FILE_FOLLOW_SYMLINK_MAX) @@ -1644,7 +1644,7 @@ static int install_info_traverse( r = install_info_follow(ctx, i, lp, flags, /* If linked, don't look at the target name */ - /* ignore_different_name= */ i->type == UNIT_FILE_TYPE_LINKED); + /* ignore_different_name= */ i->type == INSTALL_MODE_LINKED); if (r == -EXDEV) { _cleanup_free_ char *buffer = NULL; const char *bn; @@ -1942,7 +1942,7 @@ static int install_info_symlink_wants( else if (info->default_instance) { UnitFileInstallInfo instance = { - .type = _UNIT_FILE_TYPE_INVALID, + .type = _INSTALL_MODE_INVALID, }; _cleanup_free_ char *path = NULL; @@ -1959,7 +1959,7 @@ static int install_info_symlink_wants( path = TAKE_PTR(instance.path); - if (instance.type == UNIT_FILE_TYPE_MASKED) { + if (instance.type == INSTALL_MODE_MASKED) { install_changes_add(changes, n_changes, -ERFKILL, path, NULL); return -ERFKILL; } @@ -2064,7 +2064,7 @@ static int install_info_apply( assert(lp); assert(config_path); - if (info->type != UNIT_FILE_TYPE_REGULAR) + if (info->type != INSTALL_MODE_REGULAR) return 0; bool force = file_flags & UNIT_FILE_FORCE; @@ -2135,7 +2135,7 @@ static int install_context_apply( /* We can attempt to process a masked unit when a different unit * that we were processing specifies it in Also=. */ - if (i->type == UNIT_FILE_TYPE_MASKED) { + if (i->type == INSTALL_MODE_MASKED) { install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path, NULL); if (r >= 0) /* Assume that something *could* have been enabled here, @@ -2144,7 +2144,7 @@ static int install_context_apply( continue; } - if (i->type != UNIT_FILE_TYPE_REGULAR) + if (i->type != INSTALL_MODE_REGULAR) continue; q = install_info_apply(ctx->scope, file_flags, i, lp, config_path, changes, n_changes); @@ -2205,12 +2205,12 @@ static int install_context_mark_for_removal( } else if (r < 0) { log_debug_errno(r, "Failed to find unit %s, removing name: %m", i->name); install_changes_add(changes, n_changes, r, i->path ?: i->name, NULL); - } else if (i->type == UNIT_FILE_TYPE_MASKED) { + } else if (i->type == INSTALL_MODE_MASKED) { log_debug("Unit file %s is masked, ignoring.", i->name); install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path ?: i->name, NULL); continue; - } else if (i->type != UNIT_FILE_TYPE_REGULAR) { - log_debug("Unit %s has type %s, ignoring.", i->name, unit_file_type_to_string(i->type) ?: "invalid"); + } else if (i->type != INSTALL_MODE_REGULAR) { + log_debug("Unit %s has type %s, ignoring.", i->name, install_mode_to_string(i->type) ?: "invalid"); continue; } @@ -2650,7 +2650,7 @@ int unit_file_add_dependency( if (r < 0) return r; - assert(target_info->type == UNIT_FILE_TYPE_REGULAR); + assert(target_info->type == INSTALL_MODE_REGULAR); STRV_FOREACH(name, names) { char ***l; @@ -2661,7 +2661,7 @@ int unit_file_add_dependency( if (r < 0) return r; - assert(info->type == UNIT_FILE_TYPE_REGULAR); + assert(info->type == INSTALL_MODE_REGULAR); /* We didn't actually load anything from the unit * file, but instead just add in our new symlink to @@ -2702,7 +2702,7 @@ static int do_unit_file_enable( if (r < 0) return r; - assert(info->type == UNIT_FILE_TYPE_REGULAR); + assert(info->type == INSTALL_MODE_REGULAR); } /* This will return the number of symlink rules that were @@ -2980,9 +2980,9 @@ int unit_file_lookup_state( if (r < 0) return log_debug_errno(r, "Failed to discover unit %s: %m", name); - assert(IN_SET(info->type, UNIT_FILE_TYPE_REGULAR, UNIT_FILE_TYPE_MASKED)); + assert(IN_SET(info->type, INSTALL_MODE_REGULAR, INSTALL_MODE_MASKED)); log_debug("Found unit %s at %s (%s)", name, strna(info->path), - info->type == UNIT_FILE_TYPE_REGULAR ? "regular file" : "mask"); + info->type == INSTALL_MODE_REGULAR ? "regular file" : "mask"); /* Shortcut things, if the caller just wants to know if this unit exists. */ if (!ret) @@ -2990,7 +2990,7 @@ int unit_file_lookup_state( switch (info->type) { - case UNIT_FILE_TYPE_MASKED: + case INSTALL_MODE_MASKED: r = path_is_runtime(lp, info->path, true); if (r < 0) return r; @@ -2998,7 +2998,7 @@ int unit_file_lookup_state( state = r > 0 ? UNIT_FILE_MASKED_RUNTIME : UNIT_FILE_MASKED; break; - case UNIT_FILE_TYPE_REGULAR: + case INSTALL_MODE_REGULAR: /* Check if the name we were querying is actually an alias */ if (!streq(name, basename(info->path)) && !unit_name_is_valid(info->name, UNIT_NAME_INSTANCE)) { state = UNIT_FILE_ALIAS; diff --git a/src/shared/install.h b/src/shared/install.h index 6e70e751e0..6fd6d0287f 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -6,7 +6,7 @@ typedef enum UnitFilePresetMode UnitFilePresetMode; typedef enum InstallChangeType InstallChangeType; typedef enum UnitFileFlags UnitFileFlags; -typedef enum UnitFileType UnitFileType; +typedef enum InstallMode InstallMode; typedef struct InstallChange InstallChange; typedef struct UnitFileList UnitFileList; typedef struct UnitFileInstallInfo UnitFileInstallInfo; @@ -69,13 +69,13 @@ struct UnitFileList { UnitFileState state; }; -enum UnitFileType { - UNIT_FILE_TYPE_REGULAR, - UNIT_FILE_TYPE_LINKED, - UNIT_FILE_TYPE_ALIAS, - UNIT_FILE_TYPE_MASKED, - _UNIT_FILE_TYPE_MAX, - _UNIT_FILE_TYPE_INVALID = -EINVAL, +enum InstallMode { + INSTALL_MODE_REGULAR, + INSTALL_MODE_LINKED, + INSTALL_MODE_ALIAS, + INSTALL_MODE_MASKED, + _INSTALL_MODE_MAX, + _INSTALL_MODE_INVALID = -EINVAL, }; struct UnitFileInstallInfo { @@ -91,7 +91,7 @@ struct UnitFileInstallInfo { char *default_instance; char *symlink_target; - UnitFileType type; + InstallMode type; bool auxiliary; }; From 91810c8ffc34d3e324c1ef85a3135780d15fd013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 26 Aug 2022 10:11:13 +0200 Subject: [PATCH 4/8] shared/install: rename UnitFileInstallInfo.type to .install_mode --- src/shared/install.c | 59 ++++++++++++++++++++++---------------------- src/shared/install.h | 2 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/shared/install.c b/src/shared/install.c index 8375d99735..31894b882e 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1084,7 +1084,7 @@ static int install_info_may_process( /* Checks whether the loaded unit file is one we should process, or is masked, * transient or generated and thus not subject to enable/disable operations. */ - if (i->type == INSTALL_MODE_MASKED) { + if (i->install_mode == INSTALL_MODE_MASKED) { install_changes_add(changes, n_changes, -ERFKILL, i->path, NULL); return -ERFKILL; } @@ -1141,7 +1141,7 @@ static int install_info_add( return -ENOMEM; *i = (UnitFileInstallInfo) { - .type = _INSTALL_MODE_INVALID, + .install_mode = _INSTALL_MODE_INVALID, .auxiliary = auxiliary, }; @@ -1344,9 +1344,9 @@ static int unit_file_load( return -errno; if (null_or_empty(&st)) - info->type = INSTALL_MODE_MASKED; + info->install_mode = INSTALL_MODE_MASKED; else if (S_ISREG(st.st_mode)) - info->type = INSTALL_MODE_REGULAR; + info->install_mode = INSTALL_MODE_REGULAR; else if (S_ISLNK(st.st_mode)) return -ELOOP; else if (S_ISDIR(st.st_mode)) @@ -1376,7 +1376,7 @@ static int unit_file_load( if (null_or_empty(&st)) { if ((flags & SEARCH_DROPIN) == 0) - info->type = INSTALL_MODE_MASKED; + info->install_mode = INSTALL_MODE_MASKED; return 0; } @@ -1413,7 +1413,7 @@ static int unit_file_load( return log_debug_errno(r, "Failed to parse \"%s\": %m", info->name); if ((flags & SEARCH_DROPIN) == 0) - info->type = INSTALL_MODE_REGULAR; + info->install_mode = INSTALL_MODE_REGULAR; return (int) strv_length(info->aliases) + @@ -1445,11 +1445,11 @@ static int unit_file_load_or_readlink( if (r < 0 && r != -ENOENT) return log_debug_errno(r, "Failed to stat %s: %m", info->symlink_target); if (r > 0) - info->type = INSTALL_MODE_MASKED; + info->install_mode = INSTALL_MODE_MASKED; else if (outside_search_path) - info->type = INSTALL_MODE_LINKED; + info->install_mode = INSTALL_MODE_LINKED; else - info->type = INSTALL_MODE_ALIAS; + info->install_mode = INSTALL_MODE_ALIAS; return 0; } @@ -1470,7 +1470,7 @@ static int unit_file_search( assert(lp); /* Was this unit already loaded? */ - if (info->type != _INSTALL_MODE_INVALID) + if (info->install_mode != _INSTALL_MODE_INVALID) return 0; if (info->path) @@ -1530,7 +1530,7 @@ static int unit_file_search( "Cannot find unit %s%s%s.", info->name, template ? " or " : "", strempty(template)); - if (info->type == INSTALL_MODE_MASKED) + if (info->install_mode == INSTALL_MODE_MASKED) return result; /* Search for drop-in directories */ @@ -1588,7 +1588,7 @@ static int install_info_follow( assert(ctx); assert(info); - if (!IN_SET(info->type, INSTALL_MODE_ALIAS, INSTALL_MODE_LINKED)) + if (!IN_SET(info->install_mode, INSTALL_MODE_ALIAS, INSTALL_MODE_LINKED)) return -EINVAL; if (!info->symlink_target) return -EINVAL; @@ -1599,7 +1599,7 @@ static int install_info_follow( return -EXDEV; free_and_replace(info->path, info->symlink_target); - info->type = _INSTALL_MODE_INVALID; + info->install_mode = _INSTALL_MODE_INVALID; return unit_file_load_or_readlink(ctx, info, info->path, lp, flags); } @@ -1628,7 +1628,7 @@ static int install_info_traverse( return r; i = start; - while (IN_SET(i->type, INSTALL_MODE_ALIAS, INSTALL_MODE_LINKED)) { + while (IN_SET(i->install_mode, INSTALL_MODE_ALIAS, INSTALL_MODE_LINKED)) { /* Follow the symlink */ if (++k > UNIT_FILE_FOLLOW_SYMLINK_MAX) @@ -1644,7 +1644,7 @@ static int install_info_traverse( r = install_info_follow(ctx, i, lp, flags, /* If linked, don't look at the target name */ - /* ignore_different_name= */ i->type == INSTALL_MODE_LINKED); + /* ignore_different_name= */ i->install_mode == INSTALL_MODE_LINKED); if (r == -EXDEV) { _cleanup_free_ char *buffer = NULL; const char *bn; @@ -1942,7 +1942,7 @@ static int install_info_symlink_wants( else if (info->default_instance) { UnitFileInstallInfo instance = { - .type = _INSTALL_MODE_INVALID, + .install_mode = _INSTALL_MODE_INVALID, }; _cleanup_free_ char *path = NULL; @@ -1959,7 +1959,7 @@ static int install_info_symlink_wants( path = TAKE_PTR(instance.path); - if (instance.type == INSTALL_MODE_MASKED) { + if (instance.install_mode == INSTALL_MODE_MASKED) { install_changes_add(changes, n_changes, -ERFKILL, path, NULL); return -ERFKILL; } @@ -2064,7 +2064,7 @@ static int install_info_apply( assert(lp); assert(config_path); - if (info->type != INSTALL_MODE_REGULAR) + if (info->install_mode != INSTALL_MODE_REGULAR) return 0; bool force = file_flags & UNIT_FILE_FORCE; @@ -2135,7 +2135,7 @@ static int install_context_apply( /* We can attempt to process a masked unit when a different unit * that we were processing specifies it in Also=. */ - if (i->type == INSTALL_MODE_MASKED) { + if (i->install_mode == INSTALL_MODE_MASKED) { install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path, NULL); if (r >= 0) /* Assume that something *could* have been enabled here, @@ -2144,7 +2144,7 @@ static int install_context_apply( continue; } - if (i->type != INSTALL_MODE_REGULAR) + if (i->install_mode != INSTALL_MODE_REGULAR) continue; q = install_info_apply(ctx->scope, file_flags, i, lp, config_path, changes, n_changes); @@ -2205,12 +2205,13 @@ static int install_context_mark_for_removal( } else if (r < 0) { log_debug_errno(r, "Failed to find unit %s, removing name: %m", i->name); install_changes_add(changes, n_changes, r, i->path ?: i->name, NULL); - } else if (i->type == INSTALL_MODE_MASKED) { + } else if (i->install_mode == INSTALL_MODE_MASKED) { log_debug("Unit file %s is masked, ignoring.", i->name); install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path ?: i->name, NULL); continue; - } else if (i->type != INSTALL_MODE_REGULAR) { - log_debug("Unit %s has type %s, ignoring.", i->name, install_mode_to_string(i->type) ?: "invalid"); + } else if (i->install_mode != INSTALL_MODE_REGULAR) { + log_debug("Unit %s has install mode %s, ignoring.", + i->name, install_mode_to_string(i->install_mode) ?: "invalid"); continue; } @@ -2650,7 +2651,7 @@ int unit_file_add_dependency( if (r < 0) return r; - assert(target_info->type == INSTALL_MODE_REGULAR); + assert(target_info->install_mode == INSTALL_MODE_REGULAR); STRV_FOREACH(name, names) { char ***l; @@ -2661,7 +2662,7 @@ int unit_file_add_dependency( if (r < 0) return r; - assert(info->type == INSTALL_MODE_REGULAR); + assert(info->install_mode == INSTALL_MODE_REGULAR); /* We didn't actually load anything from the unit * file, but instead just add in our new symlink to @@ -2702,7 +2703,7 @@ static int do_unit_file_enable( if (r < 0) return r; - assert(info->type == INSTALL_MODE_REGULAR); + assert(info->install_mode == INSTALL_MODE_REGULAR); } /* This will return the number of symlink rules that were @@ -2980,15 +2981,15 @@ int unit_file_lookup_state( if (r < 0) return log_debug_errno(r, "Failed to discover unit %s: %m", name); - assert(IN_SET(info->type, INSTALL_MODE_REGULAR, INSTALL_MODE_MASKED)); + assert(IN_SET(info->install_mode, INSTALL_MODE_REGULAR, INSTALL_MODE_MASKED)); log_debug("Found unit %s at %s (%s)", name, strna(info->path), - info->type == INSTALL_MODE_REGULAR ? "regular file" : "mask"); + info->install_mode == INSTALL_MODE_REGULAR ? "regular file" : "mask"); /* Shortcut things, if the caller just wants to know if this unit exists. */ if (!ret) return 0; - switch (info->type) { + switch (info->install_mode) { case INSTALL_MODE_MASKED: r = path_is_runtime(lp, info->path, true); diff --git a/src/shared/install.h b/src/shared/install.h index 6fd6d0287f..af8e460b53 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -91,7 +91,7 @@ struct UnitFileInstallInfo { char *default_instance; char *symlink_target; - InstallMode type; + InstallMode install_mode; bool auxiliary; }; From 1308f72e831dcb634e7798c125611808f8b76cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 18 Sep 2022 18:00:41 +0200 Subject: [PATCH 5/8] shared/install: rename 'unit_file_change_type' to 'install_change' + followups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We had an anonymous enum with values called UNIT_FILE_…, which could easily be confused with UNIT_FILE_… from UnitFileFlags enum. This commit renames the enum values and also the variables which refer to them. --- src/core/dbus-manager.c | 14 ++-- src/shared/bus-unit-util.c | 2 +- src/shared/install.c | 94 +++++++++++++------------- src/shared/install.h | 28 ++++---- src/systemctl/systemctl-is-enabled.c | 2 +- src/test/test-install-root.c | 98 ++++++++++++++-------------- src/test/test-install.c | 4 +- src/test/test-tables.c | 2 +- 8 files changed, 123 insertions(+), 121 deletions(-) diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 73810833ca..240408f342 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -2134,9 +2134,9 @@ static int install_error( for (size_t i = 0; i < n_changes; i++) - switch (changes[i].type_or_errno) { + switch (changes[i].change_or_errno) { - case 0 ... _UNIT_FILE_CHANGE_TYPE_MAX: /* not errors */ + case 0 ... _INSTALL_CHANGE_MAX: /* not errors */ continue; case -EEXIST: @@ -2178,8 +2178,8 @@ static int install_error( goto found; default: - assert(changes[i].type_or_errno < 0); /* other errors */ - r = sd_bus_error_set_errnof(error, changes[i].type_or_errno, "File %s: %m", changes[i].path); + assert(changes[i].change_or_errno < 0); /* other errors */ + r = sd_bus_error_set_errnof(error, changes[i].change_or_errno, "File %s: %m", changes[i].path); goto found; } @@ -2224,14 +2224,14 @@ static int reply_install_changes_and_free( for (size_t i = 0; i < n_changes; i++) { - if (changes[i].type_or_errno < 0) { + if (changes[i].change_or_errno < 0) { bad = true; continue; } r = sd_bus_message_append( reply, "(sss)", - unit_file_change_type_to_string(changes[i].type_or_errno), + install_change_to_string(changes[i].change_or_errno), changes[i].path, changes[i].source); if (r < 0) @@ -2610,7 +2610,7 @@ static int method_get_unit_file_links(sd_bus_message *message, void *userdata, s return log_error_errno(r, "Failed to get file links for %s: %m", name); for (i = 0; i < n_changes; i++) - if (changes[i].type_or_errno == UNIT_FILE_UNLINK) { + if (changes[i].change_or_errno == INSTALL_CHANGE_UNLINK) { r = sd_bus_message_append(reply, "s", changes[i].path); if (r < 0) return r; diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 9b46b732ff..2962126b0f 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -2684,7 +2684,7 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, In while ((r = sd_bus_message_read(m, "(sss)", &type, &path, &source)) > 0) { /* We expect only "success" changes to be sent over the bus. Hence, reject anything negative. */ - int ch = unit_file_change_type_from_string(type); + int ch = install_change_from_string(type); if (ch < 0) { log_notice_errno(ch, "Manager reported unknown change type \"%s\" for path \"%s\", ignoring.", type, path); diff --git a/src/shared/install.c b/src/shared/install.c index 31894b882e..6dd8fc7d84 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -268,7 +268,7 @@ static const char* config_path_from_flags(const LookupPaths *lp, UnitFileFlags f int install_changes_add( InstallChange **changes, size_t *n_changes, - int type_or_errno, /* UNIT_FILE_SYMLINK, _UNLINK, _IS_MASKED, _IS_DANGLING if positive or errno if negative */ + int change_or_errno, /* INSTALL_CHANGE_SYMLINK, _UNLINK, _IS_MASKED, _IS_DANGLING, … if positive or errno if negative */ const char *path, const char *source) { @@ -277,10 +277,10 @@ int install_changes_add( assert(!changes == !n_changes); - if (type_or_errno >= 0) - assert(type_or_errno < _UNIT_FILE_CHANGE_TYPE_MAX); + if (change_or_errno >= 0) + assert(change_or_errno < _INSTALL_CHANGE_MAX); else - assert(type_or_errno >= -ERRNO_MAX); + assert(change_or_errno >= -ERRNO_MAX); if (!changes) return 0; @@ -307,7 +307,7 @@ int install_changes_add( } c[(*n_changes)++] = (InstallChange) { - .type_or_errno = type_or_errno, + .change_or_errno = change_or_errno, .path = TAKE_PTR(p), .source = TAKE_PTR(s), }; @@ -334,92 +334,92 @@ void install_changes_dump(int r, const char *verb, const InstallChange *changes, assert(verb || r >= 0); for (size_t i = 0; i < n_changes; i++) { - assert(verb || changes[i].type_or_errno >= 0); + assert(verb || changes[i].change_or_errno >= 0); - switch (changes[i].type_or_errno) { - case UNIT_FILE_SYMLINK: + switch (changes[i].change_or_errno) { + case INSTALL_CHANGE_SYMLINK: if (!quiet) log_info("Created symlink %s %s %s.", changes[i].path, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), changes[i].source); break; - case UNIT_FILE_UNLINK: + case INSTALL_CHANGE_UNLINK: if (!quiet) log_info("Removed \"%s\".", changes[i].path); break; - case UNIT_FILE_IS_MASKED: + case INSTALL_CHANGE_IS_MASKED: if (!quiet) log_info("Unit %s is masked, ignoring.", changes[i].path); break; - case UNIT_FILE_IS_DANGLING: + case INSTALL_CHANGE_IS_DANGLING: if (!quiet) log_info("Unit %s is an alias to a unit that is not present, ignoring.", changes[i].path); break; - case UNIT_FILE_DESTINATION_NOT_PRESENT: + case INSTALL_CHANGE_DESTINATION_NOT_PRESENT: if (!quiet) log_warning("Unit %s is added as a dependency to a non-existent unit %s.", changes[i].source, changes[i].path); break; - case UNIT_FILE_AUXILIARY_FAILED: + case INSTALL_CHANGE_AUXILIARY_FAILED: if (!quiet) log_warning("Failed to enable auxiliary unit %s, ignoring.", changes[i].source); break; case -EEXIST: if (changes[i].source) - err = log_error_errno(changes[i].type_or_errno, + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, file \"%s\" already exists and is a symlink to \"%s\".", verb, changes[i].path, changes[i].source); else - err = log_error_errno(changes[i].type_or_errno, + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, file \"%s\" already exists.", verb, changes[i].path); break; case -ERFKILL: - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is masked.", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s is masked.", verb, changes[i].path); break; case -EADDRNOTAVAIL: - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is transient or generated.", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s is transient or generated.", verb, changes[i].path); break; case -EBADSLT: - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, invalid specifier in \"%s\".", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, invalid specifier in \"%s\".", verb, changes[i].path); break; case -EIDRM: - err = log_error_errno(changes[i].type_or_errno, "Failed to %s %s, destination unit %s is a non-template unit.", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s %s, destination unit %s is a non-template unit.", verb, changes[i].source, changes[i].path); break; case -EUCLEAN: - err = log_error_errno(changes[i].type_or_errno, + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, \"%s\" is not a valid unit name.", verb, changes[i].path); break; case -ELOOP: - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, refusing to operate on linked unit file %s.", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, refusing to operate on linked unit file %s.", verb, changes[i].path); break; case -EXDEV: if (changes[i].source) - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, cannot alias %s as %s.", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, cannot alias %s as %s.", verb, changes[i].source, changes[i].path); else - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, invalid unit reference \"%s\".", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, invalid unit reference \"%s\".", verb, changes[i].path); break; case -ENOENT: - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s does not exist.", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s does not exist.", verb, changes[i].path); break; case -EUNATCH: - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, cannot resolve specifiers in \"%s\".", + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, cannot resolve specifiers in \"%s\".", verb, changes[i].path); break; default: - assert(changes[i].type_or_errno < 0); - err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, file \"%s\": %m", + assert(changes[i].change_or_errno < 0); + err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, file \"%s\": %m", verb, changes[i].path); } } @@ -508,7 +508,7 @@ static int create_symlink( (void) mkdir_parents_label(new_path, 0755); if (symlink(old_path, new_path) >= 0) { - install_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path); + install_changes_add(changes, n_changes, INSTALL_CHANGE_SYMLINK, new_path, old_path); return 1; } @@ -544,8 +544,8 @@ static int create_symlink( return r; } - install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, new_path, NULL); - install_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path); + install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, new_path, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_SYMLINK, new_path, old_path); return 1; } @@ -698,7 +698,7 @@ static int remove_marked_symlinks_fd( (void) rmdir_parents(p, config_path); } - install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, p, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, p, NULL); /* Now, remember the full path (but with the root prefix removed) of * the symlink we just removed, and remove any symlinks to it, too. */ @@ -2014,7 +2014,7 @@ static int install_info_symlink_wants( r = q; if (unit_file_exists(scope, lp, dst) == 0) - install_changes_add(changes, n_changes, UNIT_FILE_DESTINATION_NOT_PRESENT, dst, info->path); + install_changes_add(changes, n_changes, INSTALL_CHANGE_DESTINATION_NOT_PRESENT, dst, info->path); } return r; @@ -2123,7 +2123,7 @@ static int install_context_apply( q = install_info_traverse(ctx, lp, i, flags, NULL); if (q < 0) { if (i->auxiliary) { - q = install_changes_add(changes, n_changes, UNIT_FILE_AUXILIARY_FAILED, NULL, i->name); + q = install_changes_add(changes, n_changes, INSTALL_CHANGE_AUXILIARY_FAILED, NULL, i->name); if (q < 0) return q; continue; @@ -2136,7 +2136,7 @@ static int install_context_apply( /* We can attempt to process a masked unit when a different unit * that we were processing specifies it in Also=. */ if (i->install_mode == INSTALL_MODE_MASKED) { - install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_IS_MASKED, i->path, NULL); if (r >= 0) /* Assume that something *could* have been enabled here, * avoid "empty [Install] section" warning. */ @@ -2192,7 +2192,7 @@ static int install_context_mark_for_removal( r = install_info_traverse(ctx, lp, i, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, NULL); if (r == -ENOLINK) { log_debug_errno(r, "Name %s leads to a dangling symlink, removing name.", i->name); - install_changes_add(changes, n_changes, UNIT_FILE_IS_DANGLING, i->path ?: i->name, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_IS_DANGLING, i->path ?: i->name, NULL); } else if (r == -ENOENT) { if (i->auxiliary) /* some unit specified in Also= or similar is missing */ @@ -2207,7 +2207,7 @@ static int install_context_mark_for_removal( install_changes_add(changes, n_changes, r, i->path ?: i->name, NULL); } else if (i->install_mode == INSTALL_MODE_MASKED) { log_debug("Unit file %s is masked, ignoring.", i->name); - install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path ?: i->name, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_IS_MASKED, i->path ?: i->name, NULL); continue; } else if (i->install_mode != INSTALL_MODE_REGULAR) { log_debug("Unit %s has install mode %s, ignoring.", @@ -2345,7 +2345,7 @@ int unit_file_unmask( continue; } - install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, path, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, path, NULL); rp = skip_root(lp.root_dir, path); q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: path); @@ -2590,10 +2590,10 @@ int unit_file_revert( if (!t) return -ENOMEM; - install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, t, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, t, NULL); } - install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, *i, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, *i, NULL); rp = skip_root(lp.root_dir, *i); q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: *i); @@ -3651,16 +3651,16 @@ static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = { DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState); -static const char* const unit_file_change_type_table[_UNIT_FILE_CHANGE_TYPE_MAX] = { - [UNIT_FILE_SYMLINK] = "symlink", - [UNIT_FILE_UNLINK] = "unlink", - [UNIT_FILE_IS_MASKED] = "masked", - [UNIT_FILE_IS_DANGLING] = "dangling", - [UNIT_FILE_DESTINATION_NOT_PRESENT] = "destination not present", - [UNIT_FILE_AUXILIARY_FAILED] = "auxiliary unit failed", +static const char* const install_change_table[_INSTALL_CHANGE_MAX] = { + [INSTALL_CHANGE_SYMLINK] = "symlink", + [INSTALL_CHANGE_UNLINK] = "unlink", + [INSTALL_CHANGE_IS_MASKED] = "masked", + [INSTALL_CHANGE_IS_DANGLING] = "dangling", + [INSTALL_CHANGE_DESTINATION_NOT_PRESENT] = "destination not present", + [INSTALL_CHANGE_AUXILIARY_FAILED] = "auxiliary unit failed", }; -DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, int); +DEFINE_STRING_TABLE_LOOKUP(install_change, int); static const char* const unit_file_preset_mode_table[_UNIT_FILE_PRESET_MAX] = { [UNIT_FILE_PRESET_FULL] = "full", diff --git a/src/shared/install.h b/src/shared/install.h index af8e460b53..dfc92d5623 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -29,14 +29,14 @@ enum UnitFilePresetMode { /* This enum type is anonymous, since we usually store it in an 'int', as we overload it with negative errno * values. */ enum { - UNIT_FILE_SYMLINK, - UNIT_FILE_UNLINK, - UNIT_FILE_IS_MASKED, - UNIT_FILE_IS_DANGLING, - UNIT_FILE_DESTINATION_NOT_PRESENT, - UNIT_FILE_AUXILIARY_FAILED, - _UNIT_FILE_CHANGE_TYPE_MAX, - _UNIT_FILE_CHANGE_TYPE_INVALID = -EINVAL, + INSTALL_CHANGE_SYMLINK, + INSTALL_CHANGE_UNLINK, + INSTALL_CHANGE_IS_MASKED, + INSTALL_CHANGE_IS_DANGLING, + INSTALL_CHANGE_DESTINATION_NOT_PRESENT, + INSTALL_CHANGE_AUXILIARY_FAILED, + _INSTALL_CHANGE_MAX, + _INSTALL_CHANGE_INVALID = -EINVAL, }; enum UnitFileFlags { @@ -48,18 +48,20 @@ enum UnitFileFlags { _UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE, }; -/* type can either one of the UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK, … listed above, or a negative errno value. +/* change_or_errno can be either one of the INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, … listed above, or + * a negative errno value. + * * If source is specified, it should be the contents of the path symlink. In case of an error, source should * be the existing symlink contents or NULL. */ struct InstallChange { - int type_or_errno; /* UNIT_FILE_SYMLINK, … if positive, errno if negative */ + int change_or_errno; /* INSTALL_CHANGE_SYMLINK, … if positive, errno if negative */ char *path; char *source; }; static inline bool install_changes_have_modification(const InstallChange* changes, size_t n_changes) { for (size_t i = 0; i < n_changes; i++) - if (IN_SET(changes[i].type_or_errno, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) + if (IN_SET(changes[i].change_or_errno, INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK)) return true; return false; } @@ -217,8 +219,8 @@ const char *unit_file_state_to_string(UnitFileState s) _const_; UnitFileState unit_file_state_from_string(const char *s) _pure_; /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */ -const char *unit_file_change_type_to_string(int s) _const_; -int unit_file_change_type_from_string(const char *s) _pure_; +const char *install_change_to_string(int s) _const_; +int install_change_from_string(const char *s) _pure_; const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_; UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_; diff --git a/src/systemctl/systemctl-is-enabled.c b/src/systemctl/systemctl-is-enabled.c index 074d5084f2..91231fa9d9 100644 --- a/src/systemctl/systemctl-is-enabled.c +++ b/src/systemctl/systemctl-is-enabled.c @@ -23,7 +23,7 @@ static int show_installation_targets_client_side(const char *name) { return log_error_errno(r, "Failed to get file links for %s: %m", name); for (size_t i = 0; i < n_changes; i++) - if (changes[i].type_or_errno == UNIT_FILE_UNLINK) + if (changes[i].change_or_errno == INSTALL_CHANGE_UNLINK) printf(" %s\n", changes[i].path); return 0; diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c index 897061519f..cf9c7f4cd9 100644 --- a/src/test/test-install-root.c +++ b/src/test/test-install-root.c @@ -59,7 +59,7 @@ TEST(basic_mask_and_enable) { assert_se(unit_file_mask(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/dev/null")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service"); assert_se(streq(changes[0].path, p)); @@ -79,7 +79,7 @@ TEST(basic_mask_and_enable) { assert_se(unit_file_unmask(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service"); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); @@ -87,7 +87,7 @@ TEST(basic_mask_and_enable) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) == 1); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); @@ -107,7 +107,7 @@ TEST(basic_mask_and_enable) { assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); @@ -127,7 +127,7 @@ TEST(basic_mask_and_enable) { /* Let's enable this indirectly via a symlink */ assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("d.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); @@ -143,10 +143,10 @@ TEST(basic_mask_and_enable) { assert_se(unit_file_reenable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("b.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); - assert_se(changes[1].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/a.service")); assert_se(streq(changes[1].path, p)); install_changes_free(changes, n_changes); @@ -185,11 +185,11 @@ TEST(basic_mask_and_enable) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("f.service"), &changes, &n_changes) == 1); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/f.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/x.target.wants/f.service"); assert_se(streq(changes[0].path, p)); - assert_se(changes[1].type_or_errno == UNIT_FILE_DESTINATION_NOT_PRESENT); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_DESTINATION_NOT_PRESENT); p = strjoina(root, "/usr/lib/systemd/system/f.service"); assert_se(streq(changes[1].source, p)); assert_se(streq(changes[1].path, "x.target")); @@ -253,7 +253,7 @@ TEST(linked_units) { /* First, let's link the unit into the search path */ assert_se(unit_file_link(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("/opt/linked.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/opt/linked.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); assert_se(streq(changes[0].path, p)); @@ -265,7 +265,7 @@ TEST(linked_units) { /* Let's unlink it from the search path again */ assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); @@ -279,7 +279,7 @@ TEST(linked_units) { p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service"); q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); for (i = 0 ; i < n_changes; i++) { - assert_se(changes[i].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[i].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[i].source, "/opt/linked.service")); if (p && streq(changes[i].path, p)) @@ -301,7 +301,7 @@ TEST(linked_units) { p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service"); q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); for (i = 0; i < n_changes; i++) { - assert_se(changes[i].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[i].change_or_errno == INSTALL_CHANGE_UNLINK); if (p && streq(changes[i].path, p)) p = NULL; @@ -321,7 +321,7 @@ TEST(linked_units) { p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked2.service"); q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked2.service"); for (i = 0 ; i < n_changes; i++) { - assert_se(changes[i].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[i].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[i].source, "/opt/linked2.service")); if (p && streq(changes[i].path, p)) @@ -337,7 +337,7 @@ TEST(linked_units) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("linked3.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(startswith(changes[0].path, root)); assert_se(endswith(changes[0].path, "linked3.service")); assert_se(streq(changes[0].source, "/opt/linked3.service")); @@ -361,7 +361,7 @@ TEST(default) { assert_se(unit_file_set_default(LOOKUP_SCOPE_SYSTEM, 0, root, "idontexist.target", &changes, &n_changes) == -ENOENT); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == -ENOENT); + assert_se(changes[0].change_or_errno == -ENOENT); assert_se(streq_ptr(changes[0].path, "idontexist.target")); install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -370,7 +370,7 @@ TEST(default) { assert_se(unit_file_set_default(LOOKUP_SCOPE_SYSTEM, 0, root, "test-default.target", &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR "/" SPECIAL_DEFAULT_TARGET); assert_se(streq(changes[0].path, p)); @@ -400,7 +400,7 @@ TEST(add_dependency) { assert_se(unit_file_add_dependency(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("add-dependency-test-service.service"), "add-dependency-test-target.target", UNIT_WANTS, &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service"); assert_se(streq(changes[0].path, p)); @@ -441,7 +441,7 @@ TEST(template_enable) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template@.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@def.service"); assert_se(streq(changes[0].path, p)); @@ -457,7 +457,7 @@ TEST(template_enable) { assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template@.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -472,7 +472,7 @@ TEST(template_enable) { log_info("== %s with template@foo.service enabled ==", __func__); assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template@foo.service"), &changes, &n_changes) >= 0); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@foo.service"); assert_se(streq(changes[0].path, p)); @@ -488,7 +488,7 @@ TEST(template_enable) { assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template@foo.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -505,7 +505,7 @@ TEST(template_enable) { log_info("== %s with template-symlink@quux.service enabled ==", __func__); assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template-symlink@quux.service"), &changes, &n_changes) >= 0); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@quux.service"); assert_se(streq(changes[0].path, p)); @@ -551,7 +551,7 @@ TEST(indirect) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service"); assert_se(streq(changes[0].path, p)); @@ -564,7 +564,7 @@ TEST(indirect) { assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service"); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); @@ -603,7 +603,7 @@ TEST(preset_and_list) { assert_se(unit_file_preset(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("preset-yes.service"), UNIT_FILE_PRESET_FULL, &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/preset-yes.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service"); assert_se(streq(changes[0].path, p)); @@ -615,7 +615,7 @@ TEST(preset_and_list) { assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("preset-yes.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service"); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); @@ -640,11 +640,11 @@ TEST(preset_and_list) { for (i = 0; i < n_changes; i++) { - if (changes[i].type_or_errno == UNIT_FILE_SYMLINK) { + if (changes[i].change_or_errno == INSTALL_CHANGE_SYMLINK) { assert_se(streq(changes[i].source, "/usr/lib/systemd/system/preset-yes.service")); assert_se(streq(changes[i].path, p)); } else - assert_se(changes[i].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[i].change_or_errno == INSTALL_CHANGE_UNLINK); } install_changes_free(changes, n_changes); @@ -705,7 +705,7 @@ TEST(revert) { /* Revert the override file */ assert_se(unit_file_revert(LOOKUP_SCOPE_SYSTEM, root, STRV_MAKE("xx.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -716,11 +716,11 @@ TEST(revert) { /* Revert the dropin file */ assert_se(unit_file_revert(LOOKUP_SCOPE_SYSTEM, root, STRV_MAKE("xx.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); assert_se(streq(changes[0].path, p)); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service.d"); - assert_se(changes[1].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_UNLINK); assert_se(streq(changes[1].path, p)); install_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -756,7 +756,7 @@ TEST(preset_order) { assert_se(unit_file_preset(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("prefix-1.service"), UNIT_FILE_PRESET_FULL, &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/prefix-1.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/prefix-1.service"); assert_se(streq(changes[0].path, p)); @@ -864,8 +864,8 @@ TEST(with_dropin) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-1.service"), &changes, &n_changes) == 1); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); - assert_se(changes[1].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-1.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-1.service"); @@ -878,8 +878,8 @@ TEST(with_dropin) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2.service"), &changes, &n_changes) == 1); assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-2.service", &state) >= 0 && state == UNIT_FILE_ENABLED); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); - assert_se(changes[1].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service")); assert_se(streq(changes[1].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2.service"); @@ -892,8 +892,8 @@ TEST(with_dropin) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-3.service"), &changes, &n_changes) == 1); assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-3.service", &state) >= 0 && state == UNIT_FILE_ENABLED); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); - assert_se(changes[1].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-3.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3.service"); @@ -906,8 +906,8 @@ TEST(with_dropin) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-4a.service"), &changes, &n_changes) == 2); assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-3.service", &state) >= 0 && state == UNIT_FILE_ENABLED); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); - assert_se(changes[1].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-4a.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-4b.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-4a.service"); @@ -973,8 +973,8 @@ TEST(with_dropin_template) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-1@instance-1.service"), &changes, &n_changes) == 1); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); - assert_se(changes[1].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1@.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-1@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-1@instance-1.service"); @@ -986,8 +986,8 @@ TEST(with_dropin_template) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2@instance-1.service"), &changes, &n_changes) == 1); assert_se(n_changes == 2); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); - assert_se(changes[1].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); + assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-2@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-1.service"); @@ -999,7 +999,7 @@ TEST(with_dropin_template) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2@instance-2.service"), &changes, &n_changes) == 1); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-2.service"); assert_se(streq(changes[0].path, p)); @@ -1008,7 +1008,7 @@ TEST(with_dropin_template) { assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-3@.service"), &changes, &n_changes) == 1); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3@.service")); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3@instance-2.service"); assert_se(streq(changes[0].path, p)); @@ -1049,7 +1049,7 @@ TEST(preset_multiple_instances) { assert_se(unit_file_preset(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("foo@bar0.service"), UNIT_FILE_PRESET_FULL, &changes, &n_changes) >= 0); assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "foo@bar0.service", &state) >= 0 && state == UNIT_FILE_ENABLED); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_SYMLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service"); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); @@ -1057,7 +1057,7 @@ TEST(preset_multiple_instances) { assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("foo@bar0.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); - assert_se(changes[0].type_or_errno == UNIT_FILE_UNLINK); + assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK); p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service"); assert_se(streq(changes[0].path, p)); install_changes_free(changes, n_changes); diff --git a/src/test/test-install.c b/src/test/test-install.c index 95aeb77183..309b18c535 100644 --- a/src/test/test-install.c +++ b/src/test/test-install.c @@ -12,9 +12,9 @@ static void dump_changes(InstallChange *c, unsigned n) { assert_se(n == 0 || c); for (i = 0; i < n; i++) { - if (c[i].type_or_errno == UNIT_FILE_UNLINK) + if (c[i].change_or_errno == INSTALL_CHANGE_UNLINK) printf("rm '%s'\n", c[i].path); - else if (c[i].type_or_errno == UNIT_FILE_SYMLINK) + else if (c[i].change_or_errno == INSTALL_CHANGE_SYMLINK) printf("ln -s '%s' '%s'\n", c[i].source, c[i].path); } } diff --git a/src/test/test-tables.c b/src/test/test-tables.c index ed409701b9..cac21f3984 100644 --- a/src/test/test-tables.c +++ b/src/test/test-tables.c @@ -116,7 +116,7 @@ int main(int argc, char **argv) { test_table(timer_state, TIMER_STATE); test_table(unit_active_state, UNIT_ACTIVE_STATE); test_table(unit_dependency, UNIT_DEPENDENCY); - test_table(unit_file_change_type, UNIT_FILE_CHANGE_TYPE); + test_table(install_change, INSTALL_CHANGE); test_table(unit_file_preset_mode, UNIT_FILE_PRESET); test_table(unit_file_state, UNIT_FILE_STATE); test_table(unit_load_state, UNIT_LOAD_STATE); From 0047d54d4241e04bb8812e68d9f826d90e2881eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 26 Aug 2022 10:40:17 +0200 Subject: [PATCH 6/8] shared/install: rename 'UnitFileInstallInfo' to 'InstallInfo' - shorter is better - name now matches the defining-file name I was also considering UnitInstallInfo. Can change if people prefer that. --- src/shared/install-printf.c | 10 ++-- src/shared/install-printf.h | 2 +- src/shared/install.c | 90 +++++++++++++++++------------------ src/shared/install.h | 6 +-- src/test/test-install-root.c | 6 +-- src/test/test-load-fragment.c | 8 ++-- 6 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c index 5436aa483b..e2a4a481ea 100644 --- a/src/shared/install-printf.c +++ b/src/shared/install-printf.c @@ -14,7 +14,7 @@ #include "user-util.h" static int specifier_prefix_and_instance(char specifier, const void *data, const char *root, const void *userdata, char **ret) { - const UnitFileInstallInfo *i = ASSERT_PTR(userdata); + const InstallInfo *i = ASSERT_PTR(userdata); _cleanup_free_ char *prefix = NULL; int r; @@ -36,7 +36,7 @@ static int specifier_prefix_and_instance(char specifier, const void *data, const } static int specifier_name(char specifier, const void *data, const char *root, const void *userdata, char **ret) { - const UnitFileInstallInfo *i = ASSERT_PTR(userdata); + const InstallInfo *i = ASSERT_PTR(userdata); char *ans; if (unit_name_is_valid(i->name, UNIT_NAME_TEMPLATE) && i->default_instance) @@ -50,13 +50,13 @@ static int specifier_name(char specifier, const void *data, const char *root, co } static int specifier_prefix(char specifier, const void *data, const char *root, const void *userdata, char **ret) { - const UnitFileInstallInfo *i = ASSERT_PTR(userdata); + const InstallInfo *i = ASSERT_PTR(userdata); return unit_name_to_prefix(i->name, ret); } static int specifier_instance(char specifier, const void *data, const char *root, const void *userdata, char **ret) { - const UnitFileInstallInfo *i = ASSERT_PTR(userdata); + const InstallInfo *i = ASSERT_PTR(userdata); char *instance; int r; @@ -99,7 +99,7 @@ static int specifier_last_component(char specifier, const void *data, const char int install_name_printf( LookupScope scope, - const UnitFileInstallInfo *info, + const InstallInfo *info, const char *format, char **ret) { /* This is similar to unit_name_printf() */ diff --git a/src/shared/install-printf.h b/src/shared/install-printf.h index 6a9ab24e15..46a7514504 100644 --- a/src/shared/install-printf.h +++ b/src/shared/install-printf.h @@ -6,6 +6,6 @@ int install_name_printf( LookupScope scope, - const UnitFileInstallInfo *info, + const InstallInfo *info, const char *format, char **ret); diff --git a/src/shared/install.c b/src/shared/install.c index 6dd8fc7d84..cc0c239694 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -64,7 +64,7 @@ struct UnitFilePresetRule { char **instances; }; -static bool unit_file_install_info_has_rules(const UnitFileInstallInfo *i) { +static bool install_info_has_rules(const InstallInfo *i) { assert(i); return !strv_isempty(i->aliases) || @@ -72,7 +72,7 @@ static bool unit_file_install_info_has_rules(const UnitFileInstallInfo *i) { !strv_isempty(i->required_by); } -static bool unit_file_install_info_has_also(const UnitFileInstallInfo *i) { +static bool install_info_has_also(const InstallInfo *i) { assert(i); return !strv_isempty(i->also); @@ -753,7 +753,7 @@ static int remove_marked_symlinks( return r; } -static int is_symlink_with_known_name(const UnitFileInstallInfo *i, const char *name) { +static int is_symlink_with_known_name(const InstallInfo *i, const char *name) { int r; if (streq(name, i->name)) @@ -782,7 +782,7 @@ static int find_symlinks_in_directory( DIR *dir, const char *dir_path, const char *root_dir, - const UnitFileInstallInfo *info, + const InstallInfo *info, bool ignore_destination, bool match_name, bool ignore_same_name, @@ -882,7 +882,7 @@ static int find_symlinks_in_directory( static int find_symlinks( const char *root_dir, - const UnitFileInstallInfo *i, + const InstallInfo *i, bool match_name, bool ignore_same_name, const char *config_path, @@ -949,7 +949,7 @@ static int find_symlinks( static int find_symlinks_in_scope( LookupScope scope, const LookupPaths *lp, - const UnitFileInstallInfo *info, + const InstallInfo *info, bool match_name, UnitFileState *state) { @@ -1040,7 +1040,7 @@ static int find_symlinks_in_scope( return 0; } -static void install_info_free(UnitFileInstallInfo *i) { +static void install_info_free(InstallInfo *i) { if (!i) return; @@ -1063,8 +1063,8 @@ static void install_context_done(InstallContext *ctx) { ctx->have_processed = ordered_hashmap_free_with_destructor(ctx->have_processed, install_info_free); } -static UnitFileInstallInfo *install_info_find(InstallContext *ctx, const char *name) { - UnitFileInstallInfo *i; +static InstallInfo *install_info_find(InstallContext *ctx, const char *name) { + InstallInfo *i; i = ordered_hashmap_get(ctx->have_processed, name); if (i) @@ -1074,7 +1074,7 @@ static UnitFileInstallInfo *install_info_find(InstallContext *ctx, const char *n } static int install_info_may_process( - const UnitFileInstallInfo *i, + const InstallInfo *i, const LookupPaths *lp, InstallChange **changes, size_t *n_changes) { @@ -1098,7 +1098,7 @@ static int install_info_may_process( } /** - * Adds a new UnitFileInstallInfo entry under name in the InstallContext.will_process + * Adds a new InstallInfo entry under name in the InstallContext.will_process * hashmap, or retrieves the existing one if already present. * * Returns negative on error, 0 if the unit was already known, 1 otherwise. @@ -1109,9 +1109,9 @@ static int install_info_add( const char *path, const char *root, bool auxiliary, - UnitFileInstallInfo **ret) { + InstallInfo **ret) { - UnitFileInstallInfo *i = NULL; + InstallInfo *i = NULL; int r; assert(ctx); @@ -1136,11 +1136,11 @@ static int install_info_add( return 0; } - i = new(UnitFileInstallInfo, 1); + i = new(InstallInfo, 1); if (!i) return -ENOMEM; - *i = (UnitFileInstallInfo) { + *i = (InstallInfo) { .install_mode = _INSTALL_MODE_INVALID, .auxiliary = auxiliary, }; @@ -1222,7 +1222,7 @@ static int config_parse_also( void *data, void *userdata) { - UnitFileInstallInfo *info = ASSERT_PTR(userdata); + InstallInfo *info = ASSERT_PTR(userdata); InstallContext *ctx = ASSERT_PTR(data); int r; @@ -1272,7 +1272,7 @@ static int config_parse_default_instance( void *userdata) { InstallContext *ctx = ASSERT_PTR(data); - UnitFileInstallInfo *info = ASSERT_PTR(userdata); + InstallInfo *info = ASSERT_PTR(userdata); _cleanup_free_ char *printed = NULL; int r; @@ -1306,7 +1306,7 @@ static int config_parse_default_instance( static int unit_file_load( InstallContext *ctx, - UnitFileInstallInfo *info, + InstallInfo *info, const char *path, const char *root_dir, SearchFlags flags) { @@ -1423,7 +1423,7 @@ static int unit_file_load( static int unit_file_load_or_readlink( InstallContext *ctx, - UnitFileInstallInfo *info, + InstallInfo *info, const char *path, const LookupPaths *lp, SearchFlags flags) { @@ -1456,7 +1456,7 @@ static int unit_file_load_or_readlink( static int unit_file_search( InstallContext *ctx, - UnitFileInstallInfo *info, + InstallInfo *info, const LookupPaths *lp, SearchFlags flags) { @@ -1580,7 +1580,7 @@ static int unit_file_search( static int install_info_follow( InstallContext *ctx, - UnitFileInstallInfo *info, + InstallInfo *info, const LookupPaths *lp, SearchFlags flags, bool ignore_different_name) { @@ -1611,11 +1611,11 @@ static int install_info_follow( static int install_info_traverse( InstallContext *ctx, const LookupPaths *lp, - UnitFileInstallInfo *start, + InstallInfo *start, SearchFlags flags, - UnitFileInstallInfo **ret) { + InstallInfo **ret) { - UnitFileInstallInfo *i; + InstallInfo *i; unsigned k = 0; int r; @@ -1710,7 +1710,7 @@ static int install_info_add_auto( InstallContext *ctx, const LookupPaths *lp, const char *name_or_path, - UnitFileInstallInfo **ret) { + InstallInfo **ret) { assert(ctx); assert(name_or_path); @@ -1730,11 +1730,11 @@ static int install_info_discover( const LookupPaths *lp, const char *name_or_path, SearchFlags flags, - UnitFileInstallInfo **ret, + InstallInfo **ret, InstallChange **changes, size_t *n_changes) { - UnitFileInstallInfo *info; + InstallInfo *info; int r; assert(ctx); @@ -1755,7 +1755,7 @@ static int install_info_discover_and_check( const LookupPaths *lp, const char *name_or_path, SearchFlags flags, - UnitFileInstallInfo **ret, + InstallInfo **ret, InstallChange **changes, size_t *n_changes) { @@ -1769,7 +1769,7 @@ static int install_info_discover_and_check( } int unit_file_verify_alias( - const UnitFileInstallInfo *info, + const InstallInfo *info, const char *dst, char **ret_dst, InstallChange **changes, @@ -1871,7 +1871,7 @@ int unit_file_verify_alias( static int install_info_symlink_alias( LookupScope scope, - UnitFileInstallInfo *info, + InstallInfo *info, const LookupPaths *lp, const char *config_path, bool force, @@ -1916,7 +1916,7 @@ static int install_info_symlink_alias( static int install_info_symlink_wants( LookupScope scope, UnitFileFlags file_flags, - UnitFileInstallInfo *info, + InstallInfo *info, const LookupPaths *lp, const char *config_path, char **list, @@ -1941,7 +1941,7 @@ static int install_info_symlink_wants( n = info->name; else if (info->default_instance) { - UnitFileInstallInfo instance = { + InstallInfo instance = { .install_mode = _INSTALL_MODE_INVALID, }; _cleanup_free_ char *path = NULL; @@ -2021,7 +2021,7 @@ static int install_info_symlink_wants( } static int install_info_symlink_link( - UnitFileInstallInfo *info, + InstallInfo *info, const LookupPaths *lp, const char *config_path, bool force, @@ -2052,7 +2052,7 @@ static int install_info_symlink_link( static int install_info_apply( LookupScope scope, UnitFileFlags file_flags, - UnitFileInstallInfo *info, + InstallInfo *info, const LookupPaths *lp, const char *config_path, InstallChange **changes, @@ -2098,7 +2098,7 @@ static int install_context_apply( InstallChange **changes, size_t *n_changes) { - UnitFileInstallInfo *i; + InstallInfo *i; int r; assert(ctx); @@ -2167,7 +2167,7 @@ static int install_context_mark_for_removal( InstallChange **changes, size_t *n_changes) { - UnitFileInstallInfo *i; + InstallInfo *i; int r; assert(ctx); @@ -2624,7 +2624,7 @@ int unit_file_add_dependency( _cleanup_(lookup_paths_free) LookupPaths lp = {}; _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *info, *target_info; + InstallInfo *info, *target_info; const char *config_path; int r; @@ -2693,7 +2693,7 @@ static int do_unit_file_enable( size_t *n_changes) { _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *info; + InstallInfo *info; int r; STRV_FOREACH(name, names_or_paths) { @@ -2811,7 +2811,7 @@ static int normalize_linked_files( STRV_FOREACH(a, names_or_paths) { _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *i = NULL; + InstallInfo *i = NULL; _cleanup_free_ char *n = NULL; r = path_extract_filename(*a, &n); @@ -2899,7 +2899,7 @@ int unit_file_set_default( _cleanup_(lookup_paths_free) LookupPaths lp = {}; _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *info; + InstallInfo *info; const char *new_path; int r; @@ -2931,7 +2931,7 @@ int unit_file_get_default( _cleanup_(lookup_paths_free) LookupPaths lp = {}; _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *info; + InstallInfo *info; char *n; int r; @@ -2966,7 +2966,7 @@ int unit_file_lookup_state( UnitFileState *ret) { _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *info; + InstallInfo *info; UnitFileState state; int r; @@ -3039,9 +3039,9 @@ int unit_file_lookup_state( if (r > 0) state = UNIT_FILE_INDIRECT; else { - if (unit_file_install_info_has_rules(info)) + if (install_info_has_rules(info)) state = UNIT_FILE_DISABLED; - else if (unit_file_install_info_has_also(info)) + else if (install_info_has_also(info)) state = UNIT_FILE_INDIRECT; else state = UNIT_FILE_STATIC; @@ -3402,7 +3402,7 @@ static int preset_prepare_one( _cleanup_(install_context_done) InstallContext tmp = { .scope = scope }; _cleanup_strv_free_ char **instance_name_list = NULL; - UnitFileInstallInfo *info; + InstallInfo *info; int r; if (install_info_find(plus, name) || install_info_find(minus, name)) diff --git a/src/shared/install.h b/src/shared/install.h index dfc92d5623..5f43b21335 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -9,7 +9,7 @@ typedef enum UnitFileFlags UnitFileFlags; typedef enum InstallMode InstallMode; typedef struct InstallChange InstallChange; typedef struct UnitFileList UnitFileList; -typedef struct UnitFileInstallInfo UnitFileInstallInfo; +typedef struct InstallInfo InstallInfo; #include "hashmap.h" #include "macro.h" @@ -80,7 +80,7 @@ enum InstallMode { _INSTALL_MODE_INVALID = -EINVAL, }; -struct UnitFileInstallInfo { +struct InstallInfo { char *name; char *path; char *root; @@ -198,7 +198,7 @@ void install_changes_free(InstallChange *changes, size_t n_changes); void install_changes_dump(int r, const char *verb, const InstallChange *changes, size_t n_changes, bool quiet); int unit_file_verify_alias( - const UnitFileInstallInfo *info, + const InstallInfo *info, const char *dst, char **ret_dst, InstallChange **changes, diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c index cf9c7f4cd9..8749df2c70 100644 --- a/src/test/test-install-root.c +++ b/src/test/test-install-root.c @@ -1080,12 +1080,12 @@ TEST(preset_multiple_instances) { } static void verify_one( - const UnitFileInstallInfo *i, + const InstallInfo *i, const char *alias, int expected, const char *updated_name) { int r; - static const UnitFileInstallInfo *last_info = NULL; + static const InstallInfo *last_info = NULL; _cleanup_free_ char *alias2 = NULL; if (i != last_info) @@ -1106,7 +1106,7 @@ static void verify_one( } TEST(verify_alias) { - const UnitFileInstallInfo + const InstallInfo plain_service = { .name = (char*) "plain.service" }, bare_template = { .name = (char*) "template1@.service" }, di_template = { .name = (char*) "template2@.service", diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c index cc6301e9dc..7705c4877d 100644 --- a/src/test/test-load-fragment.c +++ b/src/test/test-load-fragment.c @@ -509,12 +509,12 @@ TEST(config_parse_log_extra_fields) { TEST(install_printf, .sd_booted = true) { char name[] = "name.service", path[] = "/run/systemd/system/name.service"; - UnitFileInstallInfo i = { .name = name, .path = path, }; - UnitFileInstallInfo i2 = { .name= name, .path = path, }; + InstallInfo i = { .name = name, .path = path, }; + InstallInfo i2 = { .name= name, .path = path, }; char name3[] = "name@inst.service", path3[] = "/run/systemd/system/name.service"; - UnitFileInstallInfo i3 = { .name = name3, .path = path3, }; - UnitFileInstallInfo i4 = { .name = name3, .path = path3, }; + InstallInfo i3 = { .name = name3, .path = path3, }; + InstallInfo i4 = { .name = name3, .path = path3, }; _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *gid = NULL, *group = NULL, *uid = NULL, *user = NULL; From acb5b834381c7938c371b0b2a912bd8c420c4a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 29 Aug 2022 10:11:41 +0200 Subject: [PATCH 7/8] shared/install: use cleanup func for InstallInfo* In the next commit cleanup will be used in one more place. This change avoids proliferation of the open-coded cleanup calls. --- src/shared/install.c | 90 ++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 50 deletions(-) diff --git a/src/shared/install.c b/src/shared/install.c index cc0c239694..7cf73fe0aa 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1040,22 +1040,28 @@ static int find_symlinks_in_scope( return 0; } -static void install_info_free(InstallInfo *i) { +static void install_info_clear(InstallInfo *i) { if (!i) return; - free(i->name); - free(i->path); - free(i->root); - strv_free(i->aliases); - strv_free(i->wanted_by); - strv_free(i->required_by); - strv_free(i->also); - free(i->default_instance); - free(i->symlink_target); - free(i); + i->name = mfree(i->name); + i->path = mfree(i->path); + i->root = mfree(i->root); + i->aliases = strv_free(i->aliases); + i->wanted_by = strv_free(i->wanted_by); + i->required_by = strv_free(i->required_by); + i->also = strv_free(i->also); + i->default_instance = mfree(i->default_instance); + i->symlink_target = mfree(i->symlink_target); } +static InstallInfo* install_info_free(InstallInfo *i) { + install_info_clear(i); + return mfree(i); +} + +DEFINE_TRIVIAL_CLEANUP_FUNC(InstallInfo*, install_info_free); + static void install_context_done(InstallContext *ctx) { assert(ctx); @@ -1111,7 +1117,6 @@ static int install_info_add( bool auxiliary, InstallInfo **ret) { - InstallInfo *i = NULL; int r; assert(ctx); @@ -1127,7 +1132,7 @@ static int install_info_add( if (!unit_name_is_valid(name, UNIT_NAME_ANY)) return -EINVAL; - i = install_info_find(ctx, name); + InstallInfo *i = install_info_find(ctx, name); if (i) { i->auxiliary = i->auxiliary && auxiliary; @@ -1136,49 +1141,39 @@ static int install_info_add( return 0; } - i = new(InstallInfo, 1); - if (!i) + _cleanup_(install_info_freep) InstallInfo *alloc = new(InstallInfo, 1); + if (!alloc) return -ENOMEM; - *i = (InstallInfo) { + *alloc = (InstallInfo) { .install_mode = _INSTALL_MODE_INVALID, .auxiliary = auxiliary, }; - i->name = strdup(name); - if (!i->name) { - r = -ENOMEM; - goto fail; - } + alloc->name = strdup(name); + if (!alloc->name) + return -ENOMEM; if (root) { - i->root = strdup(root); - if (!i->root) { - r = -ENOMEM; - goto fail; - } + alloc->root = strdup(root); + if (!alloc->root) + return -ENOMEM; } if (path) { - i->path = strdup(path); - if (!i->path) { - r = -ENOMEM; - goto fail; - } + alloc->path = strdup(path); + if (!alloc->path) + return -ENOMEM; } - r = ordered_hashmap_ensure_put(&ctx->will_process, &string_hash_ops, i->name, i); + r = ordered_hashmap_ensure_put(&ctx->will_process, &string_hash_ops, alloc->name, alloc); if (r < 0) - goto fail; + return r; + i = TAKE_PTR(alloc); if (ret) *ret = i; - return 1; - -fail: - install_info_free(i); - return r; } static int config_parse_alias( @@ -1924,7 +1919,10 @@ static int install_info_symlink_wants( InstallChange **changes, size_t *n_changes) { - _cleanup_free_ char *buf = NULL; + _cleanup_(install_info_clear) InstallInfo instance = { + .install_mode = _INSTALL_MODE_INVALID, + }; + UnitNameFlags valid_dst_type = UNIT_NAME_ANY; const char *n; int r = 0, q; @@ -1941,30 +1939,22 @@ static int install_info_symlink_wants( n = info->name; else if (info->default_instance) { - InstallInfo instance = { - .install_mode = _INSTALL_MODE_INVALID, - }; - _cleanup_free_ char *path = NULL; - /* If this is a template, and we have a default instance, use it. */ - r = unit_name_replace_instance(info->name, info->default_instance, &buf); + r = unit_name_replace_instance(info->name, info->default_instance, &instance.name); if (r < 0) return r; - instance.name = buf; r = unit_file_search(NULL, &instance, lp, SEARCH_FOLLOW_CONFIG_SYMLINKS); if (r < 0) return r; - path = TAKE_PTR(instance.path); - if (instance.install_mode == INSTALL_MODE_MASKED) { - install_changes_add(changes, n_changes, -ERFKILL, path, NULL); + install_changes_add(changes, n_changes, -ERFKILL, instance.path, NULL); return -ERFKILL; } - n = buf; + n = instance.name; } else { /* We have a template, but no instance yet. When used with an instantiated unit, we will get From bf3b0d5f29d769fc248808d323ee95b23eae86df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 26 Aug 2022 12:02:43 +0200 Subject: [PATCH 8/8] shared/install: print warning when unmasking unit with cmdline mask 'systemctl unmask foo' will try to remove the symlink to /dev/null under /etc/. But the unit may also be masked by a symlink under /run/generator, in particular the one created by systemd-debug-generator based on systemd.mask=foo on the kernel commandline. The unmask call cannot anything about this: even if it removed the symlink from /run/generator, it'll be recreated on the next daemon-reload. Thus, we can only warn about it. Initially, I wanted to check if 'systemctl.mask' is defined on the kernel command-line, but that's not effective, because such mask symlinks can be created by other generators based on other conditions. Checking for runtime mask is "dumber", but is more robust because it doesn't assume who created the mask and why. The handling of InstallInfo is the copied from install_info_symlink_wants(). It's pretty ugly, this whole code should be rewritten from scratch. The message is printed, but the whole operation is still "successful". This keep backwards compatibility: people might call unmask to remove filesystem masks even if there's still a cmdline param in place. We allow 'systemctl mask' to create such a mask, so 'unmask' should be able to remove it. Fixes #22689. --- src/shared/install.c | 32 +++++++++++++++++++++++++++++--- src/shared/install.h | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/shared/install.c b/src/shared/install.c index 7cf73fe0aa..e45ad01092 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -352,6 +352,11 @@ void install_changes_dump(int r, const char *verb, const InstallChange *changes, if (!quiet) log_info("Unit %s is masked, ignoring.", changes[i].path); break; + case INSTALL_CHANGE_IS_MASKED_GENERATOR: + if (!quiet) + log_info("Unit %s is masked via a generator and cannot be unmasked.", + changes[i].path); + break; case INSTALL_CHANGE_IS_DANGLING: if (!quiet) log_info("Unit %s is an alias to a unit that is not present, ignoring.", @@ -2287,12 +2292,32 @@ int unit_file_unmask( bool dry_run = flags & UNIT_FILE_DRY_RUN; STRV_FOREACH(name, names) { - _cleanup_free_ char *path = NULL; - if (!unit_name_is_valid(*name, UNIT_NAME_ANY)) return -EINVAL; - path = path_make_absolute(*name, config_path); + /* If root_dir is set, we don't care about kernel commandline or generators. + * But if it is not set, we need to check for interference. */ + if (!root_dir) { + _cleanup_(install_info_clear) InstallInfo info = { + .name = *name, /* We borrow *name temporarily… */ + .install_mode = _INSTALL_MODE_INVALID, + }; + + r = unit_file_search(NULL, &info, &lp, 0); + if (r < 0) { + if (r != -ENOENT) + log_debug_errno(r, "Failed to look up unit %s, ignoring: %m", info.name); + } else { + if (info.install_mode == INSTALL_MODE_MASKED && + path_is_generator(&lp, info.path)) + install_changes_add(changes, n_changes, + INSTALL_CHANGE_IS_MASKED_GENERATOR, info.name, info.path); + } + + TAKE_PTR(info.name); /* … and give it back here */ + } + + _cleanup_free_ char *path = path_make_absolute(*name, config_path); if (!path) return -ENOMEM; @@ -3645,6 +3670,7 @@ static const char* const install_change_table[_INSTALL_CHANGE_MAX] = { [INSTALL_CHANGE_SYMLINK] = "symlink", [INSTALL_CHANGE_UNLINK] = "unlink", [INSTALL_CHANGE_IS_MASKED] = "masked", + [INSTALL_CHANGE_IS_MASKED_GENERATOR] = "masked by generator", [INSTALL_CHANGE_IS_DANGLING] = "dangling", [INSTALL_CHANGE_DESTINATION_NOT_PRESENT] = "destination not present", [INSTALL_CHANGE_AUXILIARY_FAILED] = "auxiliary unit failed", diff --git a/src/shared/install.h b/src/shared/install.h index 5f43b21335..1c910e8752 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -32,6 +32,7 @@ enum { INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, INSTALL_CHANGE_IS_MASKED, + INSTALL_CHANGE_IS_MASKED_GENERATOR, INSTALL_CHANGE_IS_DANGLING, INSTALL_CHANGE_DESTINATION_NOT_PRESENT, INSTALL_CHANGE_AUXILIARY_FAILED,