diff options
-rw-r--r-- | usr.sbin/httpd/src/support/rotatelogs.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/usr.sbin/httpd/src/support/rotatelogs.c b/usr.sbin/httpd/src/support/rotatelogs.c index fa1c26d0697..023f822aa7c 100644 --- a/usr.sbin/httpd/src/support/rotatelogs.c +++ b/usr.sbin/httpd/src/support/rotatelogs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rotatelogs.c,v 1.9 2008/10/03 19:37:44 mbalmer Exp $ */ +/* $OpenBSD: rotatelogs.c,v 1.10 2008/10/06 20:50:18 mbalmer Exp $ */ /* * Simple program to rotate Apache logs without having to kill the server. @@ -80,27 +80,30 @@ main(int argc, char *argv[]) szLogRoot, (int)tLogStart); tLogEnd = tLogStart + tRotation; - nLogFD = open(buf2, O_WRONLY | O_CREAT | O_APPEND, - 0666); + do { + nLogFD = open(buf2, O_WRONLY | O_CREAT | + O_APPEND, 0666); + if (nLogFD < 0 && nLogFDprev == -1) { + fprintf(stderr, "rotatelogs: can't " + "open %s for writing: %s\n", buf2, + strerror(errno)); + sleep(2); + } + } while (nLogFD < 0 && nLogFDprev == -1); if (nLogFD < 0) { /* * 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; - snprintf(errbuf, sizeof(errbuf), - "Resetting log file due to error " - "opening new log file. %10d " - "messages lost.\n", nMessCount); - nWrite = strlen(errbuf); - ftruncate(nLogFD, 0); - write(nLogFD, errbuf, nWrite); - } + nLogFD = nLogFDprev; + snprintf(errbuf, sizeof(errbuf), + "Resetting log file due to error opening " + "new log file. %10d messages lost.\n", + nMessCount); + nWrite = strlen(errbuf); + ftruncate(nLogFD, 0); + write(nLogFD, errbuf, nWrite); } else close(nLogFDprev); nMessCount = 0; |