@@ -329,29 +329,59 @@ static void
329
329
open_logfile (FILE * * file , const char * filename_format )
330
330
{
331
331
char * filename ;
332
- struct stat st ;
332
+ struct stat st ;
333
333
bool rotation_requested = false;
334
334
335
335
filename = logfile_getname (filename_format , time (NULL ));
336
336
337
- /* First check for rotation by size */
338
- if (log_rotation_size > 0 )
337
+ /* First check for rotation */
338
+ if (log_rotation_size > 0 || log_rotation_age > 0 )
339
339
{
340
340
if (stat (filename , & st ) == -1 )
341
341
{
342
342
if (errno == ENOENT )
343
343
{
344
344
/* There is no file "filename" and rotation does not need */
345
+ goto logfile_open ;
345
346
}
346
347
else
347
348
elog (ERROR , "cannot stat log file \"%s\": %s" ,
348
349
filename , strerror (errno ));
349
350
}
350
351
/* Found log file "filename" */
351
- else
352
+
353
+ /* Check for rotation by age */
354
+ if (log_rotation_age > 0 )
355
+ {
356
+ char control [MAXPGPATH ];
357
+ struct stat control_st ;
358
+ FILE * control_file ;
359
+
360
+ snprintf (control , MAXPGPATH , "%s.rotation" , filename );
361
+ if (stat (control , & control_st ) == -1 )
362
+ {
363
+ if (errno == ENOENT )
364
+ {
365
+ /* There is no control file for rotation */
366
+ goto logfile_open ;
367
+ }
368
+ else
369
+ elog (ERROR , "cannot stat rotation file \"%s\": %s" ,
370
+ control , strerror (errno ));
371
+ }
372
+
373
+ /* Found control file for rotation */
374
+
375
+ control_file = fopen (control , "r" );
376
+ fclose (control_file );
377
+ }
378
+
379
+ /* Check for rotation by size */
380
+ if (!rotation_requested && log_rotation_size > 0 )
352
381
rotation_requested = (st .st_size >= log_rotation_size * 1024L );
353
382
}
354
383
384
+ logfile_open :
355
385
if (rotation_requested )
356
386
* file = logfile_open (filename , "w" );
357
387
else
0 commit comments