]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use 'Architecture' type consistently across the tree
authorLennart Poettering <lennart@poettering.net>
Mon, 4 Apr 2022 10:46:03 +0000 (12:46 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 4 Apr 2022 17:19:37 +0000 (02:19 +0900)
Some parts of our tree used 'Architecture' for storing architectures,
others used ints. Let's unify on the former.

Inspired by #22952's rework of the 'Virtualization' enum.

src/basic/architecture.c
src/basic/architecture.h
src/basic/process-util.c
src/shared/condition.c
src/shared/dissect-image.c
src/shared/dissect-image.h
src/test/test-architecture.c
src/test/test-condition.c
src/test/test-gpt.c

index f474ed29544dc0265e7c6cfd4df121719b0ec6ca..773ee3c50898973d0b0255c4da7bfed164ba1463 100644 (file)
@@ -7,7 +7,7 @@
 #include "string-table.h"
 #include "string-util.h"
 
-int uname_architecture(void) {
+Architecture uname_architecture(void) {
 
         /* Return a sanitized enum identifying the architecture we are running on. This
          * is based on uname(), and the user may hence control what this returns by using
@@ -22,7 +22,7 @@ int uname_architecture(void) {
 
         static const struct {
                 const char *machine;
-                int arch;
+                Architecture arch;
         } arch_map[] = {
 #if defined(__aarch64__) || defined(__arm__)
                 { "aarch64",    ARCHITECTURE_ARM64    },
@@ -122,7 +122,7 @@ int uname_architecture(void) {
 #endif
         };
 
-        static int cached = _ARCHITECTURE_INVALID;
+        static Architecture cached = _ARCHITECTURE_INVALID;
         struct utsname u;
 
         if (cached != _ARCHITECTURE_INVALID)
@@ -175,4 +175,4 @@ static const char *const architecture_table[_ARCHITECTURE_MAX] = {
         [ARCHITECTURE_TILEGX]      = "tilegx",
 };
 
-DEFINE_STRING_TABLE_LOOKUP(architecture, int);
+DEFINE_STRING_TABLE_LOOKUP(architecture, Architecture);
index cb4c79b84eb0217cc9093f1de5681e8efdf9045d..b86f5f35d0f777b96f8209913a3a8d444dab27c9 100644 (file)
@@ -48,7 +48,7 @@ typedef enum {
         _ARCHITECTURE_INVALID = -EINVAL,
 } Architecture;
 
-int uname_architecture(void);
+Architecture uname_architecture(void);
 
 /*
  * LIB_ARCH_TUPLE should resolve to the local library path
@@ -243,5 +243,5 @@ int uname_architecture(void);
 #  error "Please register your architecture here!"
 #endif
 
-const char *architecture_to_string(int a) _const_;
-int architecture_from_string(const char *s) _pure_;
+const char *architecture_to_string(Architecture a) _const_;
+Architecture architecture_from_string(const char *s) _pure_;
index 204a5d949011aa9eec5c635803d4d7ebb2de199d..6980e0c4f695023670b9db8f14390e9bff244c9e 100644 (file)
@@ -1026,7 +1026,7 @@ bool oom_score_adjust_is_valid(int oa) {
 }
 
 unsigned long personality_from_string(const char *p) {
-        int architecture;
+        Architecture architecture;
 
         if (!p)
                 return PERSONALITY_INVALID;
@@ -1050,7 +1050,7 @@ unsigned long personality_from_string(const char *p) {
 }
 
 const char* personality_to_string(unsigned long p) {
-        int architecture = _ARCHITECTURE_INVALID;
+        Architecture architecture = _ARCHITECTURE_INVALID;
 
         if (p == PER_LINUX)
                 architecture = native_architecture();
index ea334bfeb75ffc55e6c2749c000587ce4102a930..be09b852db23b9a0ec9d89d95dec8ba3c6206658 100644 (file)
@@ -490,7 +490,7 @@ static int condition_test_virtualization(Condition *c, char **env) {
 }
 
 static int condition_test_architecture(Condition *c, char **env) {
-        int a, b;
+        Architecture a, b;
 
         assert(c);
         assert(c->parameter);
index f4756bf8c589d09e94836170d09f163e470ae5c9..e63b168c24a320466f1c93d679d21b58c62c6988 100644 (file)
@@ -612,7 +612,7 @@ static void dissected_partition_done(DissectedPartition *p) {
 
         *p = (DissectedPartition) {
                 .partno = -1,
-                .architecture = -1
+                .architecture = _ARCHITECTURE_INVALID,
         };
 }
 
@@ -917,7 +917,7 @@ int dissect_image(
 
                 if (is_gpt) {
                         PartitionDesignator designator = _PARTITION_DESIGNATOR_INVALID;
-                        int architecture = _ARCHITECTURE_INVALID;
+                        Architecture architecture = _ARCHITECTURE_INVALID;
                         const char *stype, *sid, *fstype = NULL, *label;
                         sd_id128_t type_id, id;
                         bool rw = true, growfs = false;
index 032126627ca83416de1fe8ae6ef5145f854eb740..b74adf5f8de47f5df049bac59609213c70fed0ee 100644 (file)
@@ -20,9 +20,9 @@ struct DissectedPartition {
         bool found:1;
         bool rw:1;
         bool growfs:1;
-        int partno;        /* -1 if there was no partition and the images contains a file system directly */
-        int architecture;  /* Intended architecture: either native, secondary or unset (-1). */
-        sd_id128_t uuid;   /* Partition entry UUID as reported by the GPT */
+        int partno;                 /* -1 if there was no partition and the images contains a file system directly */
+        Architecture architecture;  /* Intended architecture: either native, secondary or unset ARCHITECTURE_INVALID. */
+        sd_id128_t uuid;            /* Partition entry UUID as reported by the GPT */
         char *fstype;
         char *node;
         char *label;
index 6455e5c2fa7e0e5276c9963b55597aa0166ac8ca..b542fe1ddf1c00a3dfa2b0acef92c3448d63c168 100644 (file)
@@ -9,8 +9,8 @@
 
 int main(int argc, char *argv[]) {
         Virtualization v;
+        Architecture a;
         const char *p;
-        int a;
 
         test_setup_logging(LOG_INFO);
 
index c872a6c2b9dd80a12ed32b41c803e893ef53fe8e..a637a490ece35295827ed8abf66254fc4ecdf27c 100644 (file)
@@ -276,7 +276,7 @@ TEST(condition_test_host) {
 TEST(condition_test_architecture) {
         Condition *condition;
         const char *sa;
-        int a;
+        Architecture a;
 
         a = uname_architecture();
         assert_se(a >= 0);
index 05da7a9e4854d529ebed8b191168583b1fe4d893..5037f498bb30f88ac955ae6c7e1ab5f3791c116d 100644 (file)
@@ -17,7 +17,7 @@ TEST(gpt_types_against_architectures) {
          * types. Also validates whether we can properly categorize the entries. */
 
         FOREACH_STRING(prefix, "root-", "usr-")
-                for (int a = 0; a < _ARCHITECTURE_MAX; a++)
+                for (Architecture a = 0; a < _ARCHITECTURE_MAX; a++)
                         FOREACH_STRING(suffix, "", "-verity", "-verity-sig") {
                                 _cleanup_free_ char *joined = NULL;
                                 sd_id128_t id;