summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/com/android/internal/os/ZygoteConnection.java4
-rw-r--r--core/java/com/android/internal/os/ZygoteInit.java70
-rw-r--r--core/jni/Android.mk1
-rw-r--r--core/jni/AndroidRuntime.cpp2
-rw-r--r--core/jni/com_android_internal_os_ZygoteInit.cpp111
5 files changed, 14 insertions, 174 deletions
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index e980acb1ba3c..c03938a2e658 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -993,8 +993,8 @@ class ZygoteConnection {
private void setChildPgid(int pid) {
// Try to move the new child into the peer's process group.
try {
- ZygoteInit.setpgid(pid, ZygoteInit.getpgid(peer.getPid()));
- } catch (IOException ex) {
+ Os.setpgid(pid, Os.getpgid(peer.getPid()));
+ } catch (ErrnoException ex) {
// This exception is expected in the case where
// the peer is not in our session
// TODO get rid of this log message in the case where
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index dbacc8408510..0fa9a976d863 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -229,26 +229,6 @@ public class ZygoteInit {
private static final int ROOT_UID = 0;
private static final int ROOT_GID = 0;
- /**
- * Sets effective user ID.
- */
- private static void setEffectiveUser(int uid) {
- int errno = setreuid(ROOT_UID, uid);
- if (errno != 0) {
- Log.e(TAG, "setreuid() failed. errno: " + errno);
- }
- }
-
- /**
- * Sets effective group ID.
- */
- private static void setEffectiveGroup(int gid) {
- int errno = setregid(ROOT_GID, gid);
- if (errno != 0) {
- Log.e(TAG, "setregid() failed. errno: " + errno);
- }
- }
-
static void preload() {
Log.d(TAG, "begin preload");
preloadClasses();
@@ -296,8 +276,12 @@ public class ZygoteInit {
long startTime = SystemClock.uptimeMillis();
// Drop root perms while running static initializers.
- setEffectiveGroup(UNPRIVILEGED_GID);
- setEffectiveUser(UNPRIVILEGED_UID);
+ try {
+ Os.setregid(ROOT_GID, UNPRIVILEGED_GID);
+ Os.setreuid(ROOT_UID, UNPRIVILEGED_UID);
+ } catch (ErrnoException ex) {
+ throw new RuntimeException("Failed to drop root", ex);
+ }
// Alter the target heap utilization. With explicit GCs this
// is not likely to have any effect.
@@ -352,8 +336,12 @@ public class ZygoteInit {
runtime.preloadDexCaches();
// Bring back root. We'll need it later.
- setEffectiveUser(ROOT_UID);
- setEffectiveGroup(ROOT_GID);
+ try {
+ Os.setreuid(ROOT_UID, ROOT_UID);
+ Os.setregid(ROOT_GID, ROOT_GID);
+ } catch (ErrnoException ex) {
+ throw new RuntimeException("Failed to restore root", ex);
+ }
}
}
@@ -738,40 +726,6 @@ public class ZygoteInit {
}
/**
- * The Linux syscall "setreuid()"
- * @param ruid real uid
- * @param euid effective uid
- * @return 0 on success, non-zero errno on fail
- */
- static native int setreuid(int ruid, int euid);
-
- /**
- * The Linux syscall "setregid()"
- * @param rgid real gid
- * @param egid effective gid
- * @return 0 on success, non-zero errno on fail
- */
- static native int setregid(int rgid, int egid);
-
- /**
- * Invokes the linux syscall "setpgid"
- *
- * @param pid pid to change
- * @param pgid new process group of pid
- * @return 0 on success or non-zero errno on fail
- */
- static native int setpgid(int pid, int pgid);
-
- /**
- * Invokes the linux syscall "getpgid"
- *
- * @param pid pid to query
- * @return pgid of pid in question
- * @throws IOException on error
- */
- static native int getpgid(int pid) throws IOException;
-
- /**
* Class not instantiable.
*/
private ZygoteInit() {
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 97e0fd3ccb90..2d54742b355d 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -156,7 +156,6 @@ LOCAL_SRC_FILES:= \
android_server_NetworkManagementSocketTagger.cpp \
android_server_Watchdog.cpp \
android_ddm_DdmHandleNativeHeap.cpp \
- com_android_internal_os_ZygoteInit.cpp \
android_backup_BackupDataInput.cpp \
android_backup_BackupDataOutput.cpp \
android_backup_FileBackupHelperBase.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 644f6a6cafa6..c6224e5ab360 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -162,7 +162,6 @@ extern int register_android_text_AndroidBidi(JNIEnv *env);
extern int register_android_opengl_classes(JNIEnv *env);
extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
-extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env);
extern int register_android_backup_BackupDataInput(JNIEnv *env);
extern int register_android_backup_BackupDataOutput(JNIEnv *env);
extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
@@ -1321,7 +1320,6 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_net_NetworkUtils),
REG_JNI(register_android_net_TrafficStats),
REG_JNI(register_android_os_MemoryFile),
- REG_JNI(register_com_android_internal_os_ZygoteInit),
REG_JNI(register_com_android_internal_os_Zygote),
REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
REG_JNI(register_android_hardware_Camera),
diff --git a/core/jni/com_android_internal_os_ZygoteInit.cpp b/core/jni/com_android_internal_os_ZygoteInit.cpp
deleted file mode 100644
index c42229ea7c96..000000000000
--- a/core/jni/com_android_internal_os_ZygoteInit.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "Zygote"
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <utils/misc.h>
-#include <errno.h>
-#include <sys/select.h>
-
-#include "jni.h"
-#include <JNIHelp.h>
-#include "core_jni_helpers.h"
-
-#include <sys/capability.h>
-#include <sys/prctl.h>
-
-namespace android {
-
-/*
- * In class com.android.internal.os.ZygoteInit:
- * private static native boolean setreuid(int ruid, int euid)
- */
-static jint com_android_internal_os_ZygoteInit_setreuid(
- JNIEnv* env, jobject clazz, jint ruid, jint euid)
-{
- if (setreuid(ruid, euid) < 0) {
- return errno;
- }
- return 0;
-}
-
-/*
- * In class com.android.internal.os.ZygoteInit:
- * private static native int setregid(int rgid, int egid)
- */
-static jint com_android_internal_os_ZygoteInit_setregid(
- JNIEnv* env, jobject clazz, jint rgid, jint egid)
-{
- if (setregid(rgid, egid) < 0) {
- return errno;
- }
- return 0;
-}
-
-/*
- * In class com.android.internal.os.ZygoteInit:
- * private static native int setpgid(int rgid, int egid)
- */
-static jint com_android_internal_os_ZygoteInit_setpgid(
- JNIEnv* env, jobject clazz, jint pid, jint pgid)
-{
- if (setpgid(pid, pgid) < 0) {
- return errno;
- }
- return 0;
-}
-
-/*
- * In class com.android.internal.os.ZygoteInit:
- * private static native int getpgid(int pid)
- */
-static jint com_android_internal_os_ZygoteInit_getpgid(
- JNIEnv* env, jobject clazz, jint pid)
-{
- pid_t ret;
- ret = getpgid(pid);
-
- if (ret < 0) {
- jniThrowIOException(env, errno);
- }
-
- return ret;
-}
-
-/*
- * JNI registration.
- */
-static JNINativeMethod gMethods[] = {
- /* name, signature, funcPtr */
- { "setreuid", "(II)I",
- (void*) com_android_internal_os_ZygoteInit_setreuid },
- { "setregid", "(II)I",
- (void*) com_android_internal_os_ZygoteInit_setregid },
- { "setpgid", "(II)I",
- (void *) com_android_internal_os_ZygoteInit_setpgid },
- { "getpgid", "(I)I",
- (void *) com_android_internal_os_ZygoteInit_getpgid },
-};
-int register_com_android_internal_os_ZygoteInit(JNIEnv* env)
-{
- return RegisterMethodsOrDie(env,
- "com/android/internal/os/ZygoteInit", gMethods, NELEM(gMethods));
-}
-
-}; // namespace android