blob: dbc02de5ed61bb7fa246c97d82c2b03ac49e0b23 [file] [log] [blame]
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Linux32/linux64 allows for changing uname emulation.
4 *
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;
Rob Landleyc30f4452006-03-20 02:20:18 +000015int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv)
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000016{
17 int pers = -1;
18
19 /* Figure out what personality we are supposed to switch to ...
20 * we can be invoked as either:
21 * argv[0],argv[1] -> "setarch","personality"
22 * argv[0] -> "personality"
23 */
24retry:
Rob Landleyc30f4452006-03-20 02:20:18 +000025 if (argv[0][5] == '6') /* linux64 */
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000026 pers = PER_LINUX;
Rob Landleyc30f4452006-03-20 02:20:18 +000027 else if (argv[0][5] == '3') /* linux32 */
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000028 pers = PER_LINUX32;
29 else if (pers == -1 && argv[1] != NULL) {
30 pers = PER_LINUX32;
31 ++argv;
32 goto retry;
33 }
34
35 /* make user actually gave us something to do */
36 ++argv;
37 if (argv[0] == NULL)
38 bb_show_usage();
39
40 /* Try to set personality */
Rob Landleyc30f4452006-03-20 02:20:18 +000041 if (personality(pers) >= 0) {
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000042
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}