Files
applets
arch
archival
console-tools
coreutils
debianutils
docs
e2fsprogs
editors
examples
findutils
include
init
ipsvd
libbb
libpwdgrp
loginutils
miscutils
modutils
networking
procps
runit
scripts
selinux
shell
sysklogd
testsuite
util-linux
Config.in
Kbuild
dmesg.c
fbset.c
fdformat.c
fdisk.c
fdisk_aix.c
fdisk_osf.c
fdisk_sgi.c
fdisk_sun.c
freeramdisk.c
fsck_minix.c
getopt.c
hexdump.c
hwclock.c
ipcrm.c
ipcs.c
losetup.c
mdev.c
minix.h
mkfs_minix.c
mkswap.c
more.c
mount.c
pivot_root.c
rdate.c
readprofile.c
setarch.c
swaponoff.c
switch_root.c
umount.c
.indent.pro
AUTHORS
Config.in
INSTALL
LICENSE
Makefile
Makefile.custom
Makefile.flags
Makefile.help
README
TODO
TODO_config_nommu
busybox/util-linux/setarch.c

54 lines
1.1 KiB
C

/* vi: set sw=4 ts=4: */
/*
* Linux32/linux64 allows for changing uname emulation.
*
* Copyright 2002 Andi Kleen, SuSE Labs.
*
* Licensed under GPL v2 or later, see file License for details.
*/
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <sys/personality.h>
#include "busybox.h"
int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv);
int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv)
{
int pers = -1;
/* Figure out what personality we are supposed to switch to ...
* we can be invoked as either:
* argv[0],argv[1] -> "setarch","personality"
* argv[0] -> "personality"
*/
retry:
if (argv[0][5] == '6') /* linux64 */
pers = PER_LINUX;
else if (argv[0][5] == '3') /* linux32 */
pers = PER_LINUX32;
else if (pers == -1 && argv[1] != NULL) {
pers = PER_LINUX32;
++argv;
goto retry;
}
/* make user actually gave us something to do */
++argv;
if (argv[0] == NULL)
bb_show_usage();
/* Try to set personality */
if (personality(pers) >= 0) {
/* Try to execute the program */
BB_EXECVP(argv[0], argv);
}
bb_perror_msg_and_die("%s", argv[0]);
}