diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-02-22 18:29:05 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-02-22 23:23:06 +0100 |
commit | 0c0fea07b8da1ef31521658e5764267218da2f13 (patch) | |
tree | 5fada930446a8c62ac66623f8352398dc6d5b74b /src | |
parent | d5b687e7c25bb5cc2d516bcdbd3b093749cbd337 (diff) |
util-lib: simplify personality() string matching
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/architecture.h | 4 | ||||
-rw-r--r-- | src/basic/process-util.c | 113 |
2 files changed, 13 insertions, 104 deletions
diff --git a/src/basic/architecture.h b/src/basic/architecture.h index 26679e28c6..63cf6fb703 100644 --- a/src/basic/architecture.h +++ b/src/basic/architecture.h @@ -78,6 +78,7 @@ int uname_architecture(void); # define native_architecture() ARCHITECTURE_X86_64 # define LIB_ARCH_TUPLE "x86_64-linux-gnu" # define PROC_CPUINFO_MODEL "model name" +# define SECONDARY_ARCHITECTURE ARCHITECTURE_X86 #elif defined(__i386__) # define native_architecture() ARCHITECTURE_X86 # define LIB_ARCH_TUPLE "i386-linux-gnu" @@ -86,9 +87,11 @@ int uname_architecture(void); # if __BYTE_ORDER == __BIG_ENDIAN # define native_architecture() ARCHITECTURE_PPC64 # define LIB_ARCH_TUPLE "ppc64-linux-gnu" +# define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC # else # define native_architecture() ARCHITECTURE_PPC64_LE # define LIB_ARCH_TUPLE "powerpc64le-linux-gnu" +# define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE # endif # define PROC_CPUINFO_MODEL "cpu" #elif defined(__powerpc__) @@ -114,6 +117,7 @@ int uname_architecture(void); #elif defined(__s390x__) # define native_architecture() ARCHITECTURE_S390X # define LIB_ARCH_TUPLE "s390x-linux-gnu" +# define SECONDARY_ARCHITECTURE ARCHITECTURE_S390 #elif defined(__s390__) # define native_architecture() ARCHITECTURE_S390 # define LIB_ARCH_TUPLE "s390-linux-gnu" diff --git a/src/basic/process-util.c b/src/basic/process-util.c index f45e4ca338..ae3f6109ad 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -677,6 +677,9 @@ bool oom_score_adjust_is_valid(int oa) { unsigned long personality_from_string(const char *p) { int architecture; + if (!p) + return PERSONALITY_INVALID; + /* Parse a personality specifier. We use our own identifiers that indicate specific ABIs, rather than just * hints regarding the register size, since we want to keep things open for multiple locally supported ABIs for * the same register size. */ @@ -685,62 +688,11 @@ unsigned long personality_from_string(const char *p) { if (architecture < 0) return PERSONALITY_INVALID; -#if defined(__x86_64__) - - if (architecture == ARCHITECTURE_X86) - return PER_LINUX32; - - if (architecture == ARCHITECTURE_X86_64) - return PER_LINUX; - -#elif defined(__i386__) - - if (architecture == ARCHITECTURE_X86) - return PER_LINUX; - -#elif defined(__s390x__) - - if (architecture == ARCHITECTURE_S390) - return PER_LINUX32; - - if (architecture == ARCHITECTURE_S390X) - return PER_LINUX; - -#elif defined(__s390__) - - if (architecture == ARCHITECTURE_S390) + if (architecture == native_architecture()) return PER_LINUX; - -#elif defined(__powerpc64__) -# if __BYTE_ORDER == __BIG_ENDIAN - - if (architecture == ARCHITECTURE_PPC_LE) +#ifdef SECONDARY_ARCHITECTURE + if (architecture == SECONDARY_ARCHITECTURE) return PER_LINUX32; - - if (architecture == ARCHITECTURE_PPC64_LE) - return PER_LINUX; - -# else - - if (architecture == ARCHITECTURE_PPC) - return PER_LINUX32; - - if (architecture == ARCHITECTURE_PPC64) - return PER_LINUX; - -# endif -#elif defined(__powerpc__) -# if __BYTE_ORDER == __BIG_ENDIAN - - if (architecture == ARCHITECTURE_PPC) - return PER_LINUX; - -# else - - if (architecture == ARCHITECTURE_PPC_LE) - return PER_LINUX; - -# endif #endif return PERSONALITY_INVALID; @@ -749,58 +701,11 @@ unsigned long personality_from_string(const char *p) { const char* personality_to_string(unsigned long p) { int architecture = _ARCHITECTURE_INVALID; -#if defined(__x86_64__) - if (p == PER_LINUX) - architecture = ARCHITECTURE_X86_64; + architecture = native_architecture(); +#ifdef SECONDARY_ARCHITECTURE else if (p == PER_LINUX32) - architecture = ARCHITECTURE_X86; - -#elif defined(__i386__) - - if (p == PER_LINUX) - architecture = ARCHITECTURE_X86; - -#elif defined(__s390x__) - - if (p == PER_LINUX) - architecture = ARCHITECTURE_S390X; - else if (p == PER_LINUX32) - architecture = ARCHITECTURE_S390; - -#elif defined(__s390__) - - if (p == PER_LINUX) - architecture = ARCHITECTURE_S390; - -#elif defined(__powerpc64__) -# if __BYTE_ORDER == __BIG_ENDIAN - - if (p == PER_LINUX) - architecture = ARCHITECTURE_PPC64; - else if (p == PER_LINUX32) - architecture = ARCHITECTURE_PPC; - -# else - - if (p == PER_LINUX) - architecture = ARCHITECTURE_PPC64_LE; - else if (p == PER_LINUX32) - architecture = ARCHITECTURE_PPC_LE; - -# endif -#elif defined(__powerpc__) -# if __BYTE_ORDER == __BIG_ENDIAN - - if (p == PER_LINUX) - architecture = ARCHITECTURE_PPC; - -# else - - if (p == PER_LINUX) - architecture = ARCHITECTURE_PPC_LE; - -# endif + architecture = SECONDARY_ARCHITECTURE; #endif if (architecture < 0) |