blob: 7b9421af1eefb54debe2affbb4b5fdeb9a2cbdc1 [file] [log] [blame]
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +00001/* vi: set sw=4 ts=4: */
2/*
Denis Vlasenko7fe21c62008-08-23 23:15:17 +00003 * linux32/linux64 allows for changing uname emulation.
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +00004 *
5 * Copyright 2002 Andi Kleen, SuSE Labs.
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Pere Orga5bc8c002011-04-11 03:29:49 +02008 */
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 Frysinger0a6b0bf2006-02-21 04:26:52 +000022
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000023#include <sys/personality.h>
24
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000025#include "libbb.h"
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000026
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000027int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000028int setarch_main(int argc UNUSED_PARAM, char **argv)
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000029{
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000030 int pers;
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000031
32 /* Figure out what personality we are supposed to switch to ...
33 * we can be invoked as either:
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000034 * argv[0],argv[1] == "setarch","personality"
35 * argv[0] == "personality"
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000036 */
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000037 if (ENABLE_SETARCH && applet_name[0] == 's'
38 && argv[1] && strncpy(argv[1], "linux", 5)
39 ) {
40 applet_name = argv[1];
41 argv++;
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000042 }
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000043 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 Frysinger0a6b0bf2006-02-21 04:26:52 +000049
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000050 argv++;
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000051 if (argv[0] == NULL)
52 bb_show_usage();
53
54 /* Try to set personality */
Rob Landleyc30f4452006-03-20 02:20:18 +000055 if (personality(pers) >= 0) {
Rob Landleyc30f4452006-03-20 02:20:18 +000056 /* Try to execute the program */
Denis Vlasenko1d76f432007-02-06 01:20:12 +000057 BB_EXECVP(argv[0], argv);
Rob Landleyc30f4452006-03-20 02:20:18 +000058 }
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000059
Denis Vlasenko0c97c9d2007-10-01 11:58:38 +000060 bb_simple_perror_msg_and_die(argv[0]);
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000061}