Lines 70-79
Link Here
|
70 |
fprintf(stderr, "%s\n", reason); |
70 |
fprintf(stderr, "%s\n", reason); |
71 |
} |
71 |
} |
72 |
fprintf(stderr, |
72 |
fprintf(stderr, |
73 |
"Usage: %s [-l] [-f] <logfile> " |
73 |
"Usage: %s [-N <n>] [-l] [-f] <logfile> " |
74 |
"{<rotation time in seconds>|<rotation size in megabytes>} " |
74 |
"{<rotation time in seconds>|<rotation size in megabytes>} " |
75 |
"[offset minutes from UTC]\n\n", |
75 |
"[offset minutes from UTC]\n\n", |
76 |
argv0); |
76 |
argv0); |
|
|
77 |
fprintf(stderr, |
78 |
"if [-N <n>] is used, the log file will use the name specified without extensions (/some/where) \n" |
79 |
" and roll the old logs to /some/where.n, total n files will be kept\n" |
80 |
" n must be greater than 0 \n\n", |
81 |
argv0); |
77 |
#ifdef OS2 |
82 |
#ifdef OS2 |
78 |
fprintf(stderr, |
83 |
fprintf(stderr, |
79 |
"Add this:\n\nTransferLog \"|%s.exe /some/where 86400\"\n\n", |
84 |
"Add this:\n\nTransferLog \"|%s.exe /some/where 86400\"\n\n", |
Lines 112-126
Link Here
|
112 |
|
117 |
|
113 |
int main (int argc, const char * const argv[]) |
118 |
int main (int argc, const char * const argv[]) |
114 |
{ |
119 |
{ |
115 |
char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ]; |
120 |
char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ], buf3[MAX_PATH], buf4[MAX_PATH]; |
116 |
int tLogEnd = 0, tRotation = 0, utc_offset = 0; |
121 |
int tLogEnd = 0, tRotation = 0, utc_offset = 0; |
117 |
unsigned int sRotation = 0; |
122 |
unsigned int sRotation = 0; |
118 |
int nMessCount = 0; |
123 |
int nMessCount = 0; |
119 |
apr_size_t nRead, nWrite; |
124 |
apr_size_t nRead, nWrite; |
120 |
int use_strftime = 0; |
125 |
int use_strftime = 0; |
121 |
int use_localtime = 0; |
126 |
int use_localtime = 0; |
|
|
127 |
int use_num = 0; |
128 |
int num_to_keep = 0; |
122 |
int bypass_io = 0; |
129 |
int bypass_io = 0; |
123 |
int now = 0; |
130 |
int now = 0; |
|
|
131 |
int i = 0; |
124 |
const char *szLogRoot; |
132 |
const char *szLogRoot; |
125 |
apr_file_t *f_stdin, *nLogFD = NULL, *nLogFDprev = NULL; |
133 |
apr_file_t *f_stdin, *nLogFD = NULL, *nLogFDprev = NULL; |
126 |
apr_pool_t *pool; |
134 |
apr_pool_t *pool; |
Lines 137-143
Link Here
|
137 |
|
145 |
|
138 |
apr_pool_create(&pool, NULL); |
146 |
apr_pool_create(&pool, NULL); |
139 |
apr_getopt_init(&opt, pool, argc, argv); |
147 |
apr_getopt_init(&opt, pool, argc, argv); |
140 |
while ((rv = apr_getopt(opt, "lf", &c, &optarg)) == APR_SUCCESS) { |
148 |
while ((rv = apr_getopt(opt, "lfN", &c, &optarg)) == APR_SUCCESS) { |
141 |
switch (c) { |
149 |
switch (c) { |
142 |
case 'l': |
150 |
case 'l': |
143 |
use_localtime = 1; |
151 |
use_localtime = 1; |
Lines 145-150
Link Here
|
145 |
case 'f': |
153 |
case 'f': |
146 |
bypass_io = 1; |
154 |
bypass_io = 1; |
147 |
break; |
155 |
break; |
|
|
156 |
case 'N': |
157 |
use_num = 1; |
158 |
num_to_keep = atoi(argv[opt->ind++]); |
159 |
if ( num_to_keep <= 0 ) { |
160 |
usage(argv[0], "Invalid 'number of old files' to keep parameter"); |
161 |
}; |
162 |
break; |
148 |
} |
163 |
} |
149 |
} |
164 |
} |
150 |
|
165 |
|
Lines 207-212
Link Here
|
207 |
if (nLogFD != NULL && now >= tLogEnd) { |
222 |
if (nLogFD != NULL && now >= tLogEnd) { |
208 |
nLogFDprev = nLogFD; |
223 |
nLogFDprev = nLogFD; |
209 |
nLogFD = NULL; |
224 |
nLogFD = NULL; |
|
|
225 |
if (use_num) { |
226 |
for ( i = num_to_keep; i > 1 ; i-- ) { |
227 |
sprintf(buf4, "%s.%d", buf2, i); |
228 |
sprintf(buf3, "%s.%d", buf2, i - 1); |
229 |
rename(buf3, buf4); |
230 |
} |
231 |
rename(buf2, buf3); |
232 |
} |
210 |
} |
233 |
} |
211 |
} |
234 |
} |
212 |
else if (sRotation) { |
235 |
else if (sRotation) { |
Lines 221-226
Link Here
|
221 |
if (current_size > sRotation) { |
244 |
if (current_size > sRotation) { |
222 |
nLogFDprev = nLogFD; |
245 |
nLogFDprev = nLogFD; |
223 |
nLogFD = NULL; |
246 |
nLogFD = NULL; |
|
|
247 |
if (use_num) { |
248 |
for ( i = num_to_keep; i > 1 ; i-- ) { |
249 |
sprintf(buf4, "%s.%d", buf2, i); |
250 |
sprintf(buf3, "%s.%d", buf2, i - 1); |
251 |
rename(buf3, buf4); |
252 |
} |
253 |
rename(buf2, buf3); |
254 |
} |
224 |
} |
255 |
} |
225 |
} |
256 |
} |
226 |
else { |
257 |
else { |
Lines 247-260
Link Here
|
247 |
apr_time_exp_gmt(&e, tNow); |
278 |
apr_time_exp_gmt(&e, tNow); |
248 |
apr_strftime(buf2, &rs, sizeof(buf2), szLogRoot, &e); |
279 |
apr_strftime(buf2, &rs, sizeof(buf2), szLogRoot, &e); |
249 |
} |
280 |
} |
|
|
281 |
else if (use_num) { |
282 |
sprintf(buf2, "%s", szLogRoot); |
283 |
} |
250 |
else { |
284 |
else { |
251 |
sprintf(buf2, "%s.%010d", szLogRoot, tLogStart); |
285 |
sprintf(buf2, "%s.%010d", szLogRoot, tLogStart); |
252 |
} |
286 |
} |
253 |
tLogEnd = tLogStart + tRotation; |
287 |
tLogEnd = tLogStart + tRotation; |
254 |
pfile_prev = pfile; |
288 |
pfile_prev = pfile; |
255 |
apr_pool_create(&pfile, pool); |
289 |
apr_pool_create(&pfile, pool); |
256 |
rv = apr_file_open(&nLogFD, buf2, APR_WRITE | APR_CREATE | APR_APPEND, |
290 |
if (use_num) { |
|
|
291 |
rv = apr_file_open(&nLogFD, buf2, APR_WRITE | APR_CREATE, |
257 |
APR_OS_DEFAULT, pfile); |
292 |
APR_OS_DEFAULT, pfile); |
|
|
293 |
} |
294 |
else { |
295 |
rv = apr_file_open(&nLogFD, buf2, APR_WRITE | APR_CREATE | APR_APPEND, |
296 |
APR_OS_DEFAULT, pfile); |
297 |
} |
258 |
if (rv != APR_SUCCESS) { |
298 |
if (rv != APR_SUCCESS) { |
259 |
char error[120]; |
299 |
char error[120]; |
260 |
|
300 |
|