From 5d1607e260be44a03067f09cc2034d2208c713de Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Tue, 2 Apr 2013 20:42:53 +0100 Subject: setarch: add option to list settable architectures Signed-off-by: Sami Kerola --- sys-utils/setarch.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'sys-utils/setarch.c') 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) { -- cgit v1.2.3-55-g7522