From: Lennart Poettering Date: Wed, 17 Feb 2021 09:47:30 +0000 (+0100) Subject: portable: make PortableChangeType enum anonymous X-Git-Tag: v248-rc1~69^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F18651%2Fhead;p=thirdparty%2Fsystemd.git portable: make PortableChangeType enum anonymous Same reasons as previous commit. --- diff --git a/src/portable/portable.c b/src/portable/portable.c index 0a3b1e8fde6..6c09e8bbd4f 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -10,6 +10,7 @@ #include "dirent-util.h" #include "discover-image.h" #include "dissect-image.h" +#include "errno-list.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -591,7 +592,7 @@ static int unit_file_is_active( static int portable_changes_add( PortableChange **changes, size_t *n_changes, - PortableChangeType type, + int type_or_errno, /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, or errno if negative */ const char *path, const char *source) { @@ -601,6 +602,11 @@ static int portable_changes_add( assert(path); assert(!changes == !n_changes); + if (type_or_errno >= 0) + assert(type_or_errno < _PORTABLE_CHANGE_TYPE_MAX); + else + assert(type_or_errno >= -ERRNO_MAX); + if (!changes) return 0; @@ -624,7 +630,7 @@ static int portable_changes_add( } c[(*n_changes)++] = (PortableChange) { - .type = type, + .type_or_errno = type_or_errno, .path = TAKE_PTR(p), .source = TAKE_PTR(s), }; @@ -635,7 +641,7 @@ static int portable_changes_add( static int portable_changes_add_with_prefix( PortableChange **changes, size_t *n_changes, - PortableChangeType type, + int type_or_errno, const char *prefix, const char *path, const char *source) { @@ -653,7 +659,7 @@ static int portable_changes_add_with_prefix( source = prefix_roota(prefix, source); } - return portable_changes_add(changes, n_changes, type, path, source); + return portable_changes_add(changes, n_changes, type_or_errno, path, source); } void portable_changes_free(PortableChange *changes, size_t n_changes) { @@ -1417,7 +1423,7 @@ static const char* const portable_change_type_table[_PORTABLE_CHANGE_TYPE_MAX] = [PORTABLE_WRITE] = "write", }; -DEFINE_STRING_TABLE_LOOKUP(portable_change_type, PortableChangeType); +DEFINE_STRING_TABLE_LOOKUP(portable_change_type, int); static const char* const portable_state_table[_PORTABLE_STATE_MAX] = { [PORTABLE_DETACHED] = "detached", diff --git a/src/portable/portable.h b/src/portable/portable.h index 291d9377ef0..5694bd2b623 100644 --- a/src/portable/portable.h +++ b/src/portable/portable.h @@ -24,7 +24,9 @@ typedef enum PortableFlags { PORTABLE_REATTACH = 1 << 3, } PortableFlags; -typedef enum PortableChangeType { +/* This enum is anonymous, since we usually store it in an 'int', as we overload it with negative errno + * values. */ +enum { PORTABLE_COPY, PORTABLE_SYMLINK, PORTABLE_UNLINK, @@ -32,7 +34,7 @@ typedef enum PortableChangeType { PORTABLE_MKDIR, _PORTABLE_CHANGE_TYPE_MAX, _PORTABLE_CHANGE_TYPE_INVALID = -EINVAL, -} PortableChangeType; +}; typedef enum PortableState { PORTABLE_DETACHED, @@ -47,7 +49,7 @@ typedef enum PortableState { } PortableState; typedef struct PortableChange { - int type; /* PortableFileChangeType or negative error number */ + int type_or_errno; /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, errno if negative */ char *path; char *source; } PortableChange; @@ -68,8 +70,8 @@ int portable_get_profiles(char ***ret); void portable_changes_free(PortableChange *changes, size_t n_changes); -const char *portable_change_type_to_string(PortableChangeType t) _const_; -PortableChangeType portable_change_type_from_string(const char *t) _pure_; +const char *portable_change_type_to_string(int t) _const_; +int portable_change_type_from_string(const char *t) _pure_; const char *portable_state_to_string(PortableState t) _const_; PortableState portable_state_from_string(const char *t) _pure_; diff --git a/src/portable/portabled-bus.c b/src/portable/portabled-bus.c index fa143b71c0f..8de8bfc247c 100644 --- a/src/portable/portabled-bus.c +++ b/src/portable/portabled-bus.c @@ -457,8 +457,11 @@ static int reply_portable_compose_message(sd_bus_message *reply, const PortableC return r; for (i = 0; i < n_changes; i++) { + if (changes[i].type_or_errno < 0) + continue; + r = sd_bus_message_append(reply, "(sss)", - portable_change_type_to_string(changes[i].type), + portable_change_type_to_string(changes[i].type_or_errno), changes[i].path, changes[i].source); if (r < 0) diff --git a/src/portable/portabled-image-bus.c b/src/portable/portabled-image-bus.c index 75bb4d80c16..018cc9b818a 100644 --- a/src/portable/portabled-image-bus.c +++ b/src/portable/portabled-image-bus.c @@ -483,7 +483,7 @@ static int normalize_portable_changes( } changes[n_changes++] = (PortableChange) { - .type = changes_detached[i].type, + .type_or_errno = changes_detached[i].type_or_errno, .path = TAKE_PTR(path), .source = TAKE_PTR(source), };