blob: f6433d6ba5fb6033afd670fda1baa6c76f439f53 [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
10#include <stdlib.h>
11#include <unistd.h>
12#include <string.h>
13#include <errno.h>
14#include <stdio.h>
15#include <sys/personality.h>
16
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000017#include "libbb.h"
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000018
Denis Vlasenko06af2162007-02-03 17:28:39 +000019int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv);
Rob Landleyc30f4452006-03-20 02:20:18 +000020int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv)
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000021{
22 int pers = -1;
23
24 /* Figure out what personality we are supposed to switch to ...
25 * we can be invoked as either:
26 * argv[0],argv[1] -> "setarch","personality"
27 * argv[0] -> "personality"
28 */
29retry:
Rob Landleyc30f4452006-03-20 02:20:18 +000030 if (argv[0][5] == '6') /* linux64 */
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000031 pers = PER_LINUX;
Rob Landleyc30f4452006-03-20 02:20:18 +000032 else if (argv[0][5] == '3') /* linux32 */
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000033 pers = PER_LINUX32;
34 else if (pers == -1 && argv[1] != NULL) {
35 pers = PER_LINUX32;
36 ++argv;
37 goto retry;
38 }
39
40 /* make user actually gave us something to do */
41 ++argv;
42 if (argv[0] == NULL)
43 bb_show_usage();
44
45 /* Try to set personality */
Rob Landleyc30f4452006-03-20 02:20:18 +000046 if (personality(pers) >= 0) {
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000047
Rob Landleyc30f4452006-03-20 02:20:18 +000048 /* Try to execute the program */
Denis Vlasenko1d76f432007-02-06 01:20:12 +000049 BB_EXECVP(argv[0], argv);
Rob Landleyc30f4452006-03-20 02:20:18 +000050 }
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000051
"Vladimir N. Oleynik"73804d62006-02-28 08:23:27 +000052 bb_perror_msg_and_die("%s", argv[0]);
Mike Frysinger0a6b0bf2006-02-21 04:26:52 +000053}