Return-Path: Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 35603 invoked by uid 500); 12 Jun 2002 21:46:52 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 35557 invoked by uid 500); 12 Jun 2002 21:46:52 -0000 Delivered-To: apmail-httpd-2.0-cvs@apache.org Date: 12 Jun 2002 21:46:51 -0000 Message-ID: <20020612214651.39842.qmail@icarus.apache.org> From: bnicholes@apache.org To: httpd-2.0-cvs@apache.org Subject: cvs commit: httpd-2.0 CHANGES X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bnicholes 2002/06/12 14:46:50 Modified: support rotatelogs.c . CHANGES Log: Added log rotation based on file size to the RotateLog support utility. Revision Changes Path 1.24 +62 -17 httpd-2.0/support/rotatelogs.c Index: rotatelogs.c =================================================================== RCS file: /home/cvs/httpd-2.0/support/rotatelogs.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- rotatelogs.c 11 Jun 2002 19:02:02 -0000 1.23 +++ rotatelogs.c 12 Jun 2002 21:46:50 -0000 1.24 @@ -94,7 +94,8 @@ int main (int argc, const char * const argv[]) { char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ]; - int tLogEnd = 0, tRotation, utc_offset = 0; + int tLogEnd = 0, tRotation = 0, utc_offset = 0; + unsigned int sRotation = 0; int nMessCount = 0; apr_size_t nRead, nWrite; int use_strftime = 0; @@ -102,6 +103,7 @@ const char *szLogRoot; apr_file_t *f_stdin, *nLogFD = NULL, *nLogFDprev = NULL; apr_pool_t *pool; + char *ptr = NULL; apr_app_initialize(&argc, &argv, NULL); atexit(apr_terminate); @@ -110,7 +112,7 @@ if (argc < 3 || argc > 4) { fprintf(stderr, "Usage: %s " - "[offset minutes from UTC]\n\n", + "[offset minutes from UTC] or \n\n", argv[0]); #ifdef OS2 fprintf(stderr, @@ -120,24 +122,40 @@ fprintf(stderr, "Add this:\n\nTransferLog \"|%s /some/where 86400\"\n\n", argv[0]); + fprintf(stderr, + "or \n\nTransferLog \"|%s /some/where 5M\"\n\n", argv[0]); #endif fprintf(stderr, "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. this time will always be a\nmultiple of the " - "rotation time, so you can synchronize cron scripts with it).\n" - "At the end of each rotation time a new log is started.\n"); + "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); } szLogRoot = argv[1]; - if (argc >= 4) { - utc_offset = atoi(argv[3]) * 60; + + ptr = strchr (argv[2], 'M'); + if (ptr) { + if (*(ptr+1) == '\0') { + sRotation = atoi(argv[2]) * 1048576; + } + if (sRotation == 0) { + fprintf(stderr, "Invalid rotation size parameter\n"); + exit(1); + } } - tRotation = atoi(argv[2]); - if (tRotation <= 0) { - fprintf(stderr, "Rotation time must be > 0\n"); - exit(6); + else { + if (argc >= 4) { + utc_offset = atoi(argv[3]) * 60; + } + tRotation = atoi(argv[2]); + if (tRotation <= 0) { + fprintf(stderr, "Rotation time must be > 0\n"); + exit(6); + } } use_strftime = (strchr(szLogRoot, '%') != NULL); @@ -150,17 +168,44 @@ nRead = sizeof(buf); if (apr_file_read(f_stdin, buf, &nRead) != APR_SUCCESS) exit(3); - now = (int)(apr_time_now() / APR_USEC_PER_SEC) + utc_offset; if (nRead == 0) exit(3); - if (nLogFD != NULL && (now >= tLogEnd || nRead < 0)) { - nLogFDprev = nLogFD; - nLogFD = NULL; + if (tRotation) { + now = (int)(apr_time_now() / APR_USEC_PER_SEC) + utc_offset; + if (nLogFD != NULL && (now >= tLogEnd || nRead < 0)) { + nLogFDprev = nLogFD; + nLogFD = NULL; + } } + else if (sRotation) { + apr_finfo_t finfo; + unsigned int current_size = -1; + + if ((nLogFD != NULL) && + (apr_file_info_get(&finfo, APR_FINFO_SIZE, nLogFD) == APR_SUCCESS)) { + current_size = finfo.size; + } + + if (current_size > sRotation || nRead < 0) { + nLogFDprev = nLogFD; + nLogFD = NULL; + } + } + else { + fprintf(stderr, "No rotation time or size specified\n"); + exit(2); + } + if (nLogFD == NULL) { - int tLogStart = (now / tRotation) * tRotation; + int tLogStart; + + if (tRotation) + tLogStart = (now / tRotation) * tRotation; + else + tLogStart = apr_time_now() / APR_USEC_PER_SEC; + if (use_strftime) { - apr_time_t tNow = tLogStart * APR_USEC_PER_SEC; + apr_time_t tNow = tLogStart * APR_USEC_PER_SEC; apr_time_exp_t e; apr_size_t rs; 1.823 +3 -0 httpd-2.0/CHANGES Index: CHANGES =================================================================== RCS file: /home/cvs/httpd-2.0/CHANGES,v retrieving revision 1.822 retrieving revision 1.823 diff -u -r1.822 -r1.823 --- CHANGES 11 Jun 2002 14:43:03 -0000 1.822 +++ CHANGES 12 Jun 2002 21:46:50 -0000 1.823 @@ -1,6 +1,9 @@ Changes with Apache 2.0.38 + *) Added log rotation based on file size to the RotateLog support + utility. [Brad Nicholes] + *) Fix some casting in mod_rewrite which broke random maps. PR 9770 [Allan Edwards, Greg Ames, Jeff Trawick]