summaryrefslogtreecommitdiffstats
path: root/sys-utils/setarch.c
diff options
context:
space:
mode:
authorDmitry V. Levin2016-03-04 22:22:52 +0100
committerKarel Zak2016-03-07 14:23:21 +0100
commitae7065760d9bbe776a93a73d88e85c7796acb8cc (patch)
tree4fb2c61f61aa096750be9cd0e2784ac8ab254b68 /sys-utils/setarch.c
parentblkdiscard: add --zeroout (BLKZEROOUT ioctl) (diff)
downloadkernel-qcow2-util-linux-ae7065760d9bbe776a93a73d88e85c7796acb8cc.tar.gz
kernel-qcow2-util-linux-ae7065760d9bbe776a93a73d88e85c7796acb8cc.tar.xz
kernel-qcow2-util-linux-ae7065760d9bbe776a93a73d88e85c7796acb8cc.zip
setarch: fix personality syscall return code check
Depending on architecture and kernel version, personality syscall is either capable or incapable of returning an error. If the return value is not an error, then it's the previous personality value, which can be an arbitrary value undistinguishable from an error value. To make things clear, a second call is needed. For more details about personality syscall peculiarities see https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=glibc-2.22-637-ge0043e17dfc5 Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Diffstat (limited to 'sys-utils/setarch.c')
-rw-r--r--sys-utils/setarch.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index b6159c5b4..b5e401c81 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -236,8 +236,18 @@ static int set_arch(const char *pers, unsigned long options, int list)
if (transitions[i].perval < 0)
errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers);
pers_value = transitions[i].perval | options;
- if (personality(pers_value) == -EINVAL)
- return 1;
+ if (personality(pers_value) < 0) {
+ /*
+ * Depending on architecture and kernel version, personality
+ * syscall is either capable or incapable of returning an error.
+ * If the return value is not an error, then it's the previous
+ * personality value, which can be an arbitrary value
+ * undistinguishable from an error value.
+ * To make things clear, a second call is needed.
+ */
+ if (personality(pers_value) < 0)
+ return 1;
+ }
uname(&un);
if (transitions[i].result_arch && strcmp(un.machine, transitions[i].result_arch)) {
if (strcmp(transitions[i].result_arch, "i386")