Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Linux32/linux64 allows for changing uname emulation. |
| 4 | * |
| 5 | * Copyright 2002 Andi Kleen, SuSE Labs. |
| 6 | * This file is subject to the GNU General Public License v2 |
| 7 | * |
| 8 | * Licensed under GPL v2 or later, see file License for details. |
| 9 | */ |
| 10 | |
| 11 | #include <stdlib.h> |
| 12 | #include <unistd.h> |
| 13 | #include <string.h> |
| 14 | #include <errno.h> |
| 15 | #include <stdio.h> |
| 16 | #include <sys/personality.h> |
| 17 | |
| 18 | #include "busybox.h" |
| 19 | |
| 20 | int setarch_main(int argc, char **argv) |
| 21 | { |
| 22 | int pers = -1; |
| 23 | |
| 24 | /* Figure out what personality we are supposed to switch to ... |
| 25 | * we can be invoked as either: |
| 26 | * argv[0],argv[1] -> "setarch","personality" |
| 27 | * argv[0] -> "personality" |
| 28 | */ |
| 29 | retry: |
| 30 | if (!strcmp(argv[0], "linux64")) |
| 31 | pers = PER_LINUX; |
| 32 | else if (!strcmp(argv[0], "linux32")) |
| 33 | pers = PER_LINUX32; |
| 34 | else if (pers == -1 && argv[1] != NULL) { |
| 35 | pers = PER_LINUX32; |
| 36 | ++argv; |
| 37 | goto retry; |
| 38 | } |
| 39 | |
| 40 | /* make user actually gave us something to do */ |
| 41 | ++argv; |
| 42 | if (argv[0] == NULL) |
| 43 | bb_show_usage(); |
| 44 | |
| 45 | /* Try to set personality */ |
| 46 | if (personality(pers) < 0) |
| 47 | goto failure; |
| 48 | |
| 49 | /* Try to execute the program */ |
| 50 | execvp(argv[0], argv); |
| 51 | |
| 52 | failure: |
| 53 | bb_perror_msg_and_die(argv[0]); |
| 54 | } |