rotatelogs.c revision 62cd2833e1fc0f71de15c9f493a2025dad81dc72
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Simple program to rotate Apache logs without having to kill the server.
*
* Contributed by Ben Laurie <ben algroup.co.uk>
*
* 12 Mar 1996
*
* Ported to APR by Mladen Turk <mturk mappingsoft.com>
*
* 23 Sep 2001
*
* -l option added 2004-06-11
*
* -l causes the use of local time rather than GMT as the base for the
* interval. NB: Using -l in an environment which changes the GMT offset
* (such as for BST or DST) can lead to unpredictable results!
*
*/
#include "apr.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_errno.h"
#include "apr_file_io.h"
#include "apr_file_info.h"
#include "apr_general.h"
#include "apr_time.h"
#include <stdlib.h>
#endif
#include <string.h>
#endif
#include <strings.h>
#endif
#define BUFSIZE 65536
#define ERRMSGSZ 128
#ifndef MAX_PATH
#define MAX_PATH 1024
#endif
{
unsigned int sRotation = 0;
int nMessCount = 0;
int use_strftime = 0;
int use_localtime = 0;
int now = 0;
const char *szLogRoot;
int argBase = 0;
int argFile = 1;
int argIntv = 2;
int argOffset = 3;
argBase++;
use_localtime = 1;
}
"Usage: %s [-l] <logfile> <rotation time in seconds> "
"[offset minutes from UTC] or <rotation size in megabytes>\n\n",
argv[0]);
#ifdef OS2
argv[0]);
#else
argv[0]);
#endif
"to httpd.conf. The generated name will be /some/where.nnnn "
"where nnnn is the\nsystem time at which the log nominally "
"starts (N.B. if using a rotation time,\nthe time will always "
"be a multiple of the rotation time, so you can synchronize\n"
"cron scripts with it). At the end of each rotation time or "
"when the file size\nis reached a new log is started.\n");
exit(1);
}
if (ptr) {
}
if (sRotation == 0) {
exit(1);
}
}
else {
}
if (tRotation <= 0) {
exit(6);
}
}
exit(1);
}
for (;;) {
exit(3);
}
if (tRotation) {
/*
* Check for our UTC offset every time through the loop, since
* it might change if there's a switch between standard and
* daylight savings time.
*/
if (use_localtime) {
}
nLogFDprev = nLogFD;
}
}
else if (sRotation) {
}
if (current_size > sRotation) {
nLogFDprev = nLogFD;
}
}
else {
exit(2);
}
int tLogStart;
if (tRotation) {
}
else {
}
if (use_strftime) {
apr_time_exp_gmt(&e, tNow);
}
else {
}
if (rv != APR_SUCCESS) {
char error[26];
/* 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 == NULL) {
exit(2);
}
else {
nLogFD = nLogFDprev;
/* Try to keep this error message constant length
* in case it occurs several times. */
"Resetting log file due to error opening "
"new log file, %10d messages lost: %-25.25s\n",
nMessCount, error);
apr_file_trunc(nLogFD, 0);
exit(2);
}
}
}
else if (nLogFDprev) {
}
nMessCount = 0;
}
nMessCount++;
"Error writing to log file. "
"%10d messages lost.\n",
apr_file_trunc(nLogFD, 0);
exit(2);
}
}
else {
nMessCount++;
}
}
/* Of course we never, but prevent compiler warnings */
return 0;
}