summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron/lib
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-08-24 17:51:36 +0000
committerpjd <pjd@FreeBSD.org>2005-08-24 17:51:36 +0000
commit45a889ae7cd87575cfb3c61357c03b5aa38a495b (patch)
treefb2a6b32b48a5a88421ec0e7e173b487e80a24a9 /usr.sbin/cron/lib
parentca93f2e965682fbc7b5e751fda50492bbf7d9093 (diff)
downloadFreeBSD-src-45a889ae7cd87575cfb3c61357c03b5aa38a495b.zip
FreeBSD-src-45a889ae7cd87575cfb3c61357c03b5aa38a495b.tar.gz
Use pidfile(3) in cron(8).
Note, that when cron(8) cannot create pidfile, it'll exit. I didn't changed this behaviour, but its better to ignore errors other than EEXIST, so daemon can be started on systems where /var/ file system doesn't support locking (like NFS without rpc.lockd(8)).
Diffstat (limited to 'usr.sbin/cron/lib')
-rw-r--r--usr.sbin/cron/lib/misc.c59
1 files changed, 0 insertions, 59 deletions
diff --git a/usr.sbin/cron/lib/misc.c b/usr.sbin/cron/lib/misc.c
index 5f6b89f..e557afc 100644
--- a/usr.sbin/cron/lib/misc.c
+++ b/usr.sbin/cron/lib/misc.c
@@ -222,65 +222,6 @@ set_cron_cwd()
}
-/* acquire_daemonlock() - write our PID into /etc/cron.pid, unless
- * another daemon is already running, which we detect here.
- *
- * note: main() calls us twice; once before forking, once after.
- * we maintain static storage of the file pointer so that we
- * can rewrite our PID into the PIDFILE after the fork.
- *
- * it would be great if fflush() disassociated the file buffer.
- */
-void
-acquire_daemonlock(closeflag)
- int closeflag;
-{
- static FILE *fp = NULL;
-
- if (closeflag && fp) {
- fclose(fp);
- fp = NULL;
- return;
- }
-
- if (!fp) {
- char pidfile[MAX_FNAME];
- char buf[MAX_TEMPSTR];
- int fd, otherpid;
-
- (void) sprintf(pidfile, PIDFILE, PIDDIR);
- if ((-1 == (fd = open(pidfile, O_RDWR|O_CREAT, 0644)))
- || (NULL == (fp = fdopen(fd, "r+")))
- ) {
- sprintf(buf, "can't open or create %s: %s",
- pidfile, strerror(errno));
- log_it("CRON", getpid(), "DEATH", buf);
- errx(ERROR_EXIT, "%s", buf);
- }
-
- if (flock(fd, LOCK_EX|LOCK_NB) < OK) {
- int save_errno = errno;
-
- fscanf(fp, "%d", &otherpid);
- sprintf(buf, "can't lock %s, otherpid may be %d: %s",
- pidfile, otherpid, strerror(save_errno));
- log_it("CRON", getpid(), "DEATH", buf);
- errx(ERROR_EXIT, "%s", buf);
- }
-
- (void) fcntl(fd, F_SETFD, 1);
- }
-
- rewind(fp);
- fprintf(fp, "%d\n", getpid());
- fflush(fp);
- (void) ftruncate(fileno(fp), ftell(fp));
-
- /* abandon fd and fp even though the file is open. we need to
- * keep it open and locked, but we don't need the handles elsewhere.
- */
-}
-
/* get_char(file) : like getc() but increment LineNumber on newlines
*/
int
OpenPOWER on IntegriCloud