Skip to content

Commit 750882e

Browse files
committed
* support/rotatelogs.c (main): Produce useful error message for open()
failures. PR: 39487 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@478135 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0d11448 commit 750882e

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

support/rotatelogs.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#endif
5555

5656
#define BUFSIZE 65536
57-
#define ERRMSGSZ 82
57+
#define ERRMSGSZ 128
5858

5959
#ifndef MAX_PATH
6060
#define MAX_PATH 1024
@@ -188,6 +188,7 @@ int main (int argc, const char * const argv[])
188188

189189
if (nLogFD == NULL) {
190190
int tLogStart;
191+
apr_status_t rv;
191192

192193
if (tRotation) {
193194
tLogStart = (now / tRotation) * tRotation;
@@ -208,22 +209,28 @@ int main (int argc, const char * const argv[])
208209
sprintf(buf2, "%s.%010d", szLogRoot, tLogStart);
209210
}
210211
tLogEnd = tLogStart + tRotation;
211-
apr_file_open(&nLogFD, buf2, APR_READ | APR_WRITE | APR_CREATE | APR_APPEND,
212-
APR_OS_DEFAULT, pool);
213-
if (nLogFD == NULL) {
212+
rv = apr_file_open(&nLogFD, buf2, APR_WRITE | APR_CREATE | APR_APPEND,
213+
APR_OS_DEFAULT, pool);
214+
if (rv != APR_SUCCESS) {
215+
char error[26];
216+
217+
apr_strerror(rv, error, sizeof error);
218+
214219
/* Uh-oh. Failed to open the new log file. Try to clear
215220
* the previous log file, note the lost log entries,
216221
* and keep on truckin'. */
217222
if (nLogFDprev == NULL) {
218-
fprintf(stderr, "1 Previous file handle doesn't exists %s\n", buf2);
223+
fprintf(stderr, "Could not open log file '%s' (%s)\n", buf2, error);
219224
exit(2);
220225
}
221226
else {
222227
nLogFD = nLogFDprev;
223-
sprintf(errbuf,
224-
"Resetting log file due to error opening "
225-
"new log file. %10d messages lost.\n",
226-
nMessCount);
228+
/* Try to keep this error message constant length
229+
* in case it occurs several times. */
230+
apr_snprintf(errbuf, sizeof errbuf,
231+
"Resetting log file due to error opening "
232+
"new log file, %10d messages lost: %-25.25s\n",
233+
nMessCount, error);
227234
nWrite = strlen(errbuf);
228235
apr_file_trunc(nLogFD, 0);
229236
if (apr_file_write(nLogFD, errbuf, &nWrite) != APR_SUCCESS) {

0 commit comments

Comments
 (0)