OSDN Git Service

Merge remote-tracking branch 'cern/multiuser-regression-v1' into cm-11.0
[android-x86/external-koush-Superuser.git] / Superuser / jni / su / su.c
index fc8c7ee..55e54a6 100644 (file)
@@ -607,6 +607,28 @@ static int get_api_version() {
   return ver;
 }
 
+static void fork_for_samsung(void)
+{
+    // Samsung CONFIG_SEC_RESTRICT_SETUID wants the parent process to have
+    // EUID 0, or else our setresuid() calls will be denied.  So make sure
+    // all such syscalls are executed by a child process.
+    int rv;
+
+    switch (fork()) {
+    case 0:
+        return;
+    case -1:
+        PLOGE("fork");
+        exit(1);
+    default:
+        if (wait(&rv) < 0) {
+            exit(1);
+        } else {
+            exit(WEXITSTATUS(rv));
+        }
+    }
+}
+
 int main(int argc, char *argv[]) {
     return su_main(argc, argv, 1);
 }
@@ -617,6 +639,8 @@ int su_main(int argc, char *argv[], int need_client) {
         return run_daemon();
     }
 
+    fork_for_samsung();
+
     // Sanitize all secure environment variables (from linker_environ.c in AOSP linker).
     /* The same list than GLibc at this point */
     static const char* const unsec_vars[] = {