Skip to content

Commit

Permalink
sys-process/cronbase: fix non-POSIX shell code #595492
Browse files Browse the repository at this point in the history
  • Loading branch information
vapier committed Nov 15, 2016
1 parent aaaeea2 commit b11e8d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sys-process/cronbase/files/run-crons-0.3.7
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ grab_lock() {

# This is better than kill -0 because we can verify that it's really
# another run-crons process.
if diff -qs /proc/{${cronpid},$$}/cmdline > /dev/null 2>&1; then
# We have to send stderr to /dev/null for two reasons:
# - If the process disappears, the cmdline file might not exist.
# - The cmdline file contains NUL bytes, but bash-4.4+ warns when
# you try to assign NUL bytes to variables.
# It'd be nice to not do it for a lot of code, but there's not easy
# alternative in shell code. We could `cat | tr`, but that'd waste
# a bit more than just a simple cat.
if (
cmdline1=$(cat "/proc/${cronpid}/cmdline") || :
cmdline2=$(cat "/proc/$$/cmdline")
[ "${cmdline1}" = "${cmdline2}" ]
) 2>/dev/null ; then
# Whoa, another run-crons is really running.
return 1
fi
Expand Down

0 comments on commit b11e8d8

Please sign in to comment.