Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 3 | * linux32/linux64 allows for changing uname emulation. |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 4 | * |
| 5 | * Copyright 2002 Andi Kleen, SuSE Labs. |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 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 "" |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 22 | |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 23 | #include <sys/personality.h> |
| 24 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 25 | #include "libbb.h" |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 26 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 27 | int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 28 | int setarch_main(int argc UNUSED_PARAM, char **argv) |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 29 | { |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 30 | int pers; |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 31 | |
| 32 | /* Figure out what personality we are supposed to switch to ... |
| 33 | * we can be invoked as either: |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 34 | * argv[0],argv[1] == "setarch","personality" |
| 35 | * argv[0] == "personality" |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 36 | */ |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 37 | if (ENABLE_SETARCH && applet_name[0] == 's' |
| 38 | && argv[1] && strncpy(argv[1], "linux", 5) |
| 39 | ) { |
| 40 | applet_name = argv[1]; |
| 41 | argv++; |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 42 | } |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 43 | if (applet_name[5] == '6') /* linux64 */ |
| 44 | pers = PER_LINUX; |
| 45 | else if (applet_name[5] == '3') /* linux32 */ |
| 46 | pers = PER_LINUX32; |
| 47 | else |
| 48 | bb_show_usage(); |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 49 | |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 50 | argv++; |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 51 | if (argv[0] == NULL) |
| 52 | bb_show_usage(); |
| 53 | |
| 54 | /* Try to set personality */ |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 55 | if (personality(pers) >= 0) { |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 56 | /* Try to execute the program */ |
Denis Vlasenko | 1d76f43 | 2007-02-06 01:20:12 +0000 | [diff] [blame] | 57 | BB_EXECVP(argv[0], argv); |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 58 | } |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 59 | |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 60 | bb_simple_perror_msg_and_die(argv[0]); |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 61 | } |