From: Eric Covener Date: Fri, 6 Jan 2023 20:45:16 +0000 (+0000) Subject: minor tweak to -n with size rotation X-Git-Tag: 2.5.0-alpha2-ci-test-only~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43f0c91fd01fc2f1eed3cf8330f8a1b992b28a82;p=thirdparty%2Fapache%2Fhttpd.git minor tweak to -n with size rotation Without -t, One line can be added to base "logfile" even when it's over the size limit already. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1906428 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/support/rotatelogs.c b/support/rotatelogs.c index 3ebd67c1a63..5430f9e2e3c 100644 --- a/support/rotatelogs.c +++ b/support/rotatelogs.c @@ -378,6 +378,7 @@ static void doRotate(rotate_config_t *config, rotate_status_t *status) apr_status_t rv; struct logfile newlog; int thisLogNum = -1; + int oldreason = status->rotateReason; /* Retrieve local-time-adjusted-Unix-time. */ now = get_now(config, &offset); @@ -472,6 +473,19 @@ static void doRotate(rotate_config_t *config, rotate_status_t *status) /* New log file is now 'current'. */ status->current = newlog; + + /* The first write to to the initial file hasn't checked for size + * In the normalized timestamp case and the custom strftime case with + * any reasonable accuracy, it's futile as the rotation will pick the + * same filename again. + * For -n, when not truncating, check and rotate. + */ + if (config->num_files > 0 && oldreason == ROTATE_NEW && !config->truncate) { + checkRotate(config, status); + if (status->rotateReason != ROTATE_NONE) { + doRotate(config, status); + } + } } else { char *error = apr_psprintf(newlog.pool, "%pm", &rv);