[PATCH] setarch: add long options to setarch and update manpage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>     * TODO: add long options for all flags

I've done this, and the manpage also has been updated. But I'm not sure that
the names of long options are appropriate.

Signed-off-by: Li Zefan <lizf@xxxxxxxxxxxxxx>
---
diff --git a/sys-utils/setarch.8 b/sys-utils/setarch.8
index 16946cf..02f1ca8 100644
--- a/sys-utils/setarch.8
+++ b/sys-utils/setarch.8
@@ -17,7 +17,7 @@ as machine type. It also allows to set various personality options. The default
 is /bin/sh.
 .SH OPTIONS
 .TP
-.I "\-v"
+.I "\-v," "\-\-verbose"
 Be verbose.
 .TP
 .I "\-h," "\-\-help"
@@ -26,36 +26,38 @@ Display help (it is also displayed when setarch takes no arguments).
 .I "\-3," "\-\-3gb"
 Specifies that processes should use a maximum of 3GB of address space on systems where it is supported (ADDR_LIMIT_3GB).
 .TP
-.I "\-B"
+.I "\-B," "\-\-32bit"
 Turns on ADDR_LIMIT_32BIT.
 .TP
-.I "\-F"
+.I "\-F," "\-\-fdpic-funcptrs"
 Userspace function pointers point to descriptors (turns on FDPIC_FUNCPTRS).
 .TP
-.I "\-I"
+.I "\-I," "\-\-short-inode"
 Turns on SHORT_INODE.
 .TP
-.I "\-L"
+.I "\-L," "\-\-addr-compat-layout"
 Changes the way virtual memory is allocated (turns on the ADDR_COMPAT_LAYOUT).
 .TP
-.I "\-R"
+.I "\-R," "\-\-addr-no-randomize"
 Disables randomization of the virtual address space (turns on ADDR_NO_RANDOMIZE).
 .TP
-.I "\-S"
+.I "\-S," "\-\-whole-seconds"
 Turns on WHOLE_SECONDS.
 .TP
-.I "\-T"
+.I "\-T," "\-\-sticky-timeouts"
 Turns on STICKY_TIMEOUTS.
 .TP
-.I "\-X"
+.I "\-X," "\-\-read-implies-exec"
 Turns on READ_IMPLIES_EXEC.
 .TP
-.I "\-Z"
+.I "\-Z," "\-\-mmap-page-zero"
 Turns on MMAP_PAGE_ZERO.
 .SH EXAMPLES
 setarch ppc32 rpmbuild --target=ppc --rebuild foo.src.rpm
 .br
 setarch ppc32 -v -vL3 rpmbuild --target=ppc --rebuild bar.src.rpm
+.br
+setarch ppc32 --32bit rpmbuild --target=ppc --rebuild bar.src.rpm
 .SH AUTHOR
 Elliot Lee <sopwith@xxxxxxxxxx>
 .br
diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index 6eba24a..76f1af0 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -42,20 +42,21 @@
 #define set_pers(pers) ((long)syscall(SYS_personality, pers))

 struct {
-    char c;
+    char short_opt;
+    const char *long_opt;
     const char *name;
     unsigned int option;
 } flags[] = {
-    {'R', "ADDR_NO_RANDOMIZE",  0x0040000},
-    {'F', "FDPIC_FUNCPTRS",     0x0080000},
-    {'Z', "MMAP_PAGE_ZERO",     0x0100000},
-    {'L', "ADDR_COMPAT_LAYOUT", 0x0200000},
-    {'X', "READ_IMPLIES_EXEC",  0x0400000},
-    {'B', "ADDR_LIMIT_32BIT",   0x0800000},
-    {'I', "SHORT_INODE",        0x1000000},
-    {'S', "WHOLE_SECONDS",      0x2000000},
-    {'T', "STICKY_TIMEOUTS",    0x4000000},
-    {'3', "ADDR_LIMIT_3GB",     0x8000000}
+    {'R', "addr-no-randomize",  "ADDR_NO_RANDOMIZE",  0x0040000},
+    {'F', "fdpic-funcptrs",     "FDPIC_FUNCPTRS",     0x0080000},
+    {'Z', "mmap-page-zero",     "MMAP_PAGE_ZERO",     0x0100000},
+    {'L', "addr-compat-layout", "ADDR_COMPAT_LAYOUT", 0x0200000},
+    {'X', "read-implies-exec",  "READ_IMPLIES_EXEC",  0x0400000},
+    {'B', "32bit",              "ADDR_LIMIT_32BIT",   0x0800000},
+    {'I', "short-inode",        "SHORT_INODE",        0x1000000},
+    {'S', "whole-seconds",      "WHOLE_SECONDS",      0x2000000},
+    {'T', "sticky-timeouts",    "STICKY_TIMEOUTS",    0x4000000},
+    {'3', "3gb",                "ADDR_LIMIT_3GB",     0x8000000}
 };

 static void __attribute__((__noreturn__))
@@ -71,7 +72,8 @@ show_help(void)
          p, !strcmp(p, "setarch") ? " <arch>" : "");

   for (f = 0; f < sizeof(flags) / sizeof(flags[0]); f++)
-    printf(_("\t-%c\tEnable %s\n"), flags[f].c, flags[f].name);
+    printf(_("\t-%c, --%-24sEnable %s\n"), flags[f].short_opt,
+            flags[f].long_opt, flags[f].name);

   printf(_("\nFor more information see setarch(8).\n"));
   exit(EXIT_SUCCESS);
@@ -206,23 +208,41 @@ int main(int argc, char *argv[])
    }
   #endif
   for (argv++, argc--; argc && argv[0][0] == '-'; argv++, argc--) {
-    int n, unknown = 1;
+    int n, f, unknown = 1;
     const char *arg = argv[0];

     if (!strcmp(arg, "--help"))
       show_help();

     /* compatibitity with an old Debian setarch implementation
-     * TODO: add long options for all flags
      */
-    if (!strcmp(arg, "--3gb"))
-      arg="-3";
-    else if (!strcmp(arg, "--4gb"))
+    if (!strcmp(arg, "--4gb"))
       continue;                                /* just ignore this one */

-    for (n = 1; arg[n]; n++) {
-      int f;
+    /* long option name */
+    if (arg[1] == '-') {
+      arg += 2;
+
+      if (!strcmp(arg, "verbose")) {
+        verbose = 1;
+        continue;
+
+      for (f = 0; f < sizeof(flags) / sizeof(flags[0]); f++) {
+        if (!strcmp(arg, flags[f].long_opt)) {
+          if (verbose)
+            fprintf(stderr, _("Switching on %s.\n"), flags[f].name);
+          options |= flags[f].option;
+          unknown = 0;
+          break;
+        }
+      }
+      if (unknown)
+        error(0, 0, _("Unknown option `%c' ignored"), arg[n]);
+      continue;
+    }

+    /* short option name */
+    for (n = 1; arg[n]; n++) {
       if (arg[n] == 'v') {
        verbose = 1;
        continue;
@@ -232,7 +252,7 @@ int main(int argc, char *argv[])
        show_help();

       for (f = 0; f < sizeof(flags) / sizeof(flags[0]); f++) {
-       if (arg[n] == flags[f].c) {
+       if (arg[n] == flags[f].short_opt) {
          if (verbose)
            fprintf(stderr, _("Switching on %s.\n"), flags[f].name);
          options |= flags[f].option;
---


-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux