From 05554a4ee99ae4696929cb1b9a646dbd7a6c7e76 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Mon, 10 Jan 2011 11:22:43 -0800 Subject: [PATCH] Fix start-time setreuid complaints. The code was checking errno instead of the return value from the call. This fixes calls to setreuid(), setregid(), and setpgid(). Bug 3131052 Change-Id: I8b6155bd4fa9b941895b35fed62cfc163b420fff --- .../com_android_internal_os_ZygoteInit.cpp | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/core/jni/com_android_internal_os_ZygoteInit.cpp b/core/jni/com_android_internal_os_ZygoteInit.cpp index ada4dd339be2e..52e8f4251bb9a 100644 --- a/core/jni/com_android_internal_os_ZygoteInit.cpp +++ b/core/jni/com_android_internal_os_ZygoteInit.cpp @@ -45,14 +45,10 @@ namespace android { static jint com_android_internal_os_ZygoteInit_setreuid( JNIEnv* env, jobject clazz, jint ruid, jint euid) { - int err; - - errno = 0; - err = setreuid(ruid, euid); - - //LOGI("setreuid(%d,%d) err %d errno %d", ruid, euid, err, errno); - - return errno; + if (setreuid(ruid, euid) < 0) { + return errno; + } + return 0; } /* @@ -62,14 +58,10 @@ static jint com_android_internal_os_ZygoteInit_setreuid( static jint com_android_internal_os_ZygoteInit_setregid( JNIEnv* env, jobject clazz, jint rgid, jint egid) { - int err; - - errno = 0; - err = setregid(rgid, egid); - - //LOGI("setregid(%d,%d) err %d errno %d", rgid, egid, err, errno); - - return errno; + if (setregid(rgid, egid) < 0) { + return errno; + } + return 0; } /* @@ -79,13 +71,10 @@ static jint com_android_internal_os_ZygoteInit_setregid( static jint com_android_internal_os_ZygoteInit_setpgid( JNIEnv* env, jobject clazz, jint pid, jint pgid) { - int err; - - errno = 0; - - err = setpgid(pid, pgid); - - return errno; + if (setpgid(pid, pgid) < 0) { + return errno; + } + return 0; } /*