sysctl: doesn't ignore failures to set a value for config lines starting with "-"

Forwarding Gentoo Linux bug https://bugs.gentoo.org/969014:

I have the following line in /usr/lib/sysctl.d/50-default.conf:

-net.core.default_qdisc = fq_codel

However, when the CONFIG_NET_SCH_FQ_CODEL kernel option is missing, sysctl returns a nonzero exit status, in spite of the config line starting with a "-" sign:

# sysctl -q --system
sysctl: setting key "net.core.default_qdisc": No such file or directory
# echo $?
1

AFAICS, WriteSetting fails when calling close_stream, because the kernel rejects the unknown value and returns ENOENT (i.e. there's output pending).

The patch below fixes the problem for me.

--- procps-ng-4.0.5/src/sysctl.c
+++ procps-ng-4.0.5/src/sysctl.c
@@ -623,9 +623,12 @@ static int WriteSetting(
             if (0 < fprintf(fp, "%s\n", value))
                 rc = EXIT_SUCCESS;
             if (close_stream(fp) != 0) {
-                xwarn(_("setting key \"%s\""), dotted_key);
+                xwarn(_("setting key \"%s\"%s"),
+                      dotted_key, (ignore_failure?_(", ignoring"):""));
 		free(dotted_key);
-                return EXIT_FAILURE;
+                if (!ignore_failure)
+                    rc = EXIT_FAILURE;
+                return rc;
             }
         }
     }
Assignee Loading
Time tracking Loading