[OpenWrt-Devel] [PATCH v2] sysctl: read settings from /etc/sysctl.d/*.conf

Stefan Tomanek stefan.tomanek+openwrt at wertarbyte.de
Wed May 27 14:51:13 EDT 2015


This changes makes it possible to store custom settings
in individual files inside the directory /etc/sysctl.d/.

Signed-off-by: Stefan Tomanek <stefan.tomanek+openwrt at wertarbyte.de>
---
 package/base-files/Makefile                        |    2 ++
 .../base-files/files/etc/hotplug.d/net/00-sysctl   |    9 ++++++---
 package/base-files/files/etc/init.d/sysctl         |    4 +++-
 package/base-files/files/etc/sysctl.d/local.conf   |    1 +
 4 files changed, 12 insertions(+), 4 deletions(-)
 create mode 100644 package/base-files/files/etc/sysctl.d/local.conf

diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index 0bba313..a5f15fa 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -55,6 +55,8 @@ define Package/base-files/conffiles
 /etc/config/
 /etc/dropbear/
 /etc/crontabs/
+/etc/sysctl.d/local.conf
+/etc/sysctl.d/
 $(call $(TARGET)/conffiles)
 endef
 
diff --git a/package/base-files/files/etc/hotplug.d/net/00-sysctl b/package/base-files/files/etc/hotplug.d/net/00-sysctl
index 5d9da8a..7a71652 100644
--- a/package/base-files/files/etc/hotplug.d/net/00-sysctl
+++ b/package/base-files/files/etc/hotplug.d/net/00-sysctl
@@ -1,6 +1,9 @@
 #!/bin/sh
 
-if [ -f /etc/sysctl.conf ] && [ "$ACTION" = add ]; then
-	sed -ne "/^[[:space:]]*net\..*\.$DEVICENAME\./p" /etc/sysctl.conf | \
-		sysctl -e -p - | logger -t sysctl
+if [ "$ACTION" = add ]; then
+	for CONF in /etc/sysctl.conf /etc/sysctl.d/*.conf; do
+		[ ! -f "$CONF" ] && continue;
+		sed -ne "/^[[:space:]]*net\..*\.$DEVICENAME\./p" "$CONF" | \
+			sysctl -e -p - | logger -t sysctl
+	done
 fi
diff --git a/package/base-files/files/etc/init.d/sysctl b/package/base-files/files/etc/init.d/sysctl
index 36e29ea..2dfbaf7 100755
--- a/package/base-files/files/etc/init.d/sysctl
+++ b/package/base-files/files/etc/init.d/sysctl
@@ -3,5 +3,7 @@
 
 START=11
 start() {
-	[ -f /etc/sysctl.conf ] && sysctl -p -e >&-
+	for CONF in /etc/sysctl.conf /etc/sysctl.d/*.conf; do
+		[ -f "$CONF" ] && sysctl -p "$CONF" -e >&-
+	done
 }
diff --git a/package/base-files/files/etc/sysctl.d/local.conf b/package/base-files/files/etc/sysctl.d/local.conf
new file mode 100644
index 0000000..891da73
--- /dev/null
+++ b/package/base-files/files/etc/sysctl.d/local.conf
@@ -0,0 +1 @@
+# local sysctl settings can be stored in this directory
-- 
1.7.2.5
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list