OSDN Git Service

bugfix: the multiplexer increments optc and then the command the multiplexer runs...
[android-x86/external-toybox.git] / main.c
diff --git a/main.c b/main.c
index dd985b8..92ec89f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -20,7 +20,7 @@ struct toy_list toy_list[] = {
 
 struct toy_context toys;
 union global_union this;
-char toybuf[4096];
+char toybuf[4096], libbuf[4096];
 
 struct toy_list *toy_find(char *name)
 {
@@ -92,7 +92,8 @@ void toy_init(struct toy_list *which, char *argv[])
     uid_t uid = getuid(), euid = geteuid();
 
     if (!(which->flags & TOYFLAG_STAYROOT)) {
-      if (uid != euid) xsetuid(euid=uid);
+      if (uid != euid)
+        if (!setuid(euid=uid)) perror_exit("setuid"); // drop root
     } else if (CFG_TOYBOX_DEBUG && uid && which != toy_list)
       error_msg("Not installed suid root");
 
@@ -131,6 +132,7 @@ void toybox_main(void)
 
   toys.which = toy_list;
   if (toys.argv[1]) {
+    toys.optc = 0;
     toy_exec(toys.argv+1);
     if (toys.argv[1][0] == '-') goto list;
     
@@ -161,6 +163,8 @@ int main(int argc, char *argv[])
 {
   if (CFG_TOYBOX_I18N) setlocale(LC_ALL, "");
 
+  toys.toycount = ARRAY_LEN(toy_list);
+
   if (CFG_TOYBOX) {
     // Trim path off of command name
     *argv = basename(*argv);