At least verified in openSUSE tumbleweed and ubuntu 16.04,
`sysctl -n kernel.core_pattern` returns a pipe at the start of the
value. We reset core_pattern to its original form once the script is
about to end, but if we do not discard the pipe the new value will
contain an extra pipe (apparently, the pipe is added automatically at
some point, possibly simply on read). We are simply stripping it on
read, as to prevent this behavior.
Additionally, we are also enclosing the reset of kernel.core_pattern in
quotes, so as to make sure patterns that include spaces (e.g., ubuntu's
apport, or tumbleweed's systemd-coredump) are properly reset.
Signed-off-by: Joao Eduardo Luis <joao@suse.de>
errors=0
userargs=""
precore="$(sysctl -n $KERNCORE)"
+
+if [[ "${precore:0:1}" = "|" ]]; then
+ precore="${precore:1}"
+fi
+
# If corepattern already set, avoid having to use sudo
if [ "$precore" = "$COREPATTERN" ]; then
precore=""
fi
done
if [ -n "$precore" ]; then
- sudo sysctl -w ${KERNCORE}=${precore}
+ sudo sysctl -w ${KERNCORE}="${precore}"
fi
if [ "$errors" != "0" ]; then