- don't free user-supplied string (via -e)
[oweals/busybox.git] / util-linux / setarch.c
index 3543eb6a203beabdad7ee6b26ffd1f4f3488cb88..250a93823bcf8f42b47837e9c4c461ee7585a58a 100644 (file)
@@ -3,21 +3,16 @@
  * Linux32/linux64 allows for changing uname emulation.
  *
  * Copyright 2002 Andi Kleen, SuSE Labs.
- * This file is subject to the GNU General Public License v2 
  *
  * Licensed under GPL v2 or later, see file License for details.
 */
 
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
 #include <sys/personality.h>
 
-#include "busybox.h"
+#include "libbb.h"
 
-int setarch_main(int argc, char **argv)
+int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int setarch_main(int argc UNUSED_PARAM, char **argv)
 {
        int pers = -1;
 
@@ -27,9 +22,9 @@ int setarch_main(int argc, char **argv)
         * argv[0]         -> "personality"
         */
 retry:
-       if (!strcmp(argv[0], "linux64"))
+       if (argv[0][5] == '6') /* linux64 */
                pers = PER_LINUX;
-       else if (!strcmp(argv[0], "linux32"))
+       else if (argv[0][5] == '3') /* linux32 */
                pers = PER_LINUX32;
        else if (pers == -1 && argv[1] != NULL) {
                pers = PER_LINUX32;
@@ -43,12 +38,11 @@ retry:
                bb_show_usage();
 
        /* Try to set personality */
-       if (personality(pers) < 0)
-               goto failure;
+       if (personality(pers) >= 0) {
 
-       /* Try to execute the program */
-       execvp(argv[0], argv);
+               /* Try to execute the program */
+               BB_EXECVP(argv[0], argv);
+       }
 
-failure:
-       bb_perror_msg_and_die(argv[0]);
+       bb_simple_perror_msg_and_die(argv[0]);
 }