[PATCH 3/3] sysctl: add -e option

Jeremy Kerr jk at ozlabs.org
Wed Nov 28 03:11:24 UTC 2007


The sysctl tool is missing the -e option, to supress warnings about
invalid keys. This is handy for distributions that ship an
/etc/sysctl.conf, which may contain keys that aren't valid for the
current kernel.

This change adds the -e option.

Signed-off-by: Jeremy Kerr <jk at ozlabs.org>

--
bloat-o-meter results on powerpc:
function                                             old     new   delta
sysctl_main                                          672     696     +24
sysctl_read_setting                                  468     488     +20
sysctl_write_setting                                 480     488      +8
packed_usage                                       23016   23005     -11
.rodata                                           124887  124876     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/2 up/down: 52/-22)             Total: 30 bytes


---

 include/usage.h |   11 ++++++-----
 procps/sysctl.c |   15 +++++++++++----
 2 files changed, 17 insertions(+), 9 deletions(-)

Index: busybox/procps/sysctl.c
===================================================================
--- busybox.orig/procps/sysctl.c
+++ busybox/procps/sysctl.c
@@ -33,6 +33,7 @@ enum { strlen_PROC_SYS = sizeof(PROC_SYS
 enum {
 	FLAG_TABLE_FORMAT	= 0x1,
 	FLAG_SHOW_KEYS		= 0x2,
+	FLAG_SHOW_KEY_ERRORS	= 0x4,
 };
 
 /* error messages */
@@ -68,7 +69,7 @@ int sysctl_main(int argc, char **argv) M
 int sysctl_main(int argc, char **argv)
 {
 	int retval = 0;
-	int flags = FLAG_SHOW_KEYS;
+	int flags = FLAG_SHOW_KEYS | FLAG_SHOW_KEY_ERRORS;
 	int write_mode = 0;
 	int switches_allowed = 1;
 
@@ -87,6 +88,9 @@ int sysctl_main(int argc, char **argv)
 				write_mode = 1;
 				switches_allowed = 0;
 				break;
+			case 'e':
+				flags &= ~FLAG_SHOW_KEY_ERRORS;
+				break;
 			case 'p':
 				argv++;
 				return sysctl_preload_file(((*argv /*&& **argv*/) ? *argv : ETC_SYSCTL_CONF),
@@ -212,7 +216,8 @@ static int sysctl_write_setting(const ch
 	if (fd < 0) {
 		switch (errno) {
 		case ENOENT:
-			bb_error_msg(ERR_INVALID_KEY, outname);
+			if (flags & FLAG_SHOW_KEY_ERRORS)
+				bb_error_msg(ERR_INVALID_KEY, outname);
 			break;
 		case EACCES:
 			bb_perror_msg(ERR_PERMISSION_DENIED, outname);
@@ -250,7 +255,8 @@ static int sysctl_read_setting(const cha
 	FILE *fp;
 
 	if (!*setting) {
-		bb_error_msg(ERR_INVALID_KEY, setting);
+		if (flags & FLAG_SHOW_KEY_ERRORS)
+			bb_error_msg(ERR_INVALID_KEY, setting);
 		return -1;
 	}
 
@@ -267,7 +273,8 @@ static int sysctl_read_setting(const cha
 	if (fp == NULL) {
 		switch (errno) {
 		case ENOENT:
-			bb_error_msg(ERR_INVALID_KEY, outname);
+			if (flags & FLAG_SHOW_KEY_ERRORS)
+				bb_error_msg(ERR_INVALID_KEY, outname);
 			break;
 		case EACCES:
 			bb_error_msg(ERR_PERMISSION_DENIED, outname);
Index: busybox/include/usage.h
===================================================================
--- busybox.orig/include/usage.h
+++ busybox/include/usage.h
@@ -3505,16 +3505,17 @@ USE_FEATURE_RUN_PARTS_FANCY("\n	-l	Print
        "Configure kernel parameters at runtime" \
        "\n\nOptions:\n" \
        "	-n	Disable printing of key names\n" \
+       "	-e	Don't warn about unknown keys\n" \
        "	-w	Change sysctl setting\n" \
        "	-p FILE	Load sysctl settings from FILE (default /etc/sysctl.conf)\n" \
        "	-a	Display all values\n" \
        "	-A	Display all values in table form"
 #define sysctl_example_usage \
-       "sysctl [-n] variable...\n" \
-       "sysctl [-n] -w variable=value...\n" \
-       "sysctl [-n] -a\n" \
-       "sysctl [-n] -p file	(default /etc/sysctl.conf)\n" \
-       "sysctl [-n] -A\n"
+       "sysctl [-n] [-e] variable...\n" \
+       "sysctl [-n] [-e] -w variable=value...\n" \
+       "sysctl [-n] [-e] -a\n" \
+       "sysctl [-n] [-e] -p file	(default /etc/sysctl.conf)\n" \
+       "sysctl [-n] [-e] -A\n"
 
 #define syslogd_trivial_usage \
        "[OPTION]..."



More information about the busybox mailing list