sysctl: implement -q
authorJoshua Kahlenberg <jbkberg@gmail.com>
Wed, 5 Sep 2012 16:15:12 +0000 (18:15 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 5 Sep 2012 16:15:12 +0000 (18:15 +0200)
function                                             old     new   delta
packed_usage                                       29208   29223     +15
sysctl_act_recursive                                 605     598      -7
sysctl_main                                          233     222     -11

Signed-off-by: Joshua Kahlenberg <jbkberg@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
procps/sysctl.c

index 5296d0f5813c10dfe8fd326177e18e88cf368418..8786568621cd88f2e9505c21ce4670c28dab0f80 100644 (file)
  */
 
 //usage:#define sysctl_trivial_usage
-//usage:       "[OPTIONS] [VALUE]..."
+//usage:       "[OPTIONS] [KEY[=VALUE]]..."
 //usage:#define sysctl_full_usage "\n\n"
-//usage:       "Configure kernel parameters at runtime\n"
-//usage:     "\n       -n      Don't print key names"
+//usage:       "Show/set kernel parameters\n"
 //usage:     "\n       -e      Don't warn about unknown keys"
-//usage:     "\n       -w      Change sysctl setting"
-//usage:     "\n       -p FILE Load sysctl settings from FILE (default /etc/sysctl.conf)"
-//usage:     "\n       -a      Display all values"
-//usage:     "\n       -A      Display all values in table form"
+//usage:     "\n       -n      Don't show key names"
+//usage:     "\n       -a      Show all values"
+/* Same as -a, no need to show it */
+/* //usage:     "\n    -A      Show all values in table form" */
+//usage:     "\n       -w      Set values"
+//usage:     "\n       -p FILE Set values from FILE (default /etc/sysctl.conf)"
+//usage:     "\n       -q      Set values silently"
 //usage:
 //usage:#define sysctl_example_usage
 //usage:       "sysctl [-n] [-e] variable...\n"
-//usage:       "sysctl [-n] [-e] -w variable=value...\n"
+//usage:       "sysctl [-n] [-e] [-q] -w variable=value...\n"
 //usage:       "sysctl [-n] [-e] -a\n"
-//usage:       "sysctl [-n] [-e] -p file       (default /etc/sysctl.conf)\n"
+//usage:       "sysctl [-n] [-e] [-q] -p file  (default /etc/sysctl.conf)\n"
 //usage:       "sysctl [-n] [-e] -A\n"
 
 #include "libbb.h"
@@ -37,9 +39,11 @@ enum {
        FLAG_TABLE_FORMAT    = 1 << 2, /* not implemented */
        FLAG_SHOW_ALL        = 1 << 3,
        FLAG_PRELOAD_FILE    = 1 << 4,
+/* TODO: procps 3.2.8 seems to not require -w for KEY=VAL to work: */
        FLAG_WRITE           = 1 << 5,
+       FLAG_QUIET           = 1 << 6,
 };
-#define OPTION_STR "neAapw"
+#define OPTION_STR "neAapwq"
 
 static void sysctl_dots_to_slashes(char *name)
 {
@@ -144,9 +148,11 @@ static int sysctl_act_on_setting(char *setting)
 //TODO: procps 3.2.7 writes "value\n", note trailing "\n"
                xwrite_str(fd, value);
                close(fd);
-               if (option_mask32 & FLAG_SHOW_KEYS)
-                       printf("%s = ", outname);
-               puts(value);
+               if (!(option_mask32 & FLAG_QUIET)) {
+                       if (option_mask32 & FLAG_SHOW_KEYS)
+                               printf("%s = ", outname);
+                       puts(value);
+               }
        } else {
                char c;