summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/dbus-manager.c16
-rw-r--r--src/shared/bus-unit-util.c14
-rw-r--r--src/shared/install.c46
-rw-r--r--src/shared/install.h23
-rw-r--r--src/systemctl/systemctl-is-enabled.c2
-rw-r--r--src/test/test-install-root.c98
-rw-r--r--src/test/test-install.c4
-rw-r--r--src/test/test-tables.c2
8 files changed, 103 insertions, 102 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 240408f342..fee2e56b62 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -2134,10 +2134,10 @@ static int install_error(
for (size_t i = 0; i < n_changes; i++)
- switch (changes[i].change_or_errno) {
+ switch (changes[i].type) {
- case 0 ... _INSTALL_CHANGE_MAX: /* not errors */
- continue;
+ case 0 ... _INSTALL_CHANGE_TYPE_MAX: /* not errors */
+ break;
case -EEXIST:
if (changes[i].source)
@@ -2178,8 +2178,8 @@ static int install_error(
goto found;
default:
- 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);
+ assert(changes[i].type < 0); /* other errors */
+ r = sd_bus_error_set_errnof(error, changes[i].type, "File %s: %m", changes[i].path);
goto found;
}
@@ -2224,14 +2224,14 @@ static int reply_install_changes_and_free(
for (size_t i = 0; i < n_changes; i++) {
- if (changes[i].change_or_errno < 0) {
+ if (changes[i].type < 0) {
bad = true;
continue;
}
r = sd_bus_message_append(
reply, "(sss)",
- install_change_to_string(changes[i].change_or_errno),
+ install_change_type_to_string(changes[i].type),
changes[i].path,
changes[i].source);
if (r < 0)
@@ -2610,7 +2610,7 @@ static int method_get_unit_file_links(sd_bus_message *message, void *userdata, s
return log_error_errno(r, "Failed to get file links for %s: %m", name);
for (i = 0; i < n_changes; i++)
- if (changes[i].change_or_errno == INSTALL_CHANGE_UNLINK) {
+ if (changes[i].type == INSTALL_CHANGE_UNLINK) {
r = sd_bus_message_append(reply, "s", changes[i].path);
if (r < 0)
return r;
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index 2962126b0f..b850a28e85 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -2682,16 +2682,18 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, In
return bus_log_parse_error(r);
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 = install_change_from_string(type);
- if (ch < 0) {
- log_notice_errno(ch, "Manager reported unknown change type \"%s\" for path \"%s\", ignoring.",
+ InstallChangeType t;
+
+ /* We expect only "success" changes to be sent over the bus. Hence, reject anything
+ * negative. */
+ t = install_change_type_from_string(type);
+ if (t < 0) {
+ log_notice_errno(t, "Manager reported unknown change type \"%s\" for path \"%s\", ignoring.",
type, path);
continue;
}
- r = install_changes_add(changes, n_changes, ch, path, source);
+ r = install_changes_add(changes, n_changes, t, path, source);
if (r < 0)
return r;
}
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",
diff --git a/src/shared/install.h b/src/shared/install.h
index 1c910e8752..302b52733a 100644
--- a/src/shared/install.h
+++ b/src/shared/install.h
@@ -26,9 +26,7 @@ enum UnitFilePresetMode {
_UNIT_FILE_PRESET_INVALID = -EINVAL,
};
-/* This enum type is anonymous, since we usually store it in an 'int', as we overload it with negative errno
- * values. */
-enum {
+enum InstallChangeType {
INSTALL_CHANGE_SYMLINK,
INSTALL_CHANGE_UNLINK,
INSTALL_CHANGE_IS_MASKED,
@@ -36,10 +34,15 @@ enum {
INSTALL_CHANGE_IS_DANGLING,
INSTALL_CHANGE_DESTINATION_NOT_PRESENT,
INSTALL_CHANGE_AUXILIARY_FAILED,
- _INSTALL_CHANGE_MAX,
+ _INSTALL_CHANGE_TYPE_MAX,
_INSTALL_CHANGE_INVALID = -EINVAL,
+ _INSTALL_CHANGE_ERRNO_MAX = -ERRNO_MAX, /* Ensure this type covers the whole negative errno range */
};
+static inline bool INSTALL_CHANGE_TYPE_VALID(InstallChangeType t) {
+ return t >= _INSTALL_CHANGE_ERRNO_MAX && t < _INSTALL_CHANGE_TYPE_MAX;
+}
+
enum UnitFileFlags {
UNIT_FILE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */
UNIT_FILE_FORCE = 1 << 1, /* Public API via DBUS, do not change */
@@ -49,20 +52,20 @@ enum UnitFileFlags {
_UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE,
};
-/* change_or_errno can be either one of the INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, … listed above, or
- * a negative errno value.
+/* type 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 change_or_errno; /* INSTALL_CHANGE_SYMLINK, … if positive, errno if negative */
+ int type; /* 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].change_or_errno, INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK))
+ if (IN_SET(changes[i].type, INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK))
return true;
return false;
}
@@ -220,8 +223,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 *install_change_to_string(int s) _const_;
-int install_change_from_string(const char *s) _pure_;
+const char *install_change_type_to_string(InstallChangeType t) _const_;
+int install_change_type_from_string(const char *s) _pure_;
const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;
diff --git a/src/systemctl/systemctl-is-enabled.c b/src/systemctl/systemctl-is-enabled.c
index 91231fa9d9..2d33313eb8 100644
--- a/src/systemctl/systemctl-is-enabled.c
+++ b/src/systemctl/systemctl-is-enabled.c
@@ -23,7 +23,7 @@ static int show_installation_targets_client_side(const char *name) {
return log_error_errno(r, "Failed to get file links for %s: %m", name);
for (size_t i = 0; i < n_changes; i++)
- if (changes[i].change_or_errno == INSTALL_CHANGE_UNLINK)
+ if (changes[i].type == INSTALL_CHANGE_UNLINK)
printf(" %s\n", changes[i].path);
return 0;
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
index 8749df2c70..2868ab07b2 100644
--- a/src/test/test-install-root.c
+++ b/src/test/test-install-root.c
@@ -59,7 +59,7 @@ TEST(basic_mask_and_enable) {
assert_se(unit_file_mask(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/dev/null"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service");
assert_se(streq(changes[0].path, p));
@@ -79,7 +79,7 @@ TEST(basic_mask_and_enable) {
assert_se(unit_file_unmask(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service");
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
@@ -87,7 +87,7 @@ TEST(basic_mask_and_enable) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) == 1);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service");
assert_se(streq(changes[0].path, p));
@@ -107,7 +107,7 @@ TEST(basic_mask_and_enable) {
assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service");
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
@@ -127,7 +127,7 @@ TEST(basic_mask_and_enable) {
/* Let's enable this indirectly via a symlink */
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("d.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service");
assert_se(streq(changes[0].path, p));
@@ -143,10 +143,10 @@ TEST(basic_mask_and_enable) {
assert_se(unit_file_reenable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("b.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == 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].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[1].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/a.service"));
assert_se(streq(changes[1].path, p));
install_changes_free(changes, n_changes);
@@ -185,11 +185,11 @@ TEST(basic_mask_and_enable) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("f.service"), &changes, &n_changes) == 1);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == 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].change_or_errno == INSTALL_CHANGE_DESTINATION_NOT_PRESENT);
+ assert_se(changes[1].type == INSTALL_CHANGE_DESTINATION_NOT_PRESENT);
p = strjoina(root, "/usr/lib/systemd/system/f.service");
assert_se(streq(changes[1].source, p));
assert_se(streq(changes[1].path, "x.target"));
@@ -253,7 +253,7 @@ TEST(linked_units) {
/* First, let's link the unit into the search path */
assert_se(unit_file_link(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("/opt/linked.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/opt/linked.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
assert_se(streq(changes[0].path, p));
@@ -265,7 +265,7 @@ TEST(linked_units) {
/* Let's unlink it from the search path again */
assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
@@ -279,7 +279,7 @@ TEST(linked_units) {
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service");
q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
for (i = 0 ; i < n_changes; i++) {
- assert_se(changes[i].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[i].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[i].source, "/opt/linked.service"));
if (p && streq(changes[i].path, p))
@@ -301,7 +301,7 @@ TEST(linked_units) {
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service");
q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service");
for (i = 0; i < n_changes; i++) {
- assert_se(changes[i].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[i].type == INSTALL_CHANGE_UNLINK);
if (p && streq(changes[i].path, p))
p = NULL;
@@ -321,7 +321,7 @@ TEST(linked_units) {
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked2.service");
q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked2.service");
for (i = 0 ; i < n_changes; i++) {
- assert_se(changes[i].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[i].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[i].source, "/opt/linked2.service"));
if (p && streq(changes[i].path, p))
@@ -337,7 +337,7 @@ TEST(linked_units) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("linked3.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(startswith(changes[0].path, root));
assert_se(endswith(changes[0].path, "linked3.service"));
assert_se(streq(changes[0].source, "/opt/linked3.service"));
@@ -361,7 +361,7 @@ TEST(default) {
assert_se(unit_file_set_default(LOOKUP_SCOPE_SYSTEM, 0, root, "idontexist.target", &changes, &n_changes) == -ENOENT);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == -ENOENT);
+ assert_se(changes[0].type == -ENOENT);
assert_se(streq_ptr(changes[0].path, "idontexist.target"));
install_changes_free(changes, n_changes);
changes = NULL; n_changes = 0;
@@ -370,7 +370,7 @@ TEST(default) {
assert_se(unit_file_set_default(LOOKUP_SCOPE_SYSTEM, 0, root, "test-default.target", &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR "/" SPECIAL_DEFAULT_TARGET);
assert_se(streq(changes[0].path, p));
@@ -400,7 +400,7 @@ TEST(add_dependency) {
assert_se(unit_file_add_dependency(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("add-dependency-test-service.service"), "add-dependency-test-target.target", UNIT_WANTS, &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service");
assert_se(streq(changes[0].path, p));
@@ -441,7 +441,7 @@ TEST(template_enable) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template@.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@def.service");
assert_se(streq(changes[0].path, p));
@@ -457,7 +457,7 @@ TEST(template_enable) {
assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template@.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
changes = NULL; n_changes = 0;
@@ -472,7 +472,7 @@ TEST(template_enable) {
log_info("== %s with template@foo.service enabled ==", __func__);
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template@foo.service"), &changes, &n_changes) >= 0);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@foo.service");
assert_se(streq(changes[0].path, p));
@@ -488,7 +488,7 @@ TEST(template_enable) {
assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template@foo.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
changes = NULL; n_changes = 0;
@@ -505,7 +505,7 @@ TEST(template_enable) {
log_info("== %s with template-symlink@quux.service enabled ==", __func__);
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("template-symlink@quux.service"), &changes, &n_changes) >= 0);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@quux.service");
assert_se(streq(changes[0].path, p));
@@ -551,7 +551,7 @@ TEST(indirect) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service");
assert_se(streq(changes[0].path, p));
@@ -564,7 +564,7 @@ TEST(indirect) {
assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service");
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
@@ -603,7 +603,7 @@ TEST(preset_and_list) {
assert_se(unit_file_preset(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("preset-yes.service"), UNIT_FILE_PRESET_FULL, &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/preset-yes.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service");
assert_se(streq(changes[0].path, p));
@@ -615,7 +615,7 @@ TEST(preset_and_list) {
assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("preset-yes.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service");
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
@@ -640,11 +640,11 @@ TEST(preset_and_list) {
for (i = 0; i < n_changes; i++) {
- if (changes[i].change_or_errno == INSTALL_CHANGE_SYMLINK) {
+ if (changes[i].type == 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].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[i].type == INSTALL_CHANGE_UNLINK);
}
install_changes_free(changes, n_changes);
@@ -705,7 +705,7 @@ TEST(revert) {
/* Revert the override file */
assert_se(unit_file_revert(LOOKUP_SCOPE_SYSTEM, root, STRV_MAKE("xx.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
changes = NULL; n_changes = 0;
@@ -716,11 +716,11 @@ TEST(revert) {
/* Revert the dropin file */
assert_se(unit_file_revert(LOOKUP_SCOPE_SYSTEM, root, STRV_MAKE("xx.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
assert_se(streq(changes[0].path, p));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service.d");
- assert_se(changes[1].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[1].type == INSTALL_CHANGE_UNLINK);
assert_se(streq(changes[1].path, p));
install_changes_free(changes, n_changes);
changes = NULL; n_changes = 0;
@@ -756,7 +756,7 @@ TEST(preset_order) {
assert_se(unit_file_preset(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("prefix-1.service"), UNIT_FILE_PRESET_FULL, &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/prefix-1.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/prefix-1.service");
assert_se(streq(changes[0].path, p));
@@ -864,8 +864,8 @@ TEST(with_dropin) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-1.service"), &changes, &n_changes) == 1);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
- assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[1].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1.service"));
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-1.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-1.service");
@@ -878,8 +878,8 @@ TEST(with_dropin) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2.service"), &changes, &n_changes) == 1);
assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-2.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
- assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[1].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service"));
assert_se(streq(changes[1].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2.service");
@@ -892,8 +892,8 @@ TEST(with_dropin) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-3.service"), &changes, &n_changes) == 1);
assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-3.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
- assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[1].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3.service"));
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-3.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3.service");
@@ -906,8 +906,8 @@ TEST(with_dropin) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-4a.service"), &changes, &n_changes) == 2);
assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "with-dropin-3.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
- assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[1].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-4a.service"));
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-4b.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-4a.service");
@@ -973,8 +973,8 @@ TEST(with_dropin_template) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-1@instance-1.service"), &changes, &n_changes) == 1);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
- assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[1].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1@.service"));
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-1@.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-1@instance-1.service");
@@ -986,8 +986,8 @@ TEST(with_dropin_template) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2@instance-1.service"), &changes, &n_changes) == 1);
assert_se(n_changes == 2);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
- assert_se(changes[1].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[1].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service"));
assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-2@.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-1.service");
@@ -999,7 +999,7 @@ TEST(with_dropin_template) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-2@instance-2.service"), &changes, &n_changes) == 1);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-2.service");
assert_se(streq(changes[0].path, p));
@@ -1008,7 +1008,7 @@ TEST(with_dropin_template) {
assert_se(unit_file_enable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("with-dropin-3@.service"), &changes, &n_changes) == 1);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3@.service"));
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3@instance-2.service");
assert_se(streq(changes[0].path, p));
@@ -1049,7 +1049,7 @@ TEST(preset_multiple_instances) {
assert_se(unit_file_preset(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("foo@bar0.service"), UNIT_FILE_PRESET_FULL, &changes, &n_changes) >= 0);
assert_se(unit_file_get_state(LOOKUP_SCOPE_SYSTEM, root, "foo@bar0.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_SYMLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_SYMLINK);
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service");
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
@@ -1057,7 +1057,7 @@ TEST(preset_multiple_instances) {
assert_se(unit_file_disable(LOOKUP_SCOPE_SYSTEM, 0, root, STRV_MAKE("foo@bar0.service"), &changes, &n_changes) >= 0);
assert_se(n_changes == 1);
- assert_se(changes[0].change_or_errno == INSTALL_CHANGE_UNLINK);
+ assert_se(changes[0].type == INSTALL_CHANGE_UNLINK);
p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service");
assert_se(streq(changes[0].path, p));
install_changes_free(changes, n_changes);
diff --git a/src/test/test-install.c b/src/test/test-install.c
index 309b18c535..c9b08d7b6a 100644
--- a/src/test/test-install.c
+++ b/src/test/test-install.c
@@ -12,9 +12,9 @@ static void dump_changes(InstallChange *c, unsigned n) {
assert_se(n == 0 || c);
for (i = 0; i < n; i++) {
- if (c[i].change_or_errno == INSTALL_CHANGE_UNLINK)
+ if (c[i].type == INSTALL_CHANGE_UNLINK)
printf("rm '%s'\n", c[i].path);
- else if (c[i].change_or_errno == INSTALL_CHANGE_SYMLINK)
+ else if (c[i].type == INSTALL_CHANGE_SYMLINK)
printf("ln -s '%s' '%s'\n", c[i].source, c[i].path);
}
}
diff --git a/src/test/test-tables.c b/src/test/test-tables.c
index cac21f3984..36965b334b 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(install_change, INSTALL_CHANGE);
+ test_table(install_change_type, INSTALL_CHANGE_TYPE);
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);