chiark / gitweb /
sysctl: avoiding exiting with error on -EEXIST
authorDave Reisner <dreisner@archlinux.org>
Sat, 6 Oct 2012 20:32:17 +0000 (16:32 -0400)
committerDave Reisner <dreisner@archlinux.org>
Sat, 6 Oct 2012 20:41:30 +0000 (16:41 -0400)
If the final key in any sysctl.d file is a duplicate, systemd-sysctl
will exit with an error (and no explaination why). Ignore this, as
duplicate keys are to be expected when overriding settings in the
directory hierarchy.

src/sysctl/sysctl.c

index e77f496..a68d67f 100644 (file)
@@ -167,9 +167,13 @@ static int parse_file(const char *path, bool ignore_enoent) {
 
                 r = hashmap_put(sysctl_options, property, new_value);
                 if (r < 0) {
-                        if (r == -EEXIST)
+                        if (r == -EEXIST) {
+                                /* ignore this "error" to avoid returning it
+                                 * for the function when this is the last key
+                                 * in the file being parsed. */
+                                r = 0;
                                 log_debug("Skipping previously assigned sysctl variable %s", property);
-                        else
+                        else
                                 log_error("Failed to add sysctl variable %s to hashmap: %s", property, strerror(-r));
 
                         free(property);