]> granicus.if.org Git - procps-ng/commitdiff
sysctl: do not report set key in case `close_stream` fails
authorPatrick Steinhardt <ps@pks.im>
Tue, 29 May 2018 11:29:03 +0000 (13:29 +0200)
committerCraig Small <csmall@enc.com.au>
Mon, 4 Mar 2019 10:55:24 +0000 (21:55 +1100)
As we're using buffered I/O when writing kernel parameters, write errors
may get delayed until we close the `FILE` stream. As we are currently
outputting the key that is to be set disregarding the return value of
`close_stream`, we may end up in a situation where we report error and
success:

    $ sysctl kernel.printk_ratelimit=100000000000000
    sysctl: setting key "kernel.printk_ratelimit": error code 22
    kernel.printk_ratelimit = 100000000000000

Fix the issue by only outputting the updated value in case
`close_stream` does not report an error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
sysctl.c

index 5bae47fed51ff155f731583f331c29db3eb365ac..e5ca8038049c1358db873096491961404e7b9e6d 100644 (file)
--- a/sysctl.c
+++ b/sysctl.c
@@ -462,7 +462,7 @@ static int WriteSetting(const char *setting)
                        rc = 0;
                if (close_stream(fp) != 0)
                        xwarn(_("setting key \"%s\""), outname);
-               if (rc == 0 && !Quiet) {
+               else if (rc == 0 && !Quiet) {
                        if (NameOnly) {
                                fprintf(stdout, "%s\n", outname);
                        } else {