7171#include <errno.h>
7272#include <fcntl.h>
7373
74- #define BUFSIZE 65536
74+ #define BUFSIZE 65536
7575
7676#ifndef MAX_PATH
77- #define MAX_PATH 1024
77+ #define MAX_PATH 1024
7878#endif
7979
8080int main (int argc , char * argv [])
@@ -87,59 +87,59 @@ int main (int argc, char *argv[])
8787 char * szLogRoot ;
8888
8989 if (argc != 3 ) {
90- fprintf (stderr ,
91- "%s <logfile> <rotation time in seconds>\n\n" ,
92- argv [0 ]);
90+ fprintf (stderr ,
91+ "%s <logfile> <rotation time in seconds>\n\n" ,
92+ argv [0 ]);
9393#ifdef OS2
94- fprintf (stderr ,
95- "Add this:\n\nTransferLog \"|%s.exe /some/where 86400\"\n\n" ,
96- argv [0 ]);
94+ fprintf (stderr ,
95+ "Add this:\n\nTransferLog \"|%s.exe /some/where 86400\"\n\n" ,
96+ argv [0 ]);
9797#else
98- fprintf (stderr ,
99- "Add this:\n\nTransferLog \"|%s /some/where 86400\"\n\n" ,
100- argv [0 ]);
98+ fprintf (stderr ,
99+ "Add this:\n\nTransferLog \"|%s /some/where 86400\"\n\n" ,
100+ argv [0 ]);
101101#endif
102- fprintf (stderr ,
103- "to httpd.conf. The generated name will be /some/where.nnnn "
104- "where nnnn is the\nsystem time at which the log nominally "
105- "starts (N.B. this time will always be a\nmultiple of the "
106- "rotation time, so you can synchronize cron scripts with it).\n"
107- "At the end of each rotation time a new log is started.\n" );
108- exit (1 );
102+ fprintf (stderr ,
103+ "to httpd.conf. The generated name will be /some/where.nnnn "
104+ "where nnnn is the\nsystem time at which the log nominally "
105+ "starts (N.B. this time will always be a\nmultiple of the "
106+ "rotation time, so you can synchronize cron scripts with it).\n"
107+ "At the end of each rotation time a new log is started.\n" );
108+ exit (1 );
109109 }
110110
111111 szLogRoot = argv [1 ];
112112 tRotation = atoi (argv [2 ]);
113113 if (tRotation <= 0 ) {
114- fprintf (stderr , "Rotation time must be > 0\n" );
115- exit (6 );
114+ fprintf (stderr , "Rotation time must be > 0\n" );
115+ exit (6 );
116116 }
117117
118118 for (;;) {
119- nRead = read (0 , buf , sizeof buf );
120- if (nRead == 0 )
121- exit (3 );
122- if (nRead < 0 )
123- if (errno != EINTR )
124- exit (4 );
125- if (nLogFD >= 0 && (time (NULL ) >= tLogEnd || nRead < 0 )) {
126- close (nLogFD );
127- nLogFD = -1 ;
128- }
129- if (nLogFD < 0 ) {
130- time_t tLogStart = (time (NULL ) / tRotation ) * tRotation ;
131- sprintf (buf2 , "%s.%010d" , szLogRoot , (int ) tLogStart );
132- tLogEnd = tLogStart + tRotation ;
133- nLogFD = open (buf2 , O_WRONLY | O_CREAT | O_APPEND , 0666 );
134- if (nLogFD < 0 ) {
135- perror (buf2 );
136- exit (2 );
137- }
138- }
139- if (write (nLogFD , buf , nRead ) != nRead ) {
140- perror (buf2 );
141- exit (5 );
142- }
119+ nRead = read (0 , buf , sizeof buf );
120+ if (nRead == 0 )
121+ exit (3 );
122+ if (nRead < 0 )
123+ if (errno != EINTR )
124+ exit (4 );
125+ if (nLogFD >= 0 && (time (NULL ) >= tLogEnd || nRead < 0 )) {
126+ close (nLogFD );
127+ nLogFD = -1 ;
128+ }
129+ if (nLogFD < 0 ) {
130+ time_t tLogStart = (time (NULL ) / tRotation ) * tRotation ;
131+ sprintf (buf2 , "%s.%010d" , szLogRoot , (int ) tLogStart );
132+ tLogEnd = tLogStart + tRotation ;
133+ nLogFD = open (buf2 , O_WRONLY | O_CREAT | O_APPEND , 0666 );
134+ if (nLogFD < 0 ) {
135+ perror (buf2 );
136+ exit (2 );
137+ }
138+ }
139+ if (write (nLogFD , buf , nRead ) != nRead ) {
140+ perror (buf2 );
141+ exit (5 );
142+ }
143143 }
144144 /* Of course we never, but prevent compiler warnings */
145145 return 0 ;
0 commit comments