break;
case APR_OC_REASON_UNWRITABLE:
- if (pl->pid != NULL) {
- apr_kill(pl->pid, SIGTERM);
- }
+ /* We should not kill off the pipe here, since it may only be full.
+ * If it really is locked, we should kill it off manually. */
break;
case APR_OC_REASON_RESTART:
#include <fcntl.h>
#define BUFSIZE 65536
+#define ERRMSGSZ 82
#ifndef MAX_PATH
#define MAX_PATH 1024
int main (int argc, char *argv[])
{
- char buf[BUFSIZE], buf2[MAX_PATH];
- time_t tLogEnd = 0;
- time_t tRotation;
- int nLogFD = -1;
- int nRead;
+ char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ];
+ time_t tLogEnd = 0, tRotation;
+ int nLogFD = -1, nLogFDprev = -1, nMessCount = 0, nRead, nWrite;
char *szLogRoot;
if (argc != 3) {
if (errno != EINTR)
exit(4);
if (nLogFD >= 0 && (time(NULL) >= tLogEnd || nRead < 0)) {
- close(nLogFD);
+ nLogFDprev = nLogFD;
nLogFD = -1;
}
if (nLogFD < 0) {
tLogEnd = tLogStart + tRotation;
nLogFD = open(buf2, O_WRONLY | O_CREAT | O_APPEND, 0666);
if (nLogFD < 0) {
- perror(buf2);
- exit(2);
+ /* Uh-oh. Failed to open the new log file. Try to clear
+ * the previous log file, note the lost log entries,
+ * and keep on truckin'. */
+ if (nLogFDprev == -1) {
+ perror(buf2);
+ exit(2);
+ }
+ else {
+ nLogFD = nLogFDprev;
+ sprintf(errbuf,
+ "Resetting log file due to error opening "
+ "new log file. %10d messages lost.\n",
+ nMessCount);
+ nWrite = strlen(errbuf);
+#ifdef WIN32
+ chsize(nLogFD, 0);
+#else
+ ftruncate(nLogFD, 0);
+#endif
+ write(nLogFD, errbuf, nWrite);
+ }
+ }
+ else {
+ close(nLogFDprev);
}
+ nMessCount = 0;
+ }
+ do {
+ nWrite = write(nLogFD, buf, nRead);
+ } while (nWrite < 0 && errno == EINTR);
+ if (nWrite != nRead) {
+ nMessCount++;
+ sprintf(errbuf,
+ "Error writing to log file. "
+ "%10d messages lost.\n",
+ nMessCount);
+ nWrite = strlen(errbuf);
+#ifdef WIN32
+ chsize(nLogFD, 0);
+#else
+ ftruncate(nLogFD, 0);
+#endif
+ write (nLogFD, errbuf, nWrite);
}
- if (write(nLogFD, buf, nRead) != nRead) {
- perror(buf2);
- exit(5);
+ else {
+ nMessCount++;
}
}
/* Of course we never, but prevent compiler warnings */