source: MondoRescue/branches/3.3/mindi-busybox/util-linux/setarch.c@ 3621

Last change on this file since 3621 was 3621, checked in by Bruno Cornec, 7 years ago

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

File size: 2.5 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
[2725]3 * linux32/linux64 allows for changing uname emulation.
[821]4 *
5 * Copyright 2002 Andi Kleen, SuSE Labs.
6 *
[2725]7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[3232]8 */
[3621]9//config:config SETARCH
10//config: bool "setarch"
11//config: default y
12//config: select PLATFORM_LINUX
13//config: help
14//config: The linux32 utility is used to create a 32bit environment for the
15//config: specified program (usually a shell). It only makes sense to have
16//config: this util on a system that supports both 64bit and 32bit userland
17//config: (like amd64/x86, ppc64/ppc, sparc64/sparc, etc...).
[821]18
[3621]19//applet:IF_SETARCH(APPLET(setarch, BB_DIR_BIN, BB_SUID_DROP))
20//applet:IF_SETARCH(APPLET_ODDNAME(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32))
21//applet:IF_SETARCH(APPLET_ODDNAME(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64))
22
23//kbuild:lib-$(CONFIG_SETARCH) += setarch.o
24
[3232]25//usage:#define setarch_trivial_usage
[3621]26//usage: "PERSONALITY [-R] PROG ARGS"
[3232]27//usage:#define setarch_full_usage "\n\n"
[3621]28//usage: "PERSONALITY may be:"
29//usage: "\n"" linux32 Set 32bit uname emulation"
30//usage: "\n"" linux64 Set 64bit uname emulation"
31//usage: "\n"
32//usage: "\n"" -R Disable address space randomization"
[3232]33//usage:
34//usage:#define linux32_trivial_usage NOUSAGE_STR
35//usage:#define linux32_full_usage ""
36//usage:
37//usage:#define linux64_trivial_usage NOUSAGE_STR
38//usage:#define linux64_full_usage ""
39
[3621]40#include "libbb.h"
[821]41#include <sys/personality.h>
42
[3621]43#ifndef ADDR_NO_RANDOMIZE
44# define ADDR_NO_RANDOMIZE 0x0040000
45#endif
[821]46
[2725]47int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
48int setarch_main(int argc UNUSED_PARAM, char **argv)
[821]49{
[3621]50 unsigned opts;
51 unsigned long pers;
[821]52
53 /* Figure out what personality we are supposed to switch to ...
54 * we can be invoked as either:
[2725]55 * argv[0],argv[1] == "setarch","personality"
56 * argv[0] == "personality"
[821]57 */
[2725]58 if (ENABLE_SETARCH && applet_name[0] == 's'
[3621]59 && argv[1] && is_prefixed_with(argv[1], "linux")
[2725]60 ) {
61 applet_name = argv[1];
62 argv++;
63 }
64 if (applet_name[5] == '6') /* linux64 */
[821]65 pers = PER_LINUX;
[2725]66 else if (applet_name[5] == '3') /* linux32 */
[821]67 pers = PER_LINUX32;
[2725]68 else
69 bb_show_usage();
[821]70
[3621]71 opts = getopt32(argv, "+R"); /* '+': stop at first non-option */
72 if (opts)
73 pers |= ADDR_NO_RANDOMIZE;
[821]74
75 /* Try to set personality */
[3621]76 if (personality(pers) < 0)
77 bb_perror_msg_and_die("personality(0x%lx)", pers);
[821]78
[3621]79 argv += optind;
80 if (!argv[0])
81 (--argv)[0] = (char*)"/bin/sh";
82
83 /* Try to execute the program */
84 BB_EXECVP_or_die(argv);
[821]85}
Note: See TracBrowser for help on using the repository browser.