diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2016-02-23 08:19:20 +0100 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2016-02-23 08:19:20 +0100 |
commit | 548bd139fed78a83ce063afb4b4d68dd0971884b (patch) | |
tree | 7d5867f9b46724c8df72f758db812b328a7a801a /src | |
parent | c4bcaa4148fbfe977a551cdd0b1209a416ede586 (diff) | |
parent | 13f41f6266891286f285cf4615cc389954f3f23f (diff) |
Merge pull request #2698 from poettering/personality
Personality fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/architecture.c (renamed from src/shared/architecture.c) | 0 | ||||
-rw-r--r-- | src/basic/architecture.h (renamed from src/shared/architecture.h) | 4 | ||||
-rw-r--r-- | src/basic/process-util.c | 75 | ||||
-rw-r--r-- | src/basic/virt.c | 2 | ||||
-rw-r--r-- | src/test/test-process-util.c | 26 |
5 files changed, 54 insertions, 53 deletions
diff --git a/src/shared/architecture.c b/src/basic/architecture.c index a9ecfc1cd6..a9ecfc1cd6 100644 --- a/src/shared/architecture.c +++ b/src/basic/architecture.c diff --git a/src/shared/architecture.h b/src/basic/architecture.h index 26679e28c6..63cf6fb703 100644 --- a/src/shared/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 27663eee51..ae3f6109ad 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -38,6 +38,7 @@ #endif #include "alloc-util.h" +#include "architecture.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" @@ -674,75 +675,43 @@ bool oom_score_adjust_is_valid(int oa) { } unsigned long personality_from_string(const char *p) { + int architecture; - /* Parse a personality specifier. We introduce 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. We try to reuse the ABI identifiers - * used by libseccomp. */ + if (!p) + return PERSONALITY_INVALID; -#if defined(__x86_64__) + /* 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. */ - if (streq(p, "x86")) - return PER_LINUX32; + architecture = architecture_from_string(p); + if (architecture < 0) + return PERSONALITY_INVALID; - if (streq(p, "x86-64")) + if (architecture == native_architecture()) return PER_LINUX; - -#elif defined(__i386__) - - if (streq(p, "x86")) - return PER_LINUX; - -#elif defined(__s390x__) - - if (streq(p, "s390")) +#ifdef SECONDARY_ARCHITECTURE + if (architecture == SECONDARY_ARCHITECTURE) return PER_LINUX32; - - if (streq(p, "s390x")) - return PER_LINUX; - -#elif defined(__s390__) - - if (streq(p, "s390")) - return PER_LINUX; #endif return PERSONALITY_INVALID; } const char* personality_to_string(unsigned long p) { - -#if defined(__x86_64__) - - if (p == PER_LINUX32) - return "x86"; - - if (p == PER_LINUX) - return "x86-64"; - -#elif defined(__i386__) - - if (p == PER_LINUX) - return "x86"; - -#elif defined(__s390x__) + int architecture = _ARCHITECTURE_INVALID; if (p == PER_LINUX) - return "s390x"; - - if (p == PER_LINUX32) - return "s390"; - -#elif defined(__s390__) - - if (p == PER_LINUX) - return "s390"; - + architecture = native_architecture(); +#ifdef SECONDARY_ARCHITECTURE + else if (p == PER_LINUX32) + architecture = SECONDARY_ARCHITECTURE; #endif - return NULL; + if (architecture < 0) + return NULL; + + return architecture_to_string(architecture); } void valgrind_summary_hack(void) { diff --git a/src/basic/virt.c b/src/basic/virt.c index 19b6318e3d..79387007f0 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -201,6 +201,8 @@ static int detect_vm_xen(void) { r = read_one_line_file("/proc/xen/capabilities", &domcap); if (r == -ENOENT) return VIRTUALIZATION_NONE; + if (r < 0) + return r; i = domcap; while ((cap = strsep(&i, ","))) diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 48be5a3a87..4616314200 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -18,12 +18,14 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <sys/personality.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include "alloc-util.h" +#include "architecture.h" #include "log.h" #include "macro.h" #include "process-util.h" @@ -128,6 +130,29 @@ static void test_pid_is_alive(void) { assert_se(!pid_is_alive(-1)); } +static void test_personality(void) { + + assert_se(personality_to_string(PER_LINUX)); + assert_se(!personality_to_string(PERSONALITY_INVALID)); + + assert_se(streq(personality_to_string(PER_LINUX), architecture_to_string(native_architecture()))); + + assert_se(personality_from_string(personality_to_string(PER_LINUX)) == PER_LINUX); + assert_se(personality_from_string(architecture_to_string(native_architecture())) == PER_LINUX); + +#ifdef __x86_64__ + assert_se(streq_ptr(personality_to_string(PER_LINUX), "x86-64")); + assert_se(streq_ptr(personality_to_string(PER_LINUX32), "x86")); + + assert_se(personality_from_string("x86-64") == PER_LINUX); + assert_se(personality_from_string("x86") == PER_LINUX32); + assert_se(personality_from_string("ia64") == PERSONALITY_INVALID); + assert_se(personality_from_string(NULL) == PERSONALITY_INVALID); + + assert_se(personality_from_string(personality_to_string(PER_LINUX32)) == PER_LINUX32); +#endif +} + int main(int argc, char *argv[]) { log_parse_environment(); log_open(); @@ -135,6 +160,7 @@ int main(int argc, char *argv[]) { test_get_process_comm(); test_pid_is_unwaited(); test_pid_is_alive(); + test_personality(); return 0; } |