user: avoid calling setresgid twice on machines that support setres(g|u)id32 2.1
authorRobert Swiecki <robert@swiecki.net>
Thu, 19 Oct 2017 00:14:58 +0000 (02:14 +0200)
committerRobert Swiecki <robert@swiecki.net>
Thu, 19 Oct 2017 00:14:58 +0000 (02:14 +0200)
user.c

diff --git a/user.c b/user.c
index 68dac55188accbe900e4dd01c21c7ed98a536f47..bd063e708c1015e3c36b253f02f2b6a219841b3d 100644 (file)
--- a/user.c
+++ b/user.c
@@ -48,16 +48,16 @@ static bool userSetResGid(gid_t gid)
 {
        LOG_D("setresgid(%d)", gid);
 #if defined(__NR_setresgid32)
-       if (syscall(__NR_setresgid32, (uintptr_t)gid, (uintptr_t)gid, (uintptr_t)gid) == -1
-           && errno != ENOSYS) {
+       if (syscall(__NR_setresgid32, (uintptr_t)gid, (uintptr_t)gid, (uintptr_t)gid) == -1) {
                PLOG_W("setresgid32(%d)", (int)gid);
                return false;
        }
-#endif /* defined(__NR_setresgid32) */
+#else /* defined(__NR_setresgid32) */
        if (syscall(__NR_setresgid, (uintptr_t)gid, (uintptr_t)gid, (uintptr_t)gid) == -1) {
                PLOG_W("setresgid(%d)", gid);
                return false;
        }
+#endif /* defined(__NR_setresuid32) */
        return true;
 }
 
@@ -65,16 +65,16 @@ static bool userSetResUid(uid_t uid)
 {
        LOG_D("setresuid(%d)", uid);
 #if defined(__NR_setresuid32)
-       if (syscall(__NR_setresuid32, (uintptr_t)uid, (uintptr_t)uid, (uintptr_t)uid) == -1
-           && errno != ENOSYS) {
+       if (syscall(__NR_setresuid32, (uintptr_t)uid, (uintptr_t)uid, (uintptr_t)uid) == -1) {
                PLOG_W("setresuid32(%d)", (int)uid);
                return false;
        }
-#endif /* defined(__NR_setresuid32) */
+#else /* defined(__NR_setresuid32) */
        if (syscall(__NR_setresuid, (uintptr_t)uid, (uintptr_t)uid, (uintptr_t)uid) == -1) {
                PLOG_W("setresuid(%d)", uid);
                return false;
        }
+#endif /* defined(__NR_setresuid32) */
        return true;
 }