]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
setarch: add option to list settable architectures
authorSami Kerola <kerolasa@iki.fi>
Tue, 2 Apr 2013 19:42:53 +0000 (20:42 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 5 Apr 2013 12:03:07 +0000 (14:03 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/setarch.8
sys-utils/setarch.c

index e836924cd212891dc13d7b1668bfbdf5e1468221..ea885c4ba6f771a489993fa8db5c1ac64477ac90 100644 (file)
@@ -41,6 +41,9 @@ Specifies that processes should use a maximum of 3GB of address space on systems
 \fB\-\-4gb\fR
 Ignored (for backward compatibility only).
 .TP
+\fB\-\-list\fR
+List architectures that can be set.
+.TP
 \fB\-B\fR, \fB\-\-32bit\fR
 Turns on ADDR_LIMIT_32BIT.
 .TP
index afa2d1bf1ce6334b64e5254b5ae7f549bb007e75..f6c0e206110a852338df057b06d851b0947d625f 100644 (file)
@@ -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) {