Skip to content

Commit 478a186

Browse files
committed
init.d/sysctl: manually load sysctl config if --system fails
busybox's and toybox's sysctl do not have --system currently we simply check for return success, this if fragile as failures unrelated to "missing --system" would also trigger the manually loading path, alternatively we could have some hard knob, though an automated detection method would be preferred Fixes: #947
1 parent 39eb8a9 commit 478a186

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

init.d/sysctl.in

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,66 @@ BSD_sysctl()
3737
return $retval
3838
}
3939

40-
Linux_sysctl()
40+
linux_sysctl()
4141
{
4242
local quiet
4343
yesno $rc_verbose || quiet=-q
4444

45-
sysctl ${quiet} --system
45+
# if sysctl supports --system, use it, otherwise implement
46+
# our own uapi config mechanism with -p.
47+
# notably, busybox's and toybox's sysctl do not support --system.
48+
sysctl ${quiet} --system && return 0
49+
50+
eindent
51+
52+
local files=
53+
for f in /lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do
54+
if [ -f /etc/sysctl.d/"${f##*/}" ]; then
55+
veinfo "Ignoring $f due to /etc/sysctl.d/${f##*/}"
56+
continue
57+
fi
58+
59+
if [ -f /run/sysctl.d/"${f##*/}" ]; then
60+
veinfo "Ignoring $f due to /run/sysctl.d/${f##*/}"
61+
continue
62+
fi
63+
64+
if [ -f "$f" ]; then
65+
ebegin "applying $f"
66+
sysctl $quiet -p "$f"
67+
# Don't change retval= since we expect some package/distro provided
68+
# sysctl configurations to break, so just warn when the user wants
69+
# verbose messages
70+
ewend $? "Unable to configure kernel parameters from $f"
71+
fi
72+
done
73+
74+
for f in /etc/sysctl.d/*.conf; do
75+
if [ -f /run/sysctl.d/"${f##*/}" ]; then
76+
veinfo "Ignoring $f due to /run/sysctl.d/${f##*/}"
77+
continue
78+
fi
79+
80+
files="$files $f"
81+
done
82+
83+
[ -f /etc/sysctl.conf ] && files="$files /etc/sysctl.conf"
84+
85+
for f in /run/sysctl.d/*.conf; do
86+
[ -f "$f" ] && files="$files $f"
87+
done
88+
89+
for f in $files; do
90+
ebegin "Applying $f"
91+
sysctl $quiet -p "$f"
92+
if ! eend $? "Unable to configure kernel parameters from $f"; then
93+
retval=1
94+
fi
95+
done
96+
97+
eoutdent
98+
99+
return $retval
46100
}
47101

48102
start()
@@ -52,7 +106,7 @@ start()
52106
ebegin "Configuring kernel parameters"
53107
case "$RC_UNAME" in
54108
*BSD|GNU) BSD_sysctl; rc=$? ;;
55-
Linux) Linux_sysctl; rc=$? ;;
109+
Linux) linux_sysctl; rc=$? ;;
56110
esac
57111
eend $rc "Unable to configure some kernel parameters"
58112
}

0 commit comments

Comments
 (0)