diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 73f739b12d..240408f342 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -2122,21 +2122,21 @@ 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; 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,23 +2178,23 @@ 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; } 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"); @@ -2224,14 +2224,14 @@ static int reply_unit_file_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) @@ -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; @@ -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/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..2962126b0f 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); @@ -2684,14 +2684,14 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un 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); 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-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 1a0a536080..e45ad01092 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); @@ -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; @@ -265,27 +265,27 @@ 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 */ + int change_or_errno, /* INSTALL_CHANGE_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); - 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; - c = reallocarray(*changes, *n_changes + 1, sizeof(UnitFileChange)); + c = reallocarray(*changes, *n_changes + 1, sizeof(InstallChange)); if (!c) return -ENOMEM; *changes = c; @@ -306,8 +306,8 @@ int unit_file_changes_add( path_simplify(s); } - c[(*n_changes)++] = (UnitFileChange) { - .type_or_errno = type_or_errno, + c[(*n_changes)++] = (InstallChange) { + .change_or_errno = change_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); @@ -334,92 +334,97 @@ void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *chang 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_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.", 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); } } @@ -484,7 +489,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 +513,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, INSTALL_CHANGE_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 +528,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 +539,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, INSTALL_CHANGE_UNLINK, new_path, NULL); + install_changes_add(changes, n_changes, INSTALL_CHANGE_SYMLINK, new_path, old_path); return 1; } @@ -586,7 +591,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 +676,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 +696,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, 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. */ @@ -719,7 +724,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; @@ -753,7 +758,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 +787,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 +887,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 +954,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,22 +1045,28 @@ static int find_symlinks_in_scope( return 0; } -static void install_info_free(UnitFileInstallInfo *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); @@ -1063,8 +1074,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,9 +1085,9 @@ 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, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { assert(i); assert(lp); @@ -1084,13 +1095,13 @@ 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) { - unit_file_changes_add(changes, n_changes, -ERFKILL, i->path, NULL); + if (i->install_mode == INSTALL_MODE_MASKED) { + 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; } @@ -1098,7 +1109,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 +1120,8 @@ static int install_info_add( const char *path, const char *root, bool auxiliary, - UnitFileInstallInfo **ret) { + InstallInfo **ret) { - UnitFileInstallInfo *i = NULL; int r; assert(ctx); @@ -1127,7 +1137,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 +1146,39 @@ static int install_info_add( return 0; } - i = new(UnitFileInstallInfo, 1); - if (!i) + _cleanup_(install_info_freep) InstallInfo *alloc = new(InstallInfo, 1); + if (!alloc) return -ENOMEM; - *i = (UnitFileInstallInfo) { - .type = _UNIT_FILE_TYPE_INVALID, + *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( @@ -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) { @@ -1344,9 +1344,9 @@ static int unit_file_load( return -errno; if (null_or_empty(&st)) - info->type = UNIT_FILE_TYPE_MASKED; + info->install_mode = INSTALL_MODE_MASKED; else if (S_ISREG(st.st_mode)) - info->type = UNIT_FILE_TYPE_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 = UNIT_FILE_TYPE_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 = UNIT_FILE_TYPE_REGULAR; + info->install_mode = INSTALL_MODE_REGULAR; return (int) strv_length(info->aliases) + @@ -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) { @@ -1445,18 +1445,18 @@ 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->install_mode = INSTALL_MODE_MASKED; else if (outside_search_path) - info->type = UNIT_FILE_TYPE_LINKED; + info->install_mode = INSTALL_MODE_LINKED; else - info->type = UNIT_FILE_TYPE_ALIAS; + info->install_mode = INSTALL_MODE_ALIAS; return 0; } static int unit_file_search( InstallContext *ctx, - UnitFileInstallInfo *info, + InstallInfo *info, const LookupPaths *lp, SearchFlags flags) { @@ -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->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 == UNIT_FILE_TYPE_MASKED) + if (info->install_mode == INSTALL_MODE_MASKED) return result; /* Search for drop-in directories */ @@ -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) { @@ -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->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 = _UNIT_FILE_TYPE_INVALID; + info->install_mode = _INSTALL_MODE_INVALID; return unit_file_load_or_readlink(ctx, info, info->path, lp, flags); } @@ -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; @@ -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->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 == UNIT_FILE_TYPE_LINKED); + /* ignore_different_name= */ i->install_mode == INSTALL_MODE_LINKED); if (r == -EXDEV) { _cleanup_free_ char *buffer = NULL; const char *bn; @@ -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); @@ -1728,40 +1728,40 @@ 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, + InstallInfo **ret, + InstallChange **changes, size_t *n_changes) { - UnitFileInstallInfo *info; + InstallInfo *info; int r; 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); + install_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, + InstallInfo **ret, + InstallChange **changes, size_t *n_changes) { 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; @@ -1769,10 +1769,10 @@ static int install_info_discover_and_check( } int unit_file_verify_alias( - const UnitFileInstallInfo *info, + const InstallInfo *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); @@ -1871,11 +1871,11 @@ 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, - 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; } @@ -1916,15 +1916,18 @@ 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, const char *suffix, - UnitFileChange **changes, + 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 +1944,22 @@ static int install_info_symlink_wants( n = info->name; else if (info->default_instance) { - UnitFileInstallInfo instance = { - .type = _UNIT_FILE_TYPE_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.type == UNIT_FILE_TYPE_MASKED) { - unit_file_changes_add(changes, n_changes, -ERFKILL, path, NULL); + if (instance.install_mode == INSTALL_MODE_MASKED) { + 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 @@ -1979,7 +1974,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 +1990,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,18 +2009,18 @@ 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, INSTALL_CHANGE_DESTINATION_NOT_PRESENT, dst, info->path); } return r; } static int install_info_symlink_link( - UnitFileInstallInfo *info, + InstallInfo *info, const LookupPaths *lp, const char *config_path, bool force, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_free_ char *path = NULL; @@ -2052,10 +2047,10 @@ 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, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { int r, q; @@ -2064,7 +2059,7 @@ static int install_info_apply( assert(lp); assert(config_path); - if (info->type != UNIT_FILE_TYPE_REGULAR) + if (info->install_mode != INSTALL_MODE_REGULAR) return 0; bool force = file_flags & UNIT_FILE_FORCE; @@ -2095,10 +2090,10 @@ static int install_context_apply( UnitFileFlags file_flags, const char *config_path, SearchFlags flags, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { - UnitFileInstallInfo *i; + InstallInfo *i; int r; assert(ctx); @@ -2123,20 +2118,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, INSTALL_CHANGE_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); + if (i->install_mode == INSTALL_MODE_MASKED) { + 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. */ @@ -2144,7 +2139,7 @@ static int install_context_apply( continue; } - if (i->type != UNIT_FILE_TYPE_REGULAR) + if (i->install_mode != INSTALL_MODE_REGULAR) continue; q = install_info_apply(ctx->scope, file_flags, i, lp, config_path, changes, n_changes); @@ -2164,10 +2159,10 @@ 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; + InstallInfo *i; int r; assert(ctx); @@ -2192,25 +2187,26 @@ 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, 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 */ 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); - } else if (i->type == UNIT_FILE_TYPE_MASKED) { + 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); - unit_file_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->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->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; } @@ -2226,8 +2222,8 @@ int unit_file_mask( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, - UnitFileChange **changes, + char **names, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2245,17 +2241,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,8 +2267,8 @@ int unit_file_unmask( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, - UnitFileChange **changes, + char **names, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2295,13 +2291,33 @@ int unit_file_unmask( bool dry_run = flags & UNIT_FILE_DRY_RUN; - STRV_FOREACH(i, files) { - _cleanup_free_ char *path = NULL; - - if (!unit_name_is_valid(*i, UNIT_NAME_ANY)) + STRV_FOREACH(name, names) { + if (!unit_name_is_valid(*name, UNIT_NAME_ANY)) return -EINVAL; - path = path_make_absolute(*i, 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; @@ -2316,7 +2332,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; @@ -2338,13 +2354,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, INSTALL_CHANGE_UNLINK, path, NULL); rp = skip_root(lp.root_dir, path); q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: path); @@ -2364,7 +2380,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 = {}; @@ -2384,19 +2400,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 +2422,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 +2431,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,8 +2478,8 @@ static int path_shall_revert(const LookupPaths *lp, const char *path) { int unit_file_revert( LookupScope scope, const char *root_dir, - char **files, - UnitFileChange **changes, + char **names, + InstallChange **changes, size_t *n_changes) { _cleanup_set_free_free_ Set *remove_symlinks_to = NULL; @@ -2474,11 +2490,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 +2504,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 +2561,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; @@ -2588,10 +2605,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, INSTALL_CHANGE_UNLINK, t, NULL); } - unit_file_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); @@ -2614,15 +2631,15 @@ 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, + InstallChange **changes, size_t *n_changes) { _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; @@ -2649,17 +2666,18 @@ int unit_file_add_dependency( if (r < 0) return r; - assert(target_info->type == UNIT_FILE_TYPE_REGULAR); + assert(target_info->install_mode == INSTALL_MODE_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; - assert(info->type == UNIT_FILE_TYPE_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 @@ -2685,26 +2703,27 @@ static int do_unit_file_enable( LookupScope scope, UnitFileFlags flags, const char *config_path, - char **files, - UnitFileChange **changes, + char **names_or_paths, + InstallChange **changes, size_t *n_changes) { _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *info; + InstallInfo *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; - assert(info->type == UNIT_FILE_TYPE_REGULAR); + assert(info->install_mode == INSTALL_MODE_REGULAR); } /* 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,8 +2734,8 @@ int unit_file_enable( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, - UnitFileChange **changes, + char **names_or_paths, + InstallChange **changes, size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; @@ -2733,7 +2752,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,19 +2760,19 @@ static int do_unit_file_disable( LookupScope scope, UnitFileFlags flags, const char *config_path, - char **files, - UnitFileChange **changes, + char **names, + InstallChange **changes, size_t *n_changes) { _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; _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; } @@ -2771,7 +2790,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 = {}; @@ -2807,7 +2826,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); @@ -2854,7 +2873,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 = {}; @@ -2890,12 +2909,12 @@ 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 = {}; _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *info; + InstallInfo *info; const char *new_path; int r; @@ -2927,7 +2946,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; @@ -2962,7 +2981,7 @@ int unit_file_lookup_state( UnitFileState *ret) { _cleanup_(install_context_done) InstallContext ctx = { .scope = scope }; - UnitFileInstallInfo *info; + InstallInfo *info; UnitFileState state; int r; @@ -2977,17 +2996,17 @@ 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->install_mode, 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->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 UNIT_FILE_TYPE_MASKED: + case INSTALL_MODE_MASKED: r = path_is_runtime(lp, info->path, true); if (r < 0) return r; @@ -2995,7 +3014,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; @@ -3035,9 +3054,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; @@ -3346,7 +3365,7 @@ static int execute_preset( const char *config_path, char **files, UnitFilePresetMode mode, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { int r; @@ -3393,12 +3412,12 @@ 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 }; _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)) @@ -3443,9 +3462,9 @@ int unit_file_preset( LookupScope scope, UnitFileFlags file_flags, const char *root_dir, - char **files, + char **names, UnitFilePresetMode mode, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes) { _cleanup_(install_context_done) InstallContext plus = {}, minus = {}; @@ -3470,13 +3489,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( @@ -3484,7 +3503,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 = {}; @@ -3532,7 +3551,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; } } @@ -3647,16 +3666,17 @@ 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_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", }; -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 2ba7e8aea0..1c910e8752 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -4,12 +4,12 @@ #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 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" @@ -29,14 +29,15 @@ 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_MASKED_GENERATOR, + INSTALL_CHANGE_IS_DANGLING, + INSTALL_CHANGE_DESTINATION_NOT_PRESENT, + INSTALL_CHANGE_AUXILIARY_FAILED, + _INSTALL_CHANGE_MAX, + _INSTALL_CHANGE_INVALID = -EINVAL, }; enum UnitFileFlags { @@ -48,18 +49,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 UnitFileChange { - int type_or_errno; /* UNIT_FILE_SYMLINK, … if positive, errno if negative */ +struct InstallChange { + int change_or_errno; /* INSTALL_CHANGE_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)) + if (IN_SET(changes[i].change_or_errno, INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK)) return true; return false; } @@ -69,16 +72,16 @@ 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 { +struct InstallInfo { char *name; char *path; char *root; @@ -91,7 +94,7 @@ struct UnitFileInstallInfo { char *default_instance; char *symlink_target; - UnitFileType type; + InstallMode install_mode; bool auxiliary; }; @@ -99,71 +102,71 @@ int unit_file_enable( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, - UnitFileChange **changes, + char **names_or_paths, + InstallChange **changes, size_t *n_changes); int unit_file_disable( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, - UnitFileChange **changes, + char **names, + 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, UnitFileFlags flags, const char *root_dir, - char **files, + 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 **files, - UnitFileChange **changes, + char **names, + InstallChange **changes, size_t *n_changes); int unit_file_unmask( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, - UnitFileChange **changes, + char **names, + 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 **files, - UnitFileChange **changes, + char **names, + InstallChange **changes, size_t *n_changes); int unit_file_set_default( LookupScope scope, UnitFileFlags flags, const char *root_dir, - const char *file, - UnitFileChange **changes, + const char *name, + InstallChange **changes, size_t *n_changes); int unit_file_get_default( LookupScope scope, @@ -173,10 +176,10 @@ int unit_file_add_dependency( LookupScope scope, UnitFileFlags flags, const char *root_dir, - char **files, + char **names, const char *target, UnitDependency dep, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); int unit_file_lookup_state( @@ -191,15 +194,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 InstallInfo *info, const char *dst, char **ret_dst, - UnitFileChange **changes, + InstallChange **changes, size_t *n_changes); typedef struct UnitFilePresetRule UnitFilePresetRule; @@ -217,8 +220,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-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..91231fa9d9 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; @@ -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/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..8749df2c70 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); @@ -59,12 +59,12 @@ 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)); - 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,24 +74,24 @@ 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); 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)); - 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); 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)); - 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,15 +102,15 @@ 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); 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)); - 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,17 +121,17 @@ 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 */ 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)); - 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); @@ -143,13 +143,13 @@ 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)); - 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); @@ -185,15 +185,15 @@ 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")); - 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; /* @@ -253,11 +253,11 @@ 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)); - 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); @@ -265,10 +265,10 @@ 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)); - 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); @@ -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)) @@ -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); @@ -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; @@ -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); @@ -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)) @@ -332,22 +332,22 @@ 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); 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")); - 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; @@ -361,20 +361,20 @@ 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")); - 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); 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)); - 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; @@ -400,16 +400,16 @@ 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)); - 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; @@ -441,11 +441,11 @@ 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)); - 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); @@ -457,9 +457,9 @@ 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)); - 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); @@ -472,11 +472,11 @@ 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)); - 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); @@ -488,9 +488,9 @@ 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)); - 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); @@ -505,11 +505,11 @@ 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)); - 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; @@ -551,11 +551,11 @@ 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)); - 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); @@ -564,15 +564,15 @@ 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)); - 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; @@ -603,11 +603,11 @@ 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)); - 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); @@ -615,10 +615,10 @@ 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)); - 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); @@ -640,14 +640,14 @@ 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); } - 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"); @@ -705,9 +705,9 @@ 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)); - 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"); @@ -716,18 +716,18 @@ 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)); - 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; @@ -756,11 +756,11 @@ 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)); - 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); @@ -864,57 +864,57 @@ 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"); 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); 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"); 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); 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"); 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); 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"); 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); @@ -973,46 +973,46 @@ 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"); 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); 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"); 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); 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)); - 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); 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)); - 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; @@ -1049,18 +1049,18 @@ 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)); - 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); 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)); - 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,16 +1076,16 @@ 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( - 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-install.c b/src/test/test-install.c index 6c5a036465..309b18c535 100644 --- a/src/test/test-install.c +++ b/src/test/test-install.c @@ -6,15 +6,15 @@ #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); 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); } } @@ -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/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; 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); 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))