aboutsummaryrefslogtreecommitdiff
path: root/sysklogd/syslogd.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysklogd/syslogd.c')
-rw-r--r--sysklogd/syslogd.c49
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
59static const char *logFilePath = __LOG_FILE; 59static const char *logFilePath = __LOG_FILE;
60 60
61#ifdef CONFIG_FEATURE_ROTATE_LOGFILE
62/* max size of message file bevor being rotated */
63static int logFileSize = 200 * 1024;
64
65/* number of rotated message files */
66static int logFileRotate = 1;
67#endif
68
61/* interval between marks in seconds */ 69/* interval between marks in seconds */
62static int MarkInterval = 20 * 60; 70static 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);