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. |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 6 | * |
| 7 | * Licensed under GPL v2 or later, see file License for details. |
| 8 | */ |
| 9 | |
| 10 | #include <stdlib.h> |
| 11 | #include <unistd.h> |
| 12 | #include <string.h> |
| 13 | #include <errno.h> |
| 14 | #include <stdio.h> |
| 15 | #include <sys/personality.h> |
| 16 | |
| 17 | #include "busybox.h" |
| 18 | |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame] | 19 | int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv); |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 20 | int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv) |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 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: |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 30 | if (argv[0][5] == '6') /* linux64 */ |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 31 | pers = PER_LINUX; |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 32 | else if (argv[0][5] == '3') /* linux32 */ |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 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 */ |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 46 | if (personality(pers) >= 0) { |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 47 | |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 48 | /* Try to execute the program */ |
Denis Vlasenko | 1d76f43 | 2007-02-06 01:20:12 +0000 | [diff] [blame] | 49 | BB_EXECVP(argv[0], argv); |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 50 | } |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 51 | |
"Vladimir N. Oleynik" | 73804d6 | 2006-02-28 08:23:27 +0000 | [diff] [blame] | 52 | bb_perror_msg_and_die("%s", argv[0]); |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 53 | } |