diff options
Diffstat (limited to 'sysklogd')
-rw-r--r-- | sysklogd/Config.in | 8 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 49 |
2 files changed, 56 insertions, 1 deletions
diff --git a/sysklogd/Config.in b/sysklogd/Config.in index 87b9ed7ac..83640bb3f 100644 --- a/sysklogd/Config.in +++ b/sysklogd/Config.in | |||
@@ -20,6 +20,14 @@ config CONFIG_SYSLOGD | |||
20 | wrong. And something almost always will go wrong if | 20 | wrong. And something almost always will go wrong if |
21 | you wait long enough.... | 21 | you wait long enough.... |
22 | 22 | ||
23 | config CONFIG_FEATURE_ROTATE_LOGFILE | ||
24 | bool " Rotate message files" | ||
25 | default n | ||
26 | depends on CONFIG_SYSLOGD | ||
27 | help | ||
28 | This enables syslogd to rotate the message files | ||
29 | on his own. No need to use an external rotatescript. | ||
30 | |||
23 | config CONFIG_FEATURE_REMOTE_LOG | 31 | config CONFIG_FEATURE_REMOTE_LOG |
24 | bool " Remote Log support" | 32 | bool " Remote Log support" |
25 | default n | 33 | default n |
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); |