From: Prakash Kailasa To: Andrew Ford Subject: cronolog patch Date: Tue, 15 May 2001 19:35:41 -0400 Andrew, I have been using cronolog for a few days. Thanks for developing this very useful program and releasing it for public. I have noticed a problem very frequently. On my development system, we stop and start apache several times a day. Whenever I restart apache using the 'graceful' option, one of the cronolog processes (one associated with the error_log) is not terminating. After, several graceful restarts, the cronolog processes are getting accumulated, holding system resources. Eventualy I run out of file descriptors. The only recourse at this point is to stop apache completely and start it again. The enclosed patch fixes this problem. Please take a look at it and see if it is okay to add it to your code. Its possible the code is not very good. Or, there may be a better way to do it. It's been nearly six years since I did any coding in C. Thanks, /prakash --- cronolog-1.6.1/src/cronolog.c.orig Mon Dec 20 03:56:20 1999 +++ cronolog-1.6.1/src/cronolog.c Tue May 15 19:09:43 2001 @@ -84,12 +84,14 @@ #include "cronoutils.h" #include "getopt.h" +#include /* Forward function declaration */ int new_log_file(const char *, const char *, mode_t, PERIODICITY, char *, size_t, time_t, time_t *); +void terminate_self(int); /* Definition of version and usage messages */ @@ -243,6 +245,9 @@ DEBUG(("periodicity = %s\n", periods[periodicity])); + /* set up signal handler to catch USR1 (graceful restart by apache) */ + signal(SIGUSR1, terminate_self); + /* Loop, waiting for data on standard input */ for (;;) @@ -350,4 +355,12 @@ create_link(pfilename, linkname, linktype); } return log_fd; +} + +void terminate_self(int sig) +{ + time_t time_now = time(NULL); + DEBUG(("%s (%d): received signal USR1; terminating.\n", + timestamp(time_now), time_now)); + exit(6); }