sysctl: implement -q

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>
This commit is contained in:
Joshua Kahlenberg 2012-09-05 18:15:12 +02:00 committed by Denys Vlasenko
parent d1d794fd48
commit c439851438

View File

@ -12,21 +12,23 @@
*/
//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;