@@ -329,29 +329,59 @@ static void
329329open_logfile (FILE * * file ,const char * filename_format )
330330{
331331char * filename ;
332- struct stat st ;
332+ struct stat st ;
333333bool rotation_requested = false;
334334
335335filename = logfile_getname (filename_format ,time (NULL ));
336336
337- /* First check for rotationby size */
338- if (log_rotation_size > 0 )
337+ /* First check for rotation */
338+ if (log_rotation_size > 0 || log_rotation_age > 0 )
339339{
340340if (stat (filename ,& st )== -1 )
341341{
342342if (errno == ENOENT )
343343{
344344/* There is no file "filename" and rotation does not need */
345+ gotologfile_open ;
345346}
346347else
347348elog (ERROR ,"cannot stat log file \"%s\": %s" ,
348349filename ,strerror (errno ));
349350}
350351/* 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+ gotologfile_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 )
352381rotation_requested = (st .st_size >=log_rotation_size * 1024L );
353382}
354383
384+ logfile_open :
355385if (rotation_requested )
356386* file = logfile_open (filename ,"w" );
357387else