]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
portable: make PortableChangeType enum anonymous 18651/head
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Feb 2021 09:47:30 +0000 (10:47 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 Feb 2021 18:29:24 +0000 (19:29 +0100)
Same reasons as previous commit.

src/portable/portable.c
src/portable/portable.h
src/portable/portabled-bus.c
src/portable/portabled-image-bus.c

index 0a3b1e8fde63d299306adb65fc8fa8da2ff29720..6c09e8bbd4f61eea68e54e69d272bf3434dbe7ad 100644 (file)
@@ -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",
index 291d9377ef01041c87d3968695483cf8894701d4..5694bd2b623eaf36f2b82ef730abdad2ecae484a 100644 (file)
@@ -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_;
index fa143b71c0f8f251bbcac8b7bd5ef21149bf3663..8de8bfc247c4ef673dc1c2fc10780110bf883e5b 100644 (file)
@@ -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)
index 75bb4d80c16384a60f6aed2f94263d671c3984ff..018cc9b818ad7633e602f50ef6bf3b2df335abdd 100644 (file)
@@ -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),
                         };