shared/install: rename 'unit_file_change_type' to 'install_change' + followups
We had an anonymous enum with values called UNIT_FILE_…, which could easily be confused with UNIT_FILE_… from UnitFileFlags enum. This commit renames the enum values and also the variables which refer to them.
This commit is contained in:
@@ -2684,7 +2684,7 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, In
|
||||
while ((r = sd_bus_message_read(m, "(sss)", &type, &path, &source)) > 0) {
|
||||
/* We expect only "success" changes to be sent over the bus.
|
||||
Hence, reject anything negative. */
|
||||
int ch = unit_file_change_type_from_string(type);
|
||||
int ch = install_change_from_string(type);
|
||||
if (ch < 0) {
|
||||
log_notice_errno(ch, "Manager reported unknown change type \"%s\" for path \"%s\", ignoring.",
|
||||
type, path);
|
||||
|
||||
+47
-47
@@ -268,7 +268,7 @@ static const char* config_path_from_flags(const LookupPaths *lp, UnitFileFlags f
|
||||
int install_changes_add(
|
||||
InstallChange **changes,
|
||||
size_t *n_changes,
|
||||
int type_or_errno, /* UNIT_FILE_SYMLINK, _UNLINK, _IS_MASKED, _IS_DANGLING if positive or errno if negative */
|
||||
int change_or_errno, /* INSTALL_CHANGE_SYMLINK, _UNLINK, _IS_MASKED, _IS_DANGLING, … if positive or errno if negative */
|
||||
const char *path,
|
||||
const char *source) {
|
||||
|
||||
@@ -277,10 +277,10 @@ int install_changes_add(
|
||||
|
||||
assert(!changes == !n_changes);
|
||||
|
||||
if (type_or_errno >= 0)
|
||||
assert(type_or_errno < _UNIT_FILE_CHANGE_TYPE_MAX);
|
||||
if (change_or_errno >= 0)
|
||||
assert(change_or_errno < _INSTALL_CHANGE_MAX);
|
||||
else
|
||||
assert(type_or_errno >= -ERRNO_MAX);
|
||||
assert(change_or_errno >= -ERRNO_MAX);
|
||||
|
||||
if (!changes)
|
||||
return 0;
|
||||
@@ -307,7 +307,7 @@ int install_changes_add(
|
||||
}
|
||||
|
||||
c[(*n_changes)++] = (InstallChange) {
|
||||
.type_or_errno = type_or_errno,
|
||||
.change_or_errno = change_or_errno,
|
||||
.path = TAKE_PTR(p),
|
||||
.source = TAKE_PTR(s),
|
||||
};
|
||||
@@ -334,92 +334,92 @@ void install_changes_dump(int r, const char *verb, const InstallChange *changes,
|
||||
assert(verb || r >= 0);
|
||||
|
||||
for (size_t i = 0; i < n_changes; i++) {
|
||||
assert(verb || changes[i].type_or_errno >= 0);
|
||||
assert(verb || changes[i].change_or_errno >= 0);
|
||||
|
||||
switch (changes[i].type_or_errno) {
|
||||
case UNIT_FILE_SYMLINK:
|
||||
switch (changes[i].change_or_errno) {
|
||||
case INSTALL_CHANGE_SYMLINK:
|
||||
if (!quiet)
|
||||
log_info("Created symlink %s %s %s.",
|
||||
changes[i].path,
|
||||
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT),
|
||||
changes[i].source);
|
||||
break;
|
||||
case UNIT_FILE_UNLINK:
|
||||
case INSTALL_CHANGE_UNLINK:
|
||||
if (!quiet)
|
||||
log_info("Removed \"%s\".", changes[i].path);
|
||||
break;
|
||||
case UNIT_FILE_IS_MASKED:
|
||||
case INSTALL_CHANGE_IS_MASKED:
|
||||
if (!quiet)
|
||||
log_info("Unit %s is masked, ignoring.", changes[i].path);
|
||||
break;
|
||||
case UNIT_FILE_IS_DANGLING:
|
||||
case INSTALL_CHANGE_IS_DANGLING:
|
||||
if (!quiet)
|
||||
log_info("Unit %s is an alias to a unit that is not present, ignoring.",
|
||||
changes[i].path);
|
||||
break;
|
||||
case UNIT_FILE_DESTINATION_NOT_PRESENT:
|
||||
case INSTALL_CHANGE_DESTINATION_NOT_PRESENT:
|
||||
if (!quiet)
|
||||
log_warning("Unit %s is added as a dependency to a non-existent unit %s.",
|
||||
changes[i].source, changes[i].path);
|
||||
break;
|
||||
case UNIT_FILE_AUXILIARY_FAILED:
|
||||
case INSTALL_CHANGE_AUXILIARY_FAILED:
|
||||
if (!quiet)
|
||||
log_warning("Failed to enable auxiliary unit %s, ignoring.", changes[i].source);
|
||||
break;
|
||||
case -EEXIST:
|
||||
if (changes[i].source)
|
||||
err = log_error_errno(changes[i].type_or_errno,
|
||||
err = log_error_errno(changes[i].change_or_errno,
|
||||
"Failed to %s unit, file \"%s\" already exists and is a symlink to \"%s\".",
|
||||
verb, changes[i].path, changes[i].source);
|
||||
else
|
||||
err = log_error_errno(changes[i].type_or_errno,
|
||||
err = log_error_errno(changes[i].change_or_errno,
|
||||
"Failed to %s unit, file \"%s\" already exists.",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
case -ERFKILL:
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is masked.",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s is masked.",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
case -EADDRNOTAVAIL:
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is transient or generated.",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s is transient or generated.",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
case -EBADSLT:
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, invalid specifier in \"%s\".",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, invalid specifier in \"%s\".",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
case -EIDRM:
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s %s, destination unit %s is a non-template unit.",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s %s, destination unit %s is a non-template unit.",
|
||||
verb, changes[i].source, changes[i].path);
|
||||
break;
|
||||
case -EUCLEAN:
|
||||
err = log_error_errno(changes[i].type_or_errno,
|
||||
err = log_error_errno(changes[i].change_or_errno,
|
||||
"Failed to %s unit, \"%s\" is not a valid unit name.",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
case -ELOOP:
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, refusing to operate on linked unit file %s.",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, refusing to operate on linked unit file %s.",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
case -EXDEV:
|
||||
if (changes[i].source)
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, cannot alias %s as %s.",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, cannot alias %s as %s.",
|
||||
verb, changes[i].source, changes[i].path);
|
||||
else
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, invalid unit reference \"%s\".",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, invalid unit reference \"%s\".",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
case -ENOENT:
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s does not exist.",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s does not exist.",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
case -EUNATCH:
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, cannot resolve specifiers in \"%s\".",
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, cannot resolve specifiers in \"%s\".",
|
||||
verb, changes[i].path);
|
||||
break;
|
||||
default:
|
||||
assert(changes[i].type_or_errno < 0);
|
||||
err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, file \"%s\": %m",
|
||||
assert(changes[i].change_or_errno < 0);
|
||||
err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, file \"%s\": %m",
|
||||
verb, changes[i].path);
|
||||
}
|
||||
}
|
||||
@@ -508,7 +508,7 @@ static int create_symlink(
|
||||
(void) mkdir_parents_label(new_path, 0755);
|
||||
|
||||
if (symlink(old_path, new_path) >= 0) {
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_SYMLINK, new_path, old_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -544,8 +544,8 @@ static int create_symlink(
|
||||
return r;
|
||||
}
|
||||
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, new_path, NULL);
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, new_path, NULL);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_SYMLINK, new_path, old_path);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -698,7 +698,7 @@ static int remove_marked_symlinks_fd(
|
||||
(void) rmdir_parents(p, config_path);
|
||||
}
|
||||
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, p, NULL);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, p, NULL);
|
||||
|
||||
/* Now, remember the full path (but with the root prefix removed) of
|
||||
* the symlink we just removed, and remove any symlinks to it, too. */
|
||||
@@ -2014,7 +2014,7 @@ static int install_info_symlink_wants(
|
||||
r = q;
|
||||
|
||||
if (unit_file_exists(scope, lp, dst) == 0)
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_DESTINATION_NOT_PRESENT, dst, info->path);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_DESTINATION_NOT_PRESENT, dst, info->path);
|
||||
}
|
||||
|
||||
return r;
|
||||
@@ -2123,7 +2123,7 @@ static int install_context_apply(
|
||||
q = install_info_traverse(ctx, lp, i, flags, NULL);
|
||||
if (q < 0) {
|
||||
if (i->auxiliary) {
|
||||
q = install_changes_add(changes, n_changes, UNIT_FILE_AUXILIARY_FAILED, NULL, i->name);
|
||||
q = install_changes_add(changes, n_changes, INSTALL_CHANGE_AUXILIARY_FAILED, NULL, i->name);
|
||||
if (q < 0)
|
||||
return q;
|
||||
continue;
|
||||
@@ -2136,7 +2136,7 @@ static int install_context_apply(
|
||||
/* We can attempt to process a masked unit when a different unit
|
||||
* that we were processing specifies it in Also=. */
|
||||
if (i->install_mode == INSTALL_MODE_MASKED) {
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path, NULL);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_IS_MASKED, i->path, NULL);
|
||||
if (r >= 0)
|
||||
/* Assume that something *could* have been enabled here,
|
||||
* avoid "empty [Install] section" warning. */
|
||||
@@ -2192,7 +2192,7 @@ static int install_context_mark_for_removal(
|
||||
r = install_info_traverse(ctx, lp, i, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, NULL);
|
||||
if (r == -ENOLINK) {
|
||||
log_debug_errno(r, "Name %s leads to a dangling symlink, removing name.", i->name);
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_IS_DANGLING, i->path ?: i->name, NULL);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_IS_DANGLING, i->path ?: i->name, NULL);
|
||||
} else if (r == -ENOENT) {
|
||||
|
||||
if (i->auxiliary) /* some unit specified in Also= or similar is missing */
|
||||
@@ -2207,7 +2207,7 @@ static int install_context_mark_for_removal(
|
||||
install_changes_add(changes, n_changes, r, i->path ?: i->name, NULL);
|
||||
} else if (i->install_mode == INSTALL_MODE_MASKED) {
|
||||
log_debug("Unit file %s is masked, ignoring.", i->name);
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path ?: i->name, NULL);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_IS_MASKED, i->path ?: i->name, NULL);
|
||||
continue;
|
||||
} else if (i->install_mode != INSTALL_MODE_REGULAR) {
|
||||
log_debug("Unit %s has install mode %s, ignoring.",
|
||||
@@ -2345,7 +2345,7 @@ int unit_file_unmask(
|
||||
continue;
|
||||
}
|
||||
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, path, NULL);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, path, NULL);
|
||||
|
||||
rp = skip_root(lp.root_dir, path);
|
||||
q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: path);
|
||||
@@ -2590,10 +2590,10 @@ int unit_file_revert(
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, t, NULL);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, t, NULL);
|
||||
}
|
||||
|
||||
install_changes_add(changes, n_changes, UNIT_FILE_UNLINK, *i, NULL);
|
||||
install_changes_add(changes, n_changes, INSTALL_CHANGE_UNLINK, *i, NULL);
|
||||
|
||||
rp = skip_root(lp.root_dir, *i);
|
||||
q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: *i);
|
||||
@@ -3651,16 +3651,16 @@ static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = {
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState);
|
||||
|
||||
static const char* const unit_file_change_type_table[_UNIT_FILE_CHANGE_TYPE_MAX] = {
|
||||
[UNIT_FILE_SYMLINK] = "symlink",
|
||||
[UNIT_FILE_UNLINK] = "unlink",
|
||||
[UNIT_FILE_IS_MASKED] = "masked",
|
||||
[UNIT_FILE_IS_DANGLING] = "dangling",
|
||||
[UNIT_FILE_DESTINATION_NOT_PRESENT] = "destination not present",
|
||||
[UNIT_FILE_AUXILIARY_FAILED] = "auxiliary unit failed",
|
||||
static const char* const install_change_table[_INSTALL_CHANGE_MAX] = {
|
||||
[INSTALL_CHANGE_SYMLINK] = "symlink",
|
||||
[INSTALL_CHANGE_UNLINK] = "unlink",
|
||||
[INSTALL_CHANGE_IS_MASKED] = "masked",
|
||||
[INSTALL_CHANGE_IS_DANGLING] = "dangling",
|
||||
[INSTALL_CHANGE_DESTINATION_NOT_PRESENT] = "destination not present",
|
||||
[INSTALL_CHANGE_AUXILIARY_FAILED] = "auxiliary unit failed",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, int);
|
||||
DEFINE_STRING_TABLE_LOOKUP(install_change, int);
|
||||
|
||||
static const char* const unit_file_preset_mode_table[_UNIT_FILE_PRESET_MAX] = {
|
||||
[UNIT_FILE_PRESET_FULL] = "full",
|
||||
|
||||
+15
-13
@@ -29,14 +29,14 @@ enum UnitFilePresetMode {
|
||||
/* This enum type is anonymous, since we usually store it in an 'int', as we overload it with negative errno
|
||||
* values. */
|
||||
enum {
|
||||
UNIT_FILE_SYMLINK,
|
||||
UNIT_FILE_UNLINK,
|
||||
UNIT_FILE_IS_MASKED,
|
||||
UNIT_FILE_IS_DANGLING,
|
||||
UNIT_FILE_DESTINATION_NOT_PRESENT,
|
||||
UNIT_FILE_AUXILIARY_FAILED,
|
||||
_UNIT_FILE_CHANGE_TYPE_MAX,
|
||||
_UNIT_FILE_CHANGE_TYPE_INVALID = -EINVAL,
|
||||
INSTALL_CHANGE_SYMLINK,
|
||||
INSTALL_CHANGE_UNLINK,
|
||||
INSTALL_CHANGE_IS_MASKED,
|
||||
INSTALL_CHANGE_IS_DANGLING,
|
||||
INSTALL_CHANGE_DESTINATION_NOT_PRESENT,
|
||||
INSTALL_CHANGE_AUXILIARY_FAILED,
|
||||
_INSTALL_CHANGE_MAX,
|
||||
_INSTALL_CHANGE_INVALID = -EINVAL,
|
||||
};
|
||||
|
||||
enum UnitFileFlags {
|
||||
@@ -48,18 +48,20 @@ enum UnitFileFlags {
|
||||
_UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE,
|
||||
};
|
||||
|
||||
/* type can either one of the UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK, … listed above, or a negative errno value.
|
||||
/* change_or_errno can be either one of the INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, … listed above, or
|
||||
* a negative errno value.
|
||||
*
|
||||
* If source is specified, it should be the contents of the path symlink. In case of an error, source should
|
||||
* be the existing symlink contents or NULL. */
|
||||
struct InstallChange {
|
||||
int type_or_errno; /* UNIT_FILE_SYMLINK, … if positive, errno if negative */
|
||||
int change_or_errno; /* INSTALL_CHANGE_SYMLINK, … if positive, errno if negative */
|
||||
char *path;
|
||||
char *source;
|
||||
};
|
||||
|
||||
static inline bool install_changes_have_modification(const InstallChange* changes, size_t n_changes) {
|
||||
for (size_t i = 0; i < n_changes; i++)
|
||||
if (IN_SET(changes[i].type_or_errno, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK))
|
||||
if (IN_SET(changes[i].change_or_errno, INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -217,8 +219,8 @@ const char *unit_file_state_to_string(UnitFileState s) _const_;
|
||||
UnitFileState unit_file_state_from_string(const char *s) _pure_;
|
||||
/* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
|
||||
|
||||
const char *unit_file_change_type_to_string(int s) _const_;
|
||||
int unit_file_change_type_from_string(const char *s) _pure_;
|
||||
const char *install_change_to_string(int s) _const_;
|
||||
int install_change_from_string(const char *s) _pure_;
|
||||
|
||||
const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
|
||||
UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;
|
||||
|
||||
Reference in New Issue
Block a user