Blame SOURCES/cronie-1.4.11-fcntl_locking.patch

f83704
diff -up cronie-1.4.11/src/misc.c.ddd cronie-1.4.11/src/misc.c
f83704
--- cronie-1.4.11/src/misc.c.ddd	2013-07-18 14:27:08.000000000 +0200
f83704
+++ cronie-1.4.11/src/misc.c	2013-08-30 13:51:22.227040980 +0200
f83704
@@ -75,7 +75,9 @@ static int LogFD = ERR;
f83704
 static int syslog_open = FALSE;
f83704
 #endif
f83704
 
f83704
-#if defined(HAVE_FCNTL) && defined(F_SETLK)
f83704
+#if defined(HAVE_FLOCK)
f83704
+# define trylock_file(fd)      flock((fd), LOCK_EX|LOCK_NB)
f83704
+#elif defined(HAVE_FCNTL) && defined(F_SETLK)
f83704
 static int trylock_file(int fd) {
f83704
 	struct flock fl;
f83704
 
f83704
@@ -89,8 +91,6 @@ static int trylock_file(int fd) {
f83704
 }
f83704
 #elif defined(HAVE_LOCKF)
f83704
 # define trylock_file(fd)      lockf((fd), F_TLOCK, 0)
f83704
-#elif defined(HAVE_FLOCK)
f83704
-# define trylock_file(fd)      flock((fd), LOCK_EX|LOCK_NB)
f83704
 #endif
f83704
 
f83704
 /*
f83704
@@ -346,6 +346,14 @@ void acquire_daemonlock(int closeflag) {
f83704
 		(void) fcntl(fd, F_SETFD, 1);
f83704
 	}
f83704
 
f83704
+#if !defined(HAVE_FLOCK)
f83704
+	else {
f83704
+		/* Racy but better than nothing, just hope the parent exits */
f83704
+		sleep(0);
f83704
+		trylock_file(fd);
f83704
+	}
f83704
+#endif
f83704
+
f83704
 	sprintf(buf, "%ld\n", (long) pid);
f83704
 	(void) lseek(fd, (off_t) 0, SEEK_SET);
f83704
 	len = strlen(buf);