blob: 8213382e49e6febc9b741af1819ff4dd296316d3 [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 *
7 * Licensed under GPL v2 or later, see file License for details.
8*/
9
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000010#include <sys/personality.h>
11
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000012#include "libbb.h"
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000013
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000014int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000015int setarch_main(int argc UNUSED_PARAM, char **argv)
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000016{
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000017 int pers;
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000018
19 /* Figure out what personality we are supposed to switch to ...
20 * we can be invoked as either:
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000021 * argv[0],argv[1] == "setarch","personality"
22 * argv[0] == "personality"
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000023 */
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000024 if (ENABLE_SETARCH && applet_name[0] == 's'
25 && argv[1] && strncpy(argv[1], "linux", 5)
26 ) {
27 applet_name = argv[1];
28 argv++;
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000029 }
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000030 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 Frysinger0a6b0bf2006-02-21 04:26:52 +000036
Denis Vlasenko7fe21c62008-08-23 23:15:17 +000037 argv++;
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000038 if (argv[0] == NULL)
39 bb_show_usage();
40
41 /* Try to set personality */
Rob Landleyc30f4452006-03-20 02:20:18 +000042 if (personality(pers) >= 0) {
Rob Landleyc30f4452006-03-20 02:20:18 +000043 /* Try to execute the program */
Denis Vlasenko1d76f432007-02-06 01:20:12 +000044 BB_EXECVP(argv[0], argv);
Rob Landleyc30f4452006-03-20 02:20:18 +000045 }
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000046
Denis Vlasenko0c97c9d2007-10-01 11:58:38 +000047 bb_simple_perror_msg_and_die(argv[0]);
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000048}