summaryrefslogtreecommitdiffstats
path: root/sys-utils/setarch.c
diff options
context:
space:
mode:
authorSami Kerola2013-04-02 21:42:53 +0200
committerKarel Zak2013-04-05 14:03:07 +0200
commit5d1607e260be44a03067f09cc2034d2208c713de (patch)
treecc8a84b6b283a7c1b1e59cf11d53a8dcf3c721d1 /sys-utils/setarch.c
parentchrt: make command syntax easier to understand in usage() (diff)
downloadkernel-qcow2-util-linux-5d1607e260be44a03067f09cc2034d2208c713de.tar.gz
kernel-qcow2-util-linux-5d1607e260be44a03067f09cc2034d2208c713de.tar.xz
kernel-qcow2-util-linux-5d1607e260be44a03067f09cc2034d2208c713de.zip
setarch: add option to list settable architectures
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/setarch.c')
-rw-r--r--sys-utils/setarch.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index afa2d1bf1..f6c0e2061 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -110,6 +110,8 @@ show_help(void)
" -3, --3gb limits the used address space to a maximum of 3 GB\n"
" --4gb ignored (for backward compatibility only)\n"
" --uname-2.6 turns on UNAME26\n"));
+ printf(_(
+ " --list list settable architectures, and exit\n"));
printf(USAGE_SEPARATOR);
printf(USAGE_HELP);
@@ -136,7 +138,7 @@ show_version(void)
}
static int
-set_arch(const char *pers, unsigned long options)
+set_arch(const char *pers, unsigned long options, int list)
{
struct utsname un;
int i;
@@ -198,6 +200,12 @@ set_arch(const char *pers, unsigned long options)
{-1, NULL, NULL}
};
+ if (list) {
+ for(i = 0; transitions[i].target_arch != NULL; i++)
+ printf("%s\n", transitions[i].target_arch);
+ return 0;
+ }
+
for(i = 0; transitions[i].perval >= 0; i++)
if(!strcmp(pers, transitions[i].target_arch))
break;
@@ -273,10 +281,14 @@ int main(int argc, char *argv[])
show_help();
else if (!strcmp(p, "-V") || !strcmp(p, "--version"))
show_version();
+ else if (!strcmp(p, "--list")) {
+ set_arch(argv[0], 0L, 1);
+ return EXIT_SUCCESS;
+ }
}
#if defined(__sparc64__) || defined(__sparc__)
if (!strcmp(p, "sparc32bash")) {
- if (set_arch(p, 0L))
+ if (set_arch(p, 0L, 0))
err(EXIT_FAILURE, _("Failed to set personality to %s"), p);
execl("/bin/bash", NULL);
err(EXIT_FAILURE, _("failed to execute %s"), "/bin/bash");
@@ -337,7 +349,7 @@ int main(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (set_arch(p, options))
+ if (set_arch(p, options, 0))
err(EXIT_FAILURE, _("Failed to set personality to %s"), p);
if (!argc) {