Activate built-in log rotation feature, disabled by default

Basically just removes the #ifdef blocks around the code.  With the
feature disabled by defult this should be safe.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2018-08-03 00:58:00 +02:00
parent 1a42935c2f
commit d7bfb2c66f
3 changed files with 11 additions and 17 deletions

View File

@ -8,6 +8,7 @@ All relevant changes to the project are documented in this file.
### Changes ### Changes
- IPv6 support forward ported from FreeBSD, by John Haxby <john.haxby@oracle.com> - IPv6 support forward ported from FreeBSD, by John Haxby <john.haxby@oracle.com>
- Built-in log rotation support from BusyBox syslogd, disabled by default
- Only read /etc/services when needed, by Martin Schulze <joey@infodrom.org> - Only read /etc/services when needed, by Martin Schulze <joey@infodrom.org>
- Improved sleep/alarm/mark implementation, - Improved sleep/alarm/mark implementation,
by Alan Jenkins <alan-jenkins@tuffmail.co.uk> by Alan Jenkins <alan-jenkins@tuffmail.co.uk>

View File

@ -111,7 +111,7 @@ described by the people from OpenBSD at
.BI "\-b " "size" .BI "\-b " "size"
This option controls the max size of files in the built-in log-rotation. This option controls the max size of files in the built-in log-rotation.
When present on the command line it activates log rotation of all files When present on the command line it activates log rotation of all files
with the given maximum size. with the given maximum size. Default: disabled (0).
.TP .TP
.BI "\-c " "count" .BI "\-c " "count"
This option controls the max number of files kept by the built-in This option controls the max number of files kept by the built-in
@ -119,7 +119,7 @@ log-rotation. To activate the built-in log rotation this option must be
combined with the combined with the
.BI "\-b" .BI "\-b"
option. The number of files kept include both gzipped files and the option. The number of files kept include both gzipped files and the
first rotated (not zipped) file. first rotated (not zipped) file. Default: 5.
.TP .TP
.B "\-d" .B "\-d"
Turns on debug mode. Using this the daemon will not proceed a Turns on debug mode. Using this the daemon will not proceed a

View File

@ -503,8 +503,8 @@ static char sccsid[] = "@(#)syslogd.c 5.27 (Berkeley) 10/10/88";
* i.e. when we are sending to or receiving from the network. * i.e. when we are sending to or receiving from the network.
* *
* Sun Oct 11 11:28:07 CEST 2009: Joachim Nilsson <troglobit@gmail.com> * Sun Oct 11 11:28:07 CEST 2009: Joachim Nilsson <troglobit@gmail.com>
* Port log rotation from BusyBox syslogd, see SYSLOG_ROTATE_FILES. * Port log rotation from BusyBox syslogd. This adds -b and -c
* This adds support for -b and -c options for size and rotate count. * options for size and rotate count. Disabled by default.
* *
* Fri Sep 10 08:29:04 CEST 2010: Martin Schulze <joey@infodrom.org> * Fri Sep 10 08:29:04 CEST 2010: Martin Schulze <joey@infodrom.org>
* Replace strcpy with memmove to fix continuation line problems * Replace strcpy with memmove to fix continuation line problems
@ -816,10 +816,8 @@ char **StripDomains = NULL; /* these domains may be stripped before writing logs
char **LocalHosts = NULL; /* these hosts are logged with their hostname */ char **LocalHosts = NULL; /* these hosts are logged with their hostname */
int NoHops = 1; /* Can we bounce syslog messages through an int NoHops = 1; /* Can we bounce syslog messages through an
intermediate host. */ intermediate host. */
#ifdef SYSLOG_ROTATE_FILES int RotateSz = 0; /* Max file size (bytes) before rotating, disabled by default */
int RotateSz = 200 * 1024; /* Max file size (bytes) before rotating, set with -b <SIZE> */ int RotateCnt = 5; /* Max number (count) of log files to keep, set with -c <NUM> */
int RotateCnt = 1; /* Max number (count) of log files to keep, set with -c <NUM> */
#endif
extern int errno; extern int errno;
/* Function prototypes. */ /* Function prototypes. */
@ -933,14 +931,12 @@ int main(argc, argv)
else else
fprintf(stderr, "Out of descriptors, ignoring %s\n", optarg); fprintf(stderr, "Out of descriptors, ignoring %s\n", optarg);
break; break;
#ifdef SYSLOG_ROTATE_FILES
case 'b': /* Max file size (bytes) before rotating log file. */ case 'b': /* Max file size (bytes) before rotating log file. */
RotateSz = atoi(optarg); RotateSz = atoi(optarg);
break; break;
case 'c': /* Number (count) of log files to keep. */ case 'c': /* Number (count) of log files to keep. */
RotateCnt = atoi(optarg); RotateCnt = atoi(optarg);
break; break;
#endif
case 'd': /* debug */ case 'd': /* debug */
Debug = 1; Debug = 1;
break; break;
@ -1267,9 +1263,7 @@ int main(argc, argv)
int usage() int usage()
{ {
fprintf(stderr, "usage: syslogd [-46Adrvh] [-l hostlist] [-m markinterval] [-n] [-p path]\n" fprintf(stderr, "usage: syslogd [-46Adrvh] [-l hostlist] [-m markinterval] [-n] [-p path]\n"
#ifdef SYSLOG_ROTATE_FILES
" [-b maxlogfilesize] [-c maxrotatecount]" " [-b maxlogfilesize] [-c maxrotatecount]"
#endif
" [-s domainlist] [-f conffile]\n"); " [-s domainlist] [-f conffile]\n");
exit(1); exit(1);
} }
@ -1864,15 +1858,17 @@ void logmsg(pri, msg, from, flags)
} /* balance parentheses for emacs */ } /* balance parentheses for emacs */
#endif #endif
#ifdef SYSLOG_ROTATE_FILES
void logrotate(f) void logrotate(f)
register struct filed *f; register struct filed *f;
{ {
struct stat statf; struct stat statf;
if (!RotateSz)
return;
fstat(f->f_file, &statf); fstat(f->f_file, &statf);
/* bug (mostly harmless): can wrap around if file > 4gb */ /* bug (mostly harmless): can wrap around if file > 4gb */
if (RotateSz && S_ISREG(statf.st_mode) && statf.st_size > RotateSz) { if (S_ISREG(statf.st_mode) && statf.st_size > RotateSz) {
if (RotateCnt) { /* always 0..99 */ if (RotateCnt) { /* always 0..99 */
int i = strlen(f->f_un.f_fname) + 3 + 1; int i = strlen(f->f_un.f_fname) + 3 + 1;
char oldFile[i]; char oldFile[i];
@ -1895,7 +1891,6 @@ void logrotate(f)
ftruncate(f->f_file, 0); ftruncate(f->f_file, 0);
} }
} }
#endif /* SYSLOG_ROTATE_FILES */
void fprintlog(f, from, flags, msg) void fprintlog(f, from, flags, msg)
register struct filed *f; register struct filed *f;
@ -2080,10 +2075,8 @@ void fprintlog(f, from, flags, msg)
if (f->f_file == -1) if (f->f_file == -1)
break; break;
#ifdef SYSLOG_ROTATE_FILES
if (f->f_type == F_FILE) if (f->f_type == F_FILE)
logrotate(f); logrotate(f);
#endif
if (writev(f->f_file, iov, 6) < 0) { if (writev(f->f_file, iov, 6) < 0) {
int e = errno; int e = errno;