sys-process/cronbase: fix non-POSIX shell code #595492
authorMike Frysinger <vapier@gentoo.org>
Tue, 15 Nov 2016 06:04:39 +0000 (01:04 -0500)
committerMike Frysinger <vapier@gentoo.org>
Tue, 15 Nov 2016 06:06:05 +0000 (01:06 -0500)
sys-process/cronbase/cronbase-0.3.7-r6.ebuild [moved from sys-process/cronbase/cronbase-0.3.7-r5.ebuild with 100% similarity]
sys-process/cronbase/files/run-crons-0.3.7

index 902794e19e6f744bb7aa9f928e5ee4d61e39ac3b..42c88100df1c0ac10195a5302dd53c3294024054 100755 (executable)
@@ -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