From: thib Date: Mon, 28 May 2001 18:47:30 +0000 (+0000) Subject: added support of termios.h and lockf() for Solaris and SysV systems X-Git-Tag: ver1564~259 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2698a25e618791ae090777f920c2d96c71f1170b;p=fcron added support of termios.h and lockf() for Solaris and SysV systems --- diff --git a/config.h.in b/config.h.in index e5d8a6b..478f925 100644 --- a/config.h.in +++ b/config.h.in @@ -21,7 +21,7 @@ * `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 $ */ /* *********************************************************** */ @@ -203,9 +203,6 @@ /* Define if you have the wait3 system call. */ #undef HAVE_WAIT3 -/* Define if you have . */ -#undef NLIST_STRUCT - /* Define if you have the getcwd function. */ #undef HAVE_GETCWD @@ -215,6 +212,12 @@ /* 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 @@ -266,6 +269,9 @@ /* Define if you have the header file. */ #undef HAVE_NDIR_H +/* Define if you have . */ +#undef NLIST_STRUCT + /* Define if you have the header file. */ #undef HAVE_STDARG_H @@ -284,6 +290,9 @@ /* Define if you have the header file. */ #undef HAVE_SYS_NDIR_H +/* Define if you have the header file. */ +#undef HAVE_SYS_TERMIOS_H + /* Define if you have the header file. */ #undef HAVE_SYS_TIME_H diff --git a/configure.in b/configure.in index 1ee160d..fa48cb5 100644 --- a/configure.in +++ b/configure.in @@ -29,6 +29,7 @@ AC_HEADER_SYS_WAIT 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 @@ -48,6 +49,7 @@ AC_CHECK_FUNC(getloadavg, [getloadavg=1], [getloadavg=0]) 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]) diff --git a/fcron.c b/fcron.c index c71ba88..ecd9ca6 100644 --- a/fcron.c +++ b/fcron.c @@ -21,11 +21,11 @@ * `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); @@ -166,35 +166,46 @@ get_lock() * 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. diff --git a/global.h b/global.h index 23621de..06be51c 100644 --- a/global.h +++ b/global.h @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: global.h,v 1.27 2001-05-24 19:59:12 thib Exp $ */ + /* $Id: global.h,v 1.28 2001-05-28 18:48:48 thib Exp $ */ /* @@ -79,6 +79,10 @@ #include #endif +#ifdef HAVE_SYS_TERMIOS_H +#include +#endif + #ifdef HAVE_UNISTD_H #include #endif