teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0031-sysctl-allow-overwriting-of-values-specified-in-late.patch

Harald Hoyer fe20ad
From e3435020cb50691abac53965a7ddf6f66991926f Mon Sep 17 00:00:00 2001
Harald Hoyer fe20ad
From: Kay Sievers <kay@vrfy.org>
Harald Hoyer fe20ad
Date: Thu, 15 Aug 2013 18:35:03 +0200
Harald Hoyer fe20ad
Subject: [PATCH] sysctl: allow overwriting of values specified in "later"
Harald Hoyer fe20ad
 files
Harald Hoyer fe20ad
Harald Hoyer fe20ad
---
Harald Hoyer fe20ad
 NEWS                            |  9 +++++++++
Harald Hoyer fe20ad
 src/sysctl/sysctl.c             | 16 ++++++++--------
Harald Hoyer fe20ad
 units/systemd-sysctl.service.in |  1 -
Harald Hoyer fe20ad
 3 files changed, 17 insertions(+), 9 deletions(-)
Harald Hoyer fe20ad
Harald Hoyer fe20ad
diff --git a/NEWS b/NEWS
Harald Hoyer fe20ad
index f9929d0..9d989d3 100644
Harald Hoyer fe20ad
--- a/NEWS
Harald Hoyer fe20ad
+++ b/NEWS
Harald Hoyer fe20ad
@@ -2,6 +2,15 @@ systemd System and Service Manager
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
 CHANGES WITH 206:
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
+        * The systemd-sysctl tool does no longer natively read the
Harald Hoyer fe20ad
+          file /etc/sysctl.conf. If desired, the file should be
Harald Hoyer fe20ad
+          symlinked from /etc/sysctl.d/99-sysctl.conf. Apart from
Harald Hoyer fe20ad
+          providing legacy support by a symlink rather than built-in
Harald Hoyer fe20ad
+          code, it also makes the otherwise hidden order of application
Harald Hoyer fe20ad
+          of the different files visible.
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
+CHANGES WITH 206:
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
         * The documentation has been updated to cover the various new
Harald Hoyer fe20ad
           concepts introduced with 205.
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
Harald Hoyer fe20ad
index db18dd9..b5670db 100644
Harald Hoyer fe20ad
--- a/src/sysctl/sysctl.c
Harald Hoyer fe20ad
+++ b/src/sysctl/sysctl.c
Harald Hoyer fe20ad
@@ -135,6 +135,7 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
Harald Hoyer fe20ad
         log_debug("parse: %s\n", path);
Harald Hoyer fe20ad
         while (!feof(f)) {
Harald Hoyer fe20ad
                 char l[LINE_MAX], *p, *value, *new_value, *property, *existing;
Harald Hoyer fe20ad
+                void *v;
Harald Hoyer fe20ad
                 int k;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
                 if (!fgets(l, sizeof(l), f)) {
Harald Hoyer fe20ad
@@ -167,13 +168,14 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
Harald Hoyer fe20ad
                 p = normalize_sysctl(strstrip(p));
Harald Hoyer fe20ad
                 value = strstrip(value);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-                existing = hashmap_get(sysctl_options, p);
Harald Hoyer fe20ad
+                existing = hashmap_get2(sysctl_options, p, &v);
Harald Hoyer fe20ad
                 if (existing) {
Harald Hoyer fe20ad
-                        if (!streq(value, existing))
Harald Hoyer fe20ad
-                                log_warning("Duplicate assignment of %s in file '%s', ignoring.",
Harald Hoyer fe20ad
-                                            p, path);
Harald Hoyer fe20ad
+                        if (streq(value, existing))
Harald Hoyer fe20ad
+                                continue;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-                        continue;
Harald Hoyer fe20ad
+                        log_info("Overwriting earlier assignment of %s in file '%s'.", p, path);
Harald Hoyer fe20ad
+                        free(hashmap_remove(sysctl_options, p));
Harald Hoyer fe20ad
+                        free(v);
Harald Hoyer fe20ad
                 }
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
                 property = strdup(p);
Harald Hoyer fe20ad
@@ -188,7 +190,7 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
                 k = hashmap_put(sysctl_options, property, new_value);
Harald Hoyer fe20ad
                 if (k < 0) {
Harald Hoyer fe20ad
-                        log_error("Failed to add sysctl variable %s to hashmap: %s", property, strerror(-r));
Harald Hoyer fe20ad
+                        log_error("Failed to add sysctl variable %s to hashmap: %s", property, strerror(-k));
Harald Hoyer fe20ad
                         free(property);
Harald Hoyer fe20ad
                         free(new_value);
Harald Hoyer fe20ad
                         return k;
Harald Hoyer fe20ad
@@ -304,8 +306,6 @@ int main(int argc, char *argv[]) {
Harald Hoyer fe20ad
                         goto finish;
Harald Hoyer fe20ad
                 }
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-                r = parse_file(sysctl_options, "/etc/sysctl.conf", true);
Harald Hoyer fe20ad
-
Harald Hoyer fe20ad
                 STRV_FOREACH(f, files) {
Harald Hoyer fe20ad
                         k = parse_file(sysctl_options, *f, true);
Harald Hoyer fe20ad
                         if (k < 0 && r == 0)
Harald Hoyer fe20ad
diff --git a/units/systemd-sysctl.service.in b/units/systemd-sysctl.service.in
Harald Hoyer fe20ad
index 45e1ceb..5baf22c 100644
Harald Hoyer fe20ad
--- a/units/systemd-sysctl.service.in
Harald Hoyer fe20ad
+++ b/units/systemd-sysctl.service.in
Harald Hoyer fe20ad
@@ -13,7 +13,6 @@ Conflicts=shutdown.target
Harald Hoyer fe20ad
 After=systemd-readahead-collect.service systemd-readahead-replay.service
Harald Hoyer fe20ad
 Before=sysinit.target shutdown.target
Harald Hoyer fe20ad
 ConditionPathIsReadWrite=/proc/sys/
Harald Hoyer fe20ad
-ConditionPathExists=|/etc/sysctl.conf
Harald Hoyer fe20ad
 ConditionDirectoryNotEmpty=|/lib/sysctl.d
Harald Hoyer fe20ad
 ConditionDirectoryNotEmpty=|/usr/lib/sysctl.d
Harald Hoyer fe20ad
 ConditionDirectoryNotEmpty=|/usr/local/lib/sysctl.d