* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: config.h.in,v 1.27 2001-05-15 00:49:11 thib Exp $ */
+ /* $Id: config.h.in,v 1.28 2001-05-28 18:51:24 thib Exp $ */
/* *********************************************************** */
/* Define if you have the wait3 system call. */
#undef HAVE_WAIT3
-/* Define if you have <nlist.h>. */
-#undef NLIST_STRUCT
-
/* Define if you have the getcwd function. */
#undef HAVE_GETCWD
/* Define if you have the gettimeofday function. */
#undef HAVE_GETTIMEOFDAY
+/* Define if you have the flock function. */
+#undef HAVE_FLOCK
+
+/* Define if you have the lockf function. */
+#undef HAVE_LOCKF
+
/* Define if you have the mkstemp function. */
#undef HAVE_MKSTEMP
/* Define if you have the <ndir.h> header file. */
#undef HAVE_NDIR_H
+/* Define if you have <nlist.h>. */
+#undef NLIST_STRUCT
+
/* Define if you have the <stdarg.h> header file. */
#undef HAVE_STDARG_H
/* Define if you have the <sys/ndir.h> header file. */
#undef HAVE_SYS_NDIR_H
+/* Define if you have the <sys/termios.h> header file. */
+#undef HAVE_SYS_TERMIOS_H
+
/* Define if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
AC_CHECK_HEADERS(fcntl.h sys/file.h sys/ioctl.h sys/time.h syslog.h unistd.h)
AC_CHECK_HEADERS(errno.h sys/fcntl.h getopt.h limits.h)
AC_CHECK_HEADERS(stdarg.h)
+AC_CHECK_HEADERS(sys/termios.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_FUNC_GETLOADAVG
AC_CHECK_FUNCS(getcwd gettimeofday mktime putenv strerror setenv gethostname)
AC_CHECK_FUNCS(mkstemp)
+AC_CHECK_FUNCS(flock, lockf)
AC_CHECK_FUNCS(setreuid, [setreuid=1], [setreuid=0])
AC_CHECK_FUNCS(setregid, [setregid=1], [setregid=0])
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fcron.c,v 1.45 2001-05-17 00:53:02 thib Exp $ */
+ /* $Id: fcron.c,v 1.46 2001-05-28 18:48:27 thib Exp $ */
#include "fcron.h"
-char rcs_info[] = "$Id: fcron.c,v 1.45 2001-05-17 00:53:02 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.46 2001-05-28 18:48:27 thib Exp $";
void main_loop(void);
void check_signal(void);
* if not, write our pid to /var/run/fcron.pid in order to lock,
* and to permit fcrontab to read our pid and signal us */
{
+ int otherpid = 0, foreopt;
- if ( ! daemon_lockfp ) {
- int fd, otherpid, foreopt;
+ foreopt = foreground;
+ foreground = 1;
- foreopt = foreground;
- foreground = 1;
+ if ( ! daemon_lockfp ) {
+ int fd;
if (((fd = open(PIDFILE, O_RDWR|O_CREAT, 0644)) == -1 )
|| ((daemon_lockfp = fdopen(fd, "r+"))) == NULL)
die_e("can't open or create " PIDFILE);
- if ( flock(fd, LOCK_EX|LOCK_NB) != 0 ) {
- if ((errno == EAGAIN) || (errno == EACCES))
- errno = EWOULDBLOCK;
- fscanf(daemon_lockfp, "%d", &otherpid);
- die("can't lock " PIDFILE ", running daemon's pid may be %d",
- otherpid);
- }
-
- (void) fcntl(fd, F_SETFD, 1);
-
- foreground = foreopt;
+#ifdef HAVE_FLOCK
+ /* flock() seems to keep the lock over a fork() (contrary to lockf() ):
+ * we only need to lock the file once */
+ if ( flock(fd, LOCK_EX|LOCK_NB) != 0 ) {
+ fscanf(daemon_lockfp, "%d", &otherpid);
+ die("can't lock " PIDFILE ", running daemon's pid may be %d",
+ otherpid);
+ }
+#endif /* HAVE_FLOCK */
+
+ fcntl(fd, F_SETFD, 1);
}
+#ifndef HAVE_FLOCK
+ if ( lockf(fileno(daemon_lockfp), F_TLOCK, 0) != 0 ) {
+ fscanf(daemon_lockfp, "%d", &otherpid);
+ die("can't lock " PIDFILE ", running daemon's pid may be %d",
+ otherpid);
+ }
+#endif /* ! HAVE_FLOCK */
+
+ foreground = foreopt;
+
rewind(daemon_lockfp);
fprintf(daemon_lockfp, "%d\n", daemon_pid);
fflush(daemon_lockfp);
- (void) ftruncate(fileno(daemon_lockfp), ftell(daemon_lockfp));
+ ftruncate(fileno(daemon_lockfp), ftell(daemon_lockfp));
/* abandon fd and daemon_lockfp even though the file is open. we need to
* keep it open and locked, but we don't need the handles elsewhere.