am 4ac5775d: Merge "Fix handling of wrapped processes [part 2]"

* commit '4ac5775d63791ae3635882a3b49f5ebc253262bb':
  Fix handling of wrapped processes [part 2]
This commit is contained in:
Narayan Kamath
2015-01-19 10:09:42 +00:00
committed by Android Git Automerger

View File

@@ -17,7 +17,6 @@
package com.android.internal.os; package com.android.internal.os;
import static android.system.OsConstants.POLLIN; import static android.system.OsConstants.POLLIN;
import static android.system.OsConstants.POLLOUT;
import static android.system.OsConstants.S_IRWXG; import static android.system.OsConstants.S_IRWXG;
import static android.system.OsConstants.S_IRWXO; import static android.system.OsConstants.S_IRWXO;
@@ -276,6 +275,14 @@ public class ZygoteInit {
long startTime = SystemClock.uptimeMillis(); long startTime = SystemClock.uptimeMillis();
// Drop root perms while running static initializers. // Drop root perms while running static initializers.
final int reuid = Os.getuid();
final int regid = Os.getgid();
// We need to drop root perms only if we're already root. In the case of "wrapped"
// processes (see WrapperInit), this function is called from an unprivileged uid
// and gid.
boolean droppedPriviliges = false;
if (reuid == ROOT_UID && regid == ROOT_GID) {
try { try {
Os.setregid(ROOT_GID, UNPRIVILEGED_GID); Os.setregid(ROOT_GID, UNPRIVILEGED_GID);
Os.setreuid(ROOT_UID, UNPRIVILEGED_UID); Os.setreuid(ROOT_UID, UNPRIVILEGED_UID);
@@ -283,6 +290,9 @@ public class ZygoteInit {
throw new RuntimeException("Failed to drop root", ex); throw new RuntimeException("Failed to drop root", ex);
} }
droppedPriviliges = true;
}
// Alter the target heap utilization. With explicit GCs this // Alter the target heap utilization. With explicit GCs this
// is not likely to have any effect. // is not likely to have any effect.
float defaultUtilization = runtime.getTargetHeapUtilization(); float defaultUtilization = runtime.getTargetHeapUtilization();
@@ -335,7 +345,8 @@ public class ZygoteInit {
// Fill in dex caches with classes, fields, and methods brought in by preloading. // Fill in dex caches with classes, fields, and methods brought in by preloading.
runtime.preloadDexCaches(); runtime.preloadDexCaches();
// Bring back root. We'll need it later. // Bring back root. We'll need it later if we're in the zygote.
if (droppedPriviliges) {
try { try {
Os.setreuid(ROOT_UID, ROOT_UID); Os.setreuid(ROOT_UID, ROOT_UID);
Os.setregid(ROOT_GID, ROOT_GID); Os.setregid(ROOT_GID, ROOT_GID);
@@ -344,6 +355,7 @@ public class ZygoteInit {
} }
} }
} }
}
/** /**
* Load in commonly used resources, so they can be shared across * Load in commonly used resources, so they can be shared across