OSDN Git Service

Merge pull request #87 from alvinhkh/master
[android-x86/external-koush-Superuser.git] / Superuser / jni / su / su.c
index e9134ff..32166a7 100644 (file)
@@ -174,10 +174,10 @@ static int get_multiuser_mode() {
     char mode[12];
     FILE *fp;
     if ((fp = fopen(REQUESTOR_MULTIUSER_MODE, "r"))) {
+        fgets(mode, sizeof(mode), fp);
         int last = strlen(mode) - 1;
         if (mode[last] == '\n')
             mode[last] = '\0';
-        fgets(mode, sizeof(mode), fp);
         if (strcmp(mode, MULTIUSER_VALUE_USER) == 0) {
             ret = MULTIUSER_MODE_USER;
         } else if (strcmp(mode, MULTIUSER_VALUE_OWNER_MANAGED) == 0) {
@@ -703,10 +703,17 @@ int main(int argc, char *argv[]) {
     read_options(&ctx);
     user_init(&ctx);
     
+    // TODO: customizable behavior for shell? It can currently be toggled via settings.
+    if (ctx.from.uid == AID_ROOT || ctx.from.uid == AID_SHELL) {
+        LOGD("Allowing root/shell.");
+        allow(&ctx);
+    }
+
     // verify superuser is installed
     if (stat(ctx.user.base_path, &st) < 0) {
         // send to market
-        silent_run("am start -d market://details?id=" JAVA_PACKAGE_NAME);
+        if (0 == strcmp(JAVA_PACKAGE_NAME, REQUESTOR))
+            silent_run("am start -d http://www.clockworkmod.com/superuser/install.html -a android.intent.action.VIEW");
         PLOGE("stat %s", ctx.user.base_path);
         deny(&ctx);
     }
@@ -737,12 +744,6 @@ int main(int argc, char *argv[]) {
 
     ctx.umask = umask(027);
 
-    // TODO: customizable behavior for shell? It can currently be toggled via settings.
-    if (ctx.from.uid == AID_ROOT || ctx.from.uid == AID_SHELL) {
-        LOGD("Allowing root/shell.");
-        allow(&ctx);
-    }
-
     int ret = mkdir(REQUESTOR_CACHE_PATH, 0770);
     if (chown(REQUESTOR_CACHE_PATH, st.st_uid, st.st_gid)) {
         PLOGE("chown (%s, %ld, %ld)", REQUESTOR_CACHE_PATH, st.st_uid, st.st_gid);