On 01/11/2009 03:05 PM, [email protected] wrote:
> Author: rjung
> Date: Sun Jan 11 06:05:39 2009
> New Revision: 733476
>
> URL: http://svn.apache.org/viewvc?rev=733476&view=rev
> Log:
> Refactor rotatelogs to allow easier implementation
> of signal triggered log rotation.
>
> - move code into new functions checkRotate() and doRotate()
> - bundle config data and runtime data in two structs to
> allow easier passing to functions
> - Simplify bypass_io logic as a first use case for doRotate
> and rename flag to force_open to reflect the new logic
>
>
> Modified:
> httpd/httpd/trunk/support/rotatelogs.c
>
> Modified: httpd/httpd/trunk/support/rotatelogs.c
> URL:
> http://svn.apache.org/viewvc/httpd/httpd/trunk/support/rotatelogs.c?rev=733476&r1=733475&r2=733476&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/support/rotatelogs.c (original)
> +++ httpd/httpd/trunk/support/rotatelogs.c Sun Jan 11 06:05:39 2009
> @@ -64,6 +64,37 @@
> #define MAX_PATH 1024
> #endif
>
> +typedef struct rotate_config rotate_config_t;
> +
> +struct rotate_config {
> + unsigned int sRotation;
> + int tRotation;
> + int utc_offset;
> + int use_localtime;
> + int use_strftime;
> + int force_open;
> + const char *szLogRoot;
> +};
> +
> +typedef struct rotate_status rotate_status_t;
> +
> +struct rotate_status {
> + apr_pool_t *pool;
> + apr_pool_t *pfile;
> + apr_pool_t *pfile_prev;
> + apr_file_t *nLogFD;
> + apr_file_t *nLogFDprev;
> + char filename[MAX_PATH];
> + char errbuf[ERRMSGSZ];
> + int needsRotate;
> + int tLogEnd;
> + int now;
> + int nMessCount;
> +};
> +
> +static rotate_config_t config;
> +static rotate_status_t status;
Why do they need to be global?
> +
> static void usage(const char *argv0, const char *reason)
> {
> if (reason) {
> @@ -110,22 +141,114 @@
> return (int)apr_time_sec(tNow) + utc_offset;
> }
>
> +void checkRotate(rotate_config_t *config, rotate_status_t *status) {
> +
> + if (status->nLogFD == NULL)
> + return;
No need to do further checks for status->nLogFD != NULL below.
> + if (config->tRotation) {
> + status->now = get_now(config->use_localtime, config->utc_offset);
> + if (status->nLogFD != NULL && status->now >= status->tLogEnd) {
> + status->needsRotate = 1;
> + }
> + }
> + else if (config->sRotation) {
> + apr_finfo_t finfo;
> + apr_off_t current_size = -1;
> +
> + if ((status->nLogFD != NULL) &&
> + (apr_file_info_get(&finfo, APR_FINFO_SIZE, status->nLogFD) ==
> APR_SUCCESS)) {
> + current_size = finfo.size;
> + }
> +
> + if (current_size > config->sRotation) {
> + status->needsRotate = 1;
> + }
> + }
> + else {
> + fprintf(stderr, "No rotation time or size specified\n");
> + exit(2);
> + }
> +
> + return;
> +}
> +
Regards
RĂ¼diger