summaryrefslogtreecommitdiff
path: root/src/shared/install.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-17 10:38:12 +0100
committerLennart Poettering <lennart@poettering.net>2021-02-17 19:29:24 +0100
commit93419a9601a0874a8304d0b6fe11a2f5c40c48b6 (patch)
treee3e6c6656c29ba04599082831d89f6d0ea23e07a /src/shared/install.h
parent0761da386a6cb0ced3721f2dee123fd983c71178 (diff)
downloadsystemd-93419a9601a0874a8304d0b6fe11a2f5c40c48b6.tar.gz
install: make UnitFileChangeType enum anonymous
We almost never use the named enum type, in almost all cases we use "int" instead, since we overload it with negative errnos. To simplify things, let's use "int" really everywhere. Moreover, let's rename the fields for this enum to "type_or_errno", to make the overloading clear. And let's ad some assertions that things are in the right range.
Diffstat (limited to 'src/shared/install.h')
-rw-r--r--src/shared/install.h22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/shared/install.h b/src/shared/install.h
index 232184de33..305e4f74b8 100644
--- a/src/shared/install.h
+++ b/src/shared/install.h
@@ -25,7 +25,9 @@ enum UnitFilePresetMode {
_UNIT_FILE_PRESET_INVALID = -EINVAL,
};
-enum UnitFileChangeType {
+/* 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,
@@ -42,20 +44,18 @@ enum UnitFileFlags {
_UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE,
};
-/* type can either one of the UnitFileChangeTypes listed above, or a negative error.
- * 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
- */
+/* type can either one of the UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK, … listed above, or a negative errno value.
+ * If source is specified, it should be the contents of the path symlink. In case of an error, source should
+ * be the existing symlink contents or NULL. */
struct UnitFileChange {
- int type; /* UnitFileChangeType or bust */
+ int type_or_errno; /* UNIT_FILE_SYMLINK, … if positive, errno if negative */
char *path;
char *source;
};
static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) {
- size_t i;
- for (i = 0; i < n_changes; i++)
- if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK))
+ for (size_t i = 0; i < n_changes; i++)
+ if (IN_SET(changes[i].type_or_errno, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK))
return true;
return false;
}
@@ -206,8 +206,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(UnitFileChangeType s) _const_;
-UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_;
+const char *unit_file_change_type_to_string(int s) _const_;
+int unit_file_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_;