sysctl: do report EACCES errors on write
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 9 Jun 2020 13:58:32 +0000 (15:58 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 9 Jun 2020 13:58:32 +0000 (15:58 +0200)
function                                             old     new   delta
sysctl_act_recursive                                 165     179     +14
sysctl_act_on_setting                                467     471      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 18/0)               Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
procps/sysctl.c
testsuite/unexpand.tests

index 6d77185caec8ef5b2c6887b2a1df85f749acab13..e16b119e98d4b8e5ea5058ad48877d9157ffb518 100644 (file)
@@ -169,13 +169,15 @@ static int sysctl_act_on_setting(char *setting)
 
        if (fd < 0) {
                switch (errno) {
-               case EACCES:
-                       /* Happens for write-only settings, e.g. net.ipv6.route.flush */
-                       goto end;
                case ENOENT:
                        if (option_mask32 & FLAG_SHOW_KEY_ERRORS)
                                bb_error_msg("error: '%s' is an unknown key", outname);
                        break;
+               case EACCES:
+                       /* Happens for write-only settings, e.g. net.ipv6.route.flush */
+                       if (!writing)
+                               goto end;
+                       /* fall through */
                default:
                        bb_perror_msg("error %sing key '%s'",
                                        writing ?
@@ -236,6 +238,7 @@ static int sysctl_act_recursive(const char *path)
        int retval = 0;
 
        if (!(option_mask32 & FLAG_WRITE)
+        && !strchr(path, '=')  /* do not try to resurse on "var=val" */
         && stat(path, &buf) == 0
         && S_ISDIR(buf.st_mode)
        ) {
index 4ab693ec842afcd1a85bfe8fba52c777d92fe4bb..aeaae13f01df53fab988be23ecd337f5a9d0a896 100755 (executable)
@@ -33,8 +33,8 @@ testing "unexpand case 8" "unexpand" \
 
 testcase()
 {
-    testing "unexpand flags $*" "unexpand $*" \
-        "$want" "" '        a       b    c'
+       testing "unexpand flags $*" "unexpand $*" \
+               "$want" "" '        a       b    c'
 }
 
 # tabs=8, Convert only leading sequences of blanks