Re: svn commit: r733476 - /httpd/httpd/trunk/support/rotatelogs.c

2009-01-11 Thread Ruediger Pluem


On 01/11/2009 03:05 PM, rj...@apache.org wrote:
 Author: rjung
 Date: Sun Jan 11 06:05:39 2009
 New Revision: 733476
 
 URL: http://svn.apache.org/viewvc?rev=733476view=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=733476r1=733475r2=733476view=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_PATH1024
  #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


Re: svn commit: r733476 - /httpd/httpd/trunk/support/rotatelogs.c

2009-01-11 Thread Rainer Jung

On 11.01.2009 15:53, Ruediger Pluem wrote:


On 01/11/2009 03:05 PM, rj...@apache.org wrote:

Author: rjung
Date: Sun Jan 11 06:05:39 2009
New Revision: 733476

URL: http://svn.apache.org/viewvc?rev=733476view=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=733476r1=733475r2=733476view=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_PATH1024
  #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?


I need them in the signal handler which will be introduced as the next 
step. The signal handler will allow to trigger rotation from outside.


...

+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.


Right, will be gone in the next commit.