[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
[2725] | 3 | * linux32/linux64 allows for changing uname emulation.
|
---|
[821] | 4 | *
|
---|
| 5 | * Copyright 2002 Andi Kleen, SuSE Labs.
|
---|
| 6 | *
|
---|
[2725] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
[3232] | 8 | */
|
---|
[821] | 9 |
|
---|
[3232] | 10 | //usage:#define setarch_trivial_usage
|
---|
| 11 | //usage: "personality PROG ARGS"
|
---|
| 12 | //usage:#define setarch_full_usage "\n\n"
|
---|
| 13 | //usage: "Personality may be:\n"
|
---|
| 14 | //usage: " linux32 Set 32bit uname emulation\n"
|
---|
| 15 | //usage: " linux64 Set 64bit uname emulation"
|
---|
| 16 | //usage:
|
---|
| 17 | //usage:#define linux32_trivial_usage NOUSAGE_STR
|
---|
| 18 | //usage:#define linux32_full_usage ""
|
---|
| 19 | //usage:
|
---|
| 20 | //usage:#define linux64_trivial_usage NOUSAGE_STR
|
---|
| 21 | //usage:#define linux64_full_usage ""
|
---|
| 22 |
|
---|
[821] | 23 | #include <sys/personality.h>
|
---|
| 24 |
|
---|
[1765] | 25 | #include "libbb.h"
|
---|
[821] | 26 |
|
---|
[2725] | 27 | int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
| 28 | int setarch_main(int argc UNUSED_PARAM, char **argv)
|
---|
[821] | 29 | {
|
---|
[2725] | 30 | int pers;
|
---|
[821] | 31 |
|
---|
| 32 | /* Figure out what personality we are supposed to switch to ...
|
---|
| 33 | * we can be invoked as either:
|
---|
[2725] | 34 | * argv[0],argv[1] == "setarch","personality"
|
---|
| 35 | * argv[0] == "personality"
|
---|
[821] | 36 | */
|
---|
[2725] | 37 | if (ENABLE_SETARCH && applet_name[0] == 's'
|
---|
| 38 | && argv[1] && strncpy(argv[1], "linux", 5)
|
---|
| 39 | ) {
|
---|
| 40 | applet_name = argv[1];
|
---|
| 41 | argv++;
|
---|
| 42 | }
|
---|
| 43 | if (applet_name[5] == '6') /* linux64 */
|
---|
[821] | 44 | pers = PER_LINUX;
|
---|
[2725] | 45 | else if (applet_name[5] == '3') /* linux32 */
|
---|
[821] | 46 | pers = PER_LINUX32;
|
---|
[2725] | 47 | else
|
---|
| 48 | bb_show_usage();
|
---|
[821] | 49 |
|
---|
[2725] | 50 | argv++;
|
---|
[821] | 51 | if (argv[0] == NULL)
|
---|
| 52 | bb_show_usage();
|
---|
| 53 |
|
---|
| 54 | /* Try to set personality */
|
---|
| 55 | if (personality(pers) >= 0) {
|
---|
| 56 | /* Try to execute the program */
|
---|
[1765] | 57 | BB_EXECVP(argv[0], argv);
|
---|
[821] | 58 | }
|
---|
| 59 |
|
---|
[2725] | 60 | bb_simple_perror_msg_and_die(argv[0]);
|
---|
[821] | 61 | }
|
---|