File cronie-1.4.11-pidfile_locking.patch of Package cronie.10664
From 49225e172d156531ca142518d2638350752e373a Mon Sep 17 00:00:00 2001
From: Tomas Mraz <tmraz@fedoraproject.org>
Date: Fri, 9 Aug 2013 14:57:57 +0200
Subject: Fcntl locking has different semantics than flock. Prefer flock.
---
src/misc.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/misc.c b/src/misc.c
index 106f10e..40fc58c 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -75,7 +75,9 @@ static int LogFD = ERR;
static int syslog_open = FALSE;
#endif
-#if defined(HAVE_FCNTL) && defined(F_SETLK)
+#if defined(HAVE_FLOCK)
+# define trylock_file(fd) flock((fd), LOCK_EX|LOCK_NB)
+#elif defined(HAVE_FCNTL) && defined(F_SETLK)
static int trylock_file(int fd) {
struct flock fl;
@@ -89,8 +91,6 @@ static int trylock_file(int fd) {
}
#elif defined(HAVE_LOCKF)
# define trylock_file(fd) lockf((fd), F_TLOCK, 0)
-#elif defined(HAVE_FLOCK)
-# define trylock_file(fd) flock((fd), LOCK_EX|LOCK_NB)
#endif
/*
@@ -345,6 +345,13 @@ void acquire_daemonlock(int closeflag) {
(void) fchmod(fd, 0644);
(void) fcntl(fd, F_SETFD, 1);
}
+#if !defined(HAVE_FLOCK)
+ else {
+ /* Racy but better than nothing, just hope the parent exits */
+ sleep(0);
+ trylock_file(fd);
+ }
+#endif
sprintf(buf, "%ld\n", (long) pid);
(void) lseek(fd, (off_t) 0, SEEK_SET);
--
cgit v0.12