Fix and improve the S02sysctl init script
cover Fix and improve the S02sysctl init script
From: Carlos Santos <[email protected]>
Both busybox and procps-ng provide a S02sysctl init script. Since the scripts are the same, except for some comments, make the busybox one a symlink to the procps-ng one.
Also the scripts used the logger utility unconditionally but it may not exist. Declare two functions to perform the operation, run_logger and run_std, and use the appropriate one, depending on the existence of logger.
Carlos Santos (3):
pakage/busybox: use same S02sysctl script as procps-ng package/procps-ng: add busybox-related comments to S02sysctl pakage/procps-ng: use logger in S02sysctl only if it is available
package/busybox/S02sysctl | 67 +------------------------------------ package/procps-ng/S02sysctl | 54 +++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 78 deletions(-) mode change 100644 => 120000 package/busybox/S02sysctl
Signature · 1 line
2.18.2
PATCH 1/3 pakage/busybox: use same S02sysctl script as procps-ng
From: Carlos Santos <[email protected]>
The scripts were already the same, except for some comments, so make the busybox S02sysctl a symlink to the procps-ng one, which works with both versions of the "sysctl" utility.
--- package/busybox/S02sysctl | 67 +-------------------------------------- 1 file changed, 1 insertion(+), 66 deletions(-) mode change 100644 => 120000 package/busybox/S02sysctl
package/busybox/S02sysctl deleted +0 -66
@@ -1,66 +0,0 @@ -#!/bin/sh - -PROGRAM="sysctl" - -SYSCTL_ARGS="" - -# shellcheck source=/dev/null -[ -r "/etc/default/$PROGRAM" ] && . "/etc/default/$PROGRAM" - -# Files are read from directories in the SYSCTL_SOURCES list, in the given -# order. A file may be used more than once, since there can be multiple -# symlinks to it. No attempt is made to prevent this. -SYSCTL_SOURCES="/etc/sysctl.d/ /usr/local/lib/sysctl.d/ /usr/lib/sysctl.d/ /lib/sysctl.d/ /etc/sysctl.conf" - -# Use some scripting to mimic the --system option of the sysctl provided by -# procps-ng but still reporting errors. Users not interested on error report -# can put "-e" in SYSCTL_ARGS. -# -# The file redirections do the following: -# -# - stdout is redirected to syslog with facility.level "kern.info" -# - stderr is redirected to syslog with facility.level "kern.err" -# - file dscriptor 4 is used to pass the result to the "start" function. -# -# Testing the sysctl exit code is fruitless, as at the moment, since it ends -# with status zero even if errors happen. Hopefully this will be fixed in a -# future version of Busybox. -# -run_program() { - # shellcheck disable=SC2086 # we need the word splitting - find $SYSCTL_SOURCES -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \ - xargs -0 -r -n 1 readlink -f | { - prog_status="OK" - while :; do - read -r file - if [ -z "$file" ]; then - echo "$prog_status" >&4 - break - fi - echo "* Applying $file ..." - /sbin/sysctl -p "$file" $SYSCTL_ARGS || prog_status="FAIL" - done 2>&1 >&3 | /usr/bin/logger -t sysctl -p kern.err - } 3>&1 | /usr/bin/logger -t sysctl -p kern.info -} - -start() { - printf '%s %s: ' "$1" "$PROGRAM" - status=$(run_program 4>&1) - echo "$status" - if [ "$status" = "OK" ]; then - return 0 - fi - return 1 -} - -case "$1" in - start) - start "Running";; - restart|reload) - start "Rerunning";; - stop) - :;; - *) - echo "Usage: $0 {start|stop|restart|reload}" - exit 1 -esac
package/busybox/S02sysctl new file +1 -0
@@ -0,0 +1 @@ +../procps-ng/S02sysctl
Signature · 1 line
2.18.2
PATCH 2/3 package/procps-ng: add busybox-related comments to S02sysctl
In reply to unixmania at gmail.comFrom: Carlos Santos <[email protected]>
Explain the busybox peculiarities and how the script works with both versions of the sysctl utility.
--- package/procps-ng/S02sysctl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
package/procps-ng/S02sysctl +13 -6
@@ -1,4 +1,17 @@ #!/bin/sh +# +# This script is used by busybox and procps-ng. +# +# With procps-ng, the "--system" option of sysctl also enables "--ignore", so +# errors are not reported via syslog. Use the run_logger function to mimic the +# --system behavior, still reporting errors via syslog. Users not interested +# on error reports can add "-e" to SYSCTL_ARGS. +# +# busybox does not have a "--system" option neither reports errors via syslog, +# so the scripting provides a consistent behavior between the implementations. +# Testing the busybox sysctl exit code is fruitless, as at the moment, since +# its exit status is zero even if errors happen. Hopefully this will be fixed +# in a future busybox version. PROGRAM="sysctl"
@@ -12,12 +25,6 @@ SYSCTL_ARGS="" # symlinks to it. No attempt is made to prevent this. SYSCTL_SOURCES="/etc/sysctl.d/ /usr/local/lib/sysctl.d/ /usr/lib/sysctl.d/ /lib/sysctl.d/ /etc/sysctl.conf" -# The "--system" option activates "--ignore", which is bad because invalid -# variable settings in the configuration files will not be reported on the -# system log. Use some scripting to mimic the --system behavior but still -# reporting errors. Users not interested on error report can put "-e" in -# SYSCTL_ARGS. -# # The file redirections do the following: # # - stdout is redirected to syslog with facility.level "kern.info"
Signature · 1 line
2.18.2
PATCH 3/3 pakage/procps-ng: use logger in S02sysctl only if it is available
In reply to unixmania at gmail.comFrom: Carlos Santos <[email protected]>
The script used the logger utility unconditionally but it may not exist (e.g. busybox-minimal.config is used and BR2_PACKAGE_UTIL_LINUX_LOGGER is not selected).
Declare two functions to perform the operation, run_logger and run_std, and use the appropriate one, depending on the existence of logger.
--- package/procps-ng/S02sysctl | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)
package/procps-ng/S02sysctl +29 -6
@@ -25,32 +25,55 @@ SYSCTL_ARGS="" # symlinks to it. No attempt is made to prevent this. SYSCTL_SOURCES="/etc/sysctl.d/ /usr/local/lib/sysctl.d/ /usr/lib/sysctl.d/ /lib/sysctl.d/ /etc/sysctl.conf" -# The file redirections do the following: +# If the logger utility is available all messages are sent to syslog, except +# for the final status. The file redirections do the following: # # - stdout is redirected to syslog with facility.level "kern.info" # - stderr is redirected to syslog with facility.level "kern.err" # - file dscriptor 4 is used to pass the result to the "start" function. # -run_program() { +run_logger() { # shellcheck disable=SC2086 # we need the word splitting find $SYSCTL_SOURCES -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \ xargs -0 -r -n 1 readlink -f | { prog_status="OK" while :; do - read -r file - if [ -z "$file" ]; then + read -r file || { echo "$prog_status" >&4 break - fi + } echo "* Applying $file ..." /sbin/sysctl -p "$file" $SYSCTL_ARGS || prog_status="FAIL" done 2>&1 >&3 | /usr/bin/logger -t sysctl -p kern.err } 3>&1 | /usr/bin/logger -t sysctl -p kern.info } +# If logger is not available all messages are sent to stdout/stderr. +run_std() { + # shellcheck disable=SC2086 # we need the word splitting + find $SYSCTL_SOURCES -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \ + xargs -0 -r -n 1 readlink -f | { + prog_status="OK" + while :; do + read -r file || { + echo "$prog_status" >&4 + break + } + echo "* Applying $file ..." + /sbin/sysctl -p "$file" $SYSCTL_ARGS || prog_status="FAIL" + done + } +} + +if [ -x /usr/bin/logger ]; then + run_program="run_logger" +else + run_program="run_std" +fi + start() { printf '%s %s: ' "$1" "$PROGRAM" - status=$(run_program 4>&1) + status=$("$run_program" 4>&1) echo "$status" if [ "$status" = "OK" ]; then return 0
Signature · 1 line
2.18.2
cover Fix and improve the S02sysctl init script
In reply to unixmania at gmail.comQuoted 4 lines · On Sun, 29 Mar 2020 20:49:21 -0300 unixmania at gmail.com wrote:
Carlos Santos (3):
pakage/busybox: use same S02sysctl script as procps-ng package/procps-ng: add busybox-related comments to S02sysctl pakage/procps-ng: use logger in S02sysctl only if it is available
Thanks, series applied. I must admit I'm starting to be a bit worried by the complexity of what should be a simple script to load sysctl values, but OK.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
cover Fix and improve the S02sysctl init script
Quoted 4 lines · Thomas Petazzoni
On Sun, 29 Mar 2020 20:49:21 -0300
unixmania at gmail.com wrote:
Quoted 8 lines
Quoted 4 lines
Carlos Santos (3):
pakage/busybox: use same S02sysctl script as procps-ng package/procps-ng: add busybox-related comments to S02sysctl pakage/procps-ng: use logger in S02sysctl only if it is availableThanks, series applied. I must admit I'm starting to be a bit worried by the complexity of what should be a simple script to load sysctl values, but OK.
I don't like it, either, and will submit a patch to kmod fixing the behavior when the --system option is passed. Triggering the --ignore option seems to be a bug, since it is not documented in the manual page.
Signature · 1 line
Carlos Santos <[email protected]>
cover Fix and improve the S02sysctl init script
Quoted 12 lines · Carlos Santos
Quoted 9 lines · Thomas Petazzoni
Quoted 4 lines · On Sun, 29 Mar 2020 20:49:21 -0300 unixmania at gmail.com wrote:
Carlos Santos (3):
pakage/busybox: use same S02sysctl script as procps-ng package/procps-ng: add busybox-related comments to S02sysctl pakage/procps-ng: use logger in S02sysctl only if it is available
Quoted 8 lines
Quoted 3 lines
Thanks, series applied. I must admit I'm starting to be a bit worried by the complexity of what should be a simple script to load sysctl values, but OK.
I don't like it, either, and will submit a patch to kmod fixing the behavior when the --system option is passed. Triggering the --ignore option seems to be a bug, since it is not documented in the manual page.
Errata: will submit a patch to procps-ng.
Signature · 1 line
Carlos Santos <[email protected]>