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 | * |
| 7 | * Licensed under GPL v2 or later, see file License for details. |
| 8 | */ |
| 9 | |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 10 | #include <sys/personality.h> |
| 11 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 12 | #include "libbb.h" |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 13 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 14 | int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 15 | int setarch_main(int argc UNUSED_PARAM, char **argv) |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 16 | { |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 17 | int pers; |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 18 | |
| 19 | /* Figure out what personality we are supposed to switch to ... |
| 20 | * we can be invoked as either: |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 21 | * argv[0],argv[1] == "setarch","personality" |
| 22 | * argv[0] == "personality" |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 23 | */ |
Denis Vlasenko | 7fe21c6 | 2008-08-23 23:15:17 +0000 | [diff] [blame] | 24 | if (ENABLE_SETARCH && applet_name[0] == 's' |
| 25 | && argv[1] && strncpy(argv[1], "linux", 5) |
| 26 | ) { |
| 27 | applet_name = argv[1]; |
| 28 | 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 | if (applet_name[5] == '6') /* linux64 */ |
| 31 | pers = PER_LINUX; |
| 32 | else if (applet_name[5] == '3') /* linux32 */ |
| 33 | pers = PER_LINUX32; |
| 34 | else |
| 35 | bb_show_usage(); |
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 | argv++; |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 38 | if (argv[0] == NULL) |
| 39 | bb_show_usage(); |
| 40 | |
| 41 | /* Try to set personality */ |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 42 | if (personality(pers) >= 0) { |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 43 | /* Try to execute the program */ |
Denis Vlasenko | 1d76f43 | 2007-02-06 01:20:12 +0000 | [diff] [blame] | 44 | BB_EXECVP(argv[0], argv); |
Rob Landley | c30f445 | 2006-03-20 02:20:18 +0000 | [diff] [blame] | 45 | } |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 46 | |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 47 | bb_simple_perror_msg_and_die(argv[0]); |
Mike Frysinger | 0a6b0bf | 2006-02-21 04:26:52 +0000 | [diff] [blame] | 48 | } |