diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-10-09 09:43:18 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-10-09 09:43:18 +0000 |
commit | 9fba16c0c820acbd4445a07f86329e94e9a15949 (patch) | |
tree | 02298f6f20d982cb8daed726a8d68e0abdd14798 /sysklogd/syslogd.c | |
parent | d279ec3d6a6fbe679b01862989573c87cb146d70 (diff) | |
download | busybox-w32-9fba16c0c820acbd4445a07f86329e94e9a15949.tar.gz busybox-w32-9fba16c0c820acbd4445a07f86329e94e9a15949.tar.bz2 busybox-w32-9fba16c0c820acbd4445a07f86329e94e9a15949.zip |
Arnd Ben Otto writes:
Hi Eric
I have written a small patch for the Busybox syslogd. With this patch
one can limit the size of the messagfile. As soon as the limit is
reached the syslogd can rotate or purge the messagefile(s) on his own.
There is no necessity to use an external rotatescript.
Even if logread does something similar, its very handy to have some
messagefile after your box crash.
I wrote this patch initial vor BB 0.6x where no cron daemon was avail.
Now I adapted it for the new Version and i hope it is still useful. At
least I still use it :-)
bye
Arnd
git-svn-id: svn://busybox.net/trunk/busybox@7623 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'sysklogd/syslogd.c')
-rw-r--r-- | sysklogd/syslogd.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 3ba239882..74b242c42 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -58,6 +58,14 @@ static char lfile[MAXPATHLEN]; | |||
58 | 58 | ||
59 | static const char *logFilePath = __LOG_FILE; | 59 | static const char *logFilePath = __LOG_FILE; |
60 | 60 | ||
61 | #ifdef CONFIG_FEATURE_ROTATE_LOGFILE | ||
62 | /* max size of message file bevor being rotated */ | ||
63 | static int logFileSize = 200 * 1024; | ||
64 | |||
65 | /* number of rotated message files */ | ||
66 | static int logFileRotate = 1; | ||
67 | #endif | ||
68 | |||
61 | /* interval between marks in seconds */ | 69 | /* interval between marks in seconds */ |
62 | static int MarkInterval = 20 * 60; | 70 | static int MarkInterval = 20 * 60; |
63 | 71 | ||
@@ -305,6 +313,36 @@ static void message(char *fmt, ...) | |||
305 | O_NONBLOCK)) >= 0) { | 313 | O_NONBLOCK)) >= 0) { |
306 | fl.l_type = F_WRLCK; | 314 | fl.l_type = F_WRLCK; |
307 | fcntl(fd, F_SETLKW, &fl); | 315 | fcntl(fd, F_SETLKW, &fl); |
316 | #ifdef CONFIG_FEATURE_ROTATE_LOGFILE | ||
317 | if ( logFileSize > 0 ) { | ||
318 | struct stat statf; | ||
319 | int r = fstat(fd, &statf); | ||
320 | if( !r && (statf.st_mode & S_IFREG) | ||
321 | && (lseek(fd,0,SEEK_END) > logFileSize) ) { | ||
322 | if(logFileRotate > 0) { | ||
323 | int i; | ||
324 | char oldFile[(strlen(logFilePath)+3)], newFile[(strlen(logFilePath)+3)]; | ||
325 | for(i=logFileRotate-1;i>0;i--) { | ||
326 | sprintf(oldFile, "%s.%d", logFilePath, i-1); | ||
327 | sprintf(newFile, "%s.%d", logFilePath, i); | ||
328 | rename(oldFile, newFile); | ||
329 | } | ||
330 | sprintf(newFile, "%s.%d", logFilePath, 0); | ||
331 | fl.l_type = F_UNLCK; | ||
332 | fcntl (fd, F_SETLKW, &fl); | ||
333 | close(fd); | ||
334 | rename(logFilePath, newFile); | ||
335 | fd = device_open (logFilePath, | ||
336 | O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND | | ||
337 | O_NONBLOCK); | ||
338 | fl.l_type = F_WRLCK; | ||
339 | fcntl (fd, F_SETLKW, &fl); | ||
340 | } else { | ||
341 | ftruncate( fd, 0 ); | ||
342 | } | ||
343 | } | ||
344 | } | ||
345 | #endif | ||
308 | va_start(arguments, fmt); | 346 | va_start(arguments, fmt); |
309 | vdprintf(fd, fmt, arguments); | 347 | vdprintf(fd, fmt, arguments); |
310 | va_end(arguments); | 348 | va_end(arguments); |
@@ -578,7 +616,7 @@ extern int syslogd_main(int argc, char **argv) | |||
578 | char *p; | 616 | char *p; |
579 | 617 | ||
580 | /* do normal option parsing */ | 618 | /* do normal option parsing */ |
581 | while ((opt = getopt(argc, argv, "m:nO:R:LC::")) > 0) { | 619 | while ((opt = getopt(argc, argv, "m:nO:s:b:R:LC::")) > 0) { |
582 | switch (opt) { | 620 | switch (opt) { |
583 | case 'm': | 621 | case 'm': |
584 | MarkInterval = atoi(optarg) * 60; | 622 | MarkInterval = atoi(optarg) * 60; |
@@ -589,6 +627,15 @@ extern int syslogd_main(int argc, char **argv) | |||
589 | case 'O': | 627 | case 'O': |
590 | logFilePath = optarg; | 628 | logFilePath = optarg; |
591 | break; | 629 | break; |
630 | #ifdef CONFIG_FEATURE_ROTATE_LOGFILE | ||
631 | case 's': | ||
632 | logFileSize = atoi(optarg) * 1024; | ||
633 | break; | ||
634 | case 'b': | ||
635 | logFileRotate = atoi(optarg); | ||
636 | if( logFileRotate > 99 ) logFileRotate = 99; | ||
637 | break; | ||
638 | #endif | ||
592 | #ifdef CONFIG_FEATURE_REMOTE_LOG | 639 | #ifdef CONFIG_FEATURE_REMOTE_LOG |
593 | case 'R': | 640 | case 'R': |
594 | RemoteHost = bb_xstrdup(optarg); | 641 | RemoteHost = bb_xstrdup(optarg); |