summaryrefslogtreecommitdiff
path: root/src/shared/install.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-10-14 11:11:53 +0200
committerLennart Poettering <lennart@poettering.net>2022-10-14 11:40:40 +0200
commitf8662fee2fac735385dc060f1435e4af5327138d (patch)
treef2d3c0599cc6fcd7bb095d38921be106ed593031 /src/shared/install.c
parent4554c178bf07ded86f9f3982f26e87afd1caf0f4 (diff)
downloadsystemd-f8662fee2fac735385dc060f1435e4af5327138d.tar.gz
install: make InstallChange enum type a proper type
We can just make this an enum, as long as we ensure it has enough range, which we can do by adding -ERRNO_MAX as one possible value (at least on GNU C). We already do that at multiple other places, so let's do this here too.
Diffstat (limited to 'src/shared/install.c')
-rw-r--r--src/shared/install.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index e45ad01092..43aa865b0e 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -268,7 +268,7 @@ static const char* config_path_from_flags(const LookupPaths *lp, UnitFileFlags f
int install_changes_add(
InstallChange **changes,
size_t *n_changes,
- int change_or_errno, /* INSTALL_CHANGE_SYMLINK, _UNLINK, _IS_MASKED, _IS_DANGLING, … if positive or errno if negative */
+ InstallChangeType type, /* INSTALL_CHANGE_SYMLINK, _UNLINK, _IS_MASKED, _IS_DANGLING, … if positive or errno if negative */
const char *path,
const char *source) {
@@ -276,11 +276,7 @@ int install_changes_add(
InstallChange *c;
assert(!changes == !n_changes);
-
- if (change_or_errno >= 0)
- assert(change_or_errno < _INSTALL_CHANGE_MAX);
- else
- assert(change_or_errno >= -ERRNO_MAX);
+ assert(INSTALL_CHANGE_TYPE_VALID(type));
if (!changes)
return 0;
@@ -307,7 +303,7 @@ int install_changes_add(
}
c[(*n_changes)++] = (InstallChange) {
- .change_or_errno = change_or_errno,
+ .type = type,
.path = TAKE_PTR(p),
.source = TAKE_PTR(s),
};
@@ -334,9 +330,9 @@ 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].change_or_errno >= 0);
+ assert(verb || changes[i].type >= 0);
- switch (changes[i].change_or_errno) {
+ switch (changes[i].type) {
case INSTALL_CHANGE_SYMLINK:
if (!quiet)
log_info("Created symlink %s %s %s.",
@@ -373,58 +369,58 @@ void install_changes_dump(int r, const char *verb, const InstallChange *changes,
break;
case -EEXIST:
if (changes[i].source)
- err = log_error_errno(changes[i].change_or_errno,
+ err = log_error_errno(changes[i].type,
"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].change_or_errno,
+ err = log_error_errno(changes[i].type,
"Failed to %s unit, file \"%s\" already exists.",
verb, changes[i].path);
break;
case -ERFKILL:
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s is masked.",
+ err = log_error_errno(changes[i].type, "Failed to %s unit, unit %s is masked.",
verb, changes[i].path);
break;
case -EADDRNOTAVAIL:
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s is transient or generated.",
+ err = log_error_errno(changes[i].type, "Failed to %s unit, unit %s is transient or generated.",
verb, changes[i].path);
break;
case -EBADSLT:
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, invalid specifier in \"%s\".",
+ err = log_error_errno(changes[i].type, "Failed to %s unit, invalid specifier in \"%s\".",
verb, changes[i].path);
break;
case -EIDRM:
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s %s, destination unit %s is a non-template unit.",
+ err = log_error_errno(changes[i].type, "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].change_or_errno,
+ err = log_error_errno(changes[i].type,
"Failed to %s unit, \"%s\" is not a valid unit name.",
verb, changes[i].path);
break;
case -ELOOP:
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, refusing to operate on linked unit file %s.",
+ err = log_error_errno(changes[i].type, "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].change_or_errno, "Failed to %s unit, cannot alias %s as %s.",
+ err = log_error_errno(changes[i].type, "Failed to %s unit, cannot alias %s as %s.",
verb, changes[i].source, changes[i].path);
else
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, invalid unit reference \"%s\".",
+ err = log_error_errno(changes[i].type, "Failed to %s unit, invalid unit reference \"%s\".",
verb, changes[i].path);
break;
case -ENOENT:
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, unit %s does not exist.",
+ err = log_error_errno(changes[i].type, "Failed to %s unit, unit %s does not exist.",
verb, changes[i].path);
break;
case -EUNATCH:
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, cannot resolve specifiers in \"%s\".",
+ err = log_error_errno(changes[i].type, "Failed to %s unit, cannot resolve specifiers in \"%s\".",
verb, changes[i].path);
break;
default:
- assert(changes[i].change_or_errno < 0);
- err = log_error_errno(changes[i].change_or_errno, "Failed to %s unit, file \"%s\": %m",
+ assert(changes[i].type < 0);
+ err = log_error_errno(changes[i].type, "Failed to %s unit, file \"%s\": %m",
verb, changes[i].path);
}
}
@@ -3666,7 +3662,7 @@ static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState);
-static const char* const install_change_table[_INSTALL_CHANGE_MAX] = {
+static const char* const install_change_type_table[_INSTALL_CHANGE_TYPE_MAX] = {
[INSTALL_CHANGE_SYMLINK] = "symlink",
[INSTALL_CHANGE_UNLINK] = "unlink",
[INSTALL_CHANGE_IS_MASKED] = "masked",
@@ -3676,7 +3672,7 @@ static const char* const install_change_table[_INSTALL_CHANGE_MAX] = {
[INSTALL_CHANGE_AUXILIARY_FAILED] = "auxiliary unit failed",
};
-DEFINE_STRING_TABLE_LOOKUP(install_change, int);
+DEFINE_STRING_TABLE_LOOKUP(install_change_type, InstallChangeType);
static const char* const unit_file_preset_mode_table[_UNIT_FILE_PRESET_MAX] = {
[UNIT_FILE_PRESET_FULL] = "full",