2022-10-19 12:09:25 +00:00
|
|
|
---
|
|
|
|
klogd.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
|
|
|
|
1 file changed, 47 insertions(+), 5 deletions(-)
|
|
|
|
|
2010-01-19 10:40:12 +00:00
|
|
|
--- klogd.c
|
2022-10-19 12:09:25 +00:00
|
|
|
+++ klogd.c 2022-10-14 13:17:38.386601331 +0000
|
|
|
|
@@ -309,8 +309,10 @@ static int use_syscall = 0,
|
2006-12-18 23:17:53 +00:00
|
|
|
no_fork = 0; /* don't fork - don't run in daemon mode */
|
|
|
|
|
|
|
|
static char *symfile = (char *) 0,
|
|
|
|
- log_buffer[LOG_BUFFER_SIZE];
|
|
|
|
+ *log_buffer = (char *) 0;
|
|
|
|
|
|
|
|
+static int log_buf_size = 0;
|
|
|
|
+
|
|
|
|
static FILE *output_file = (FILE *) 0;
|
|
|
|
|
|
|
|
static enum LOGSRC {none, proc, kernel} logsrc;
|
2022-10-19 12:09:25 +00:00
|
|
|
@@ -932,8 +934,8 @@ static void LogKernelLine(void)
|
2006-12-18 23:17:53 +00:00
|
|
|
* which will contain old messages. Then read the kernel log
|
|
|
|
* messages into this fresh buffer.
|
|
|
|
*/
|
|
|
|
- memset(log_buffer, '\0', sizeof(log_buffer));
|
2022-10-19 12:09:25 +00:00
|
|
|
- if ( (rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer)-1)) < 0 )
|
2006-12-18 23:17:53 +00:00
|
|
|
+ memset(log_buffer, '\0', log_buf_size);
|
|
|
|
+ if ( (rdcnt = ksyslog(2, log_buffer, log_buf_size-1)) < 0 )
|
|
|
|
{
|
|
|
|
if ( errno == EINTR )
|
|
|
|
return;
|
2022-10-19 12:09:25 +00:00
|
|
|
@@ -957,8 +959,8 @@ static void LogProcLine(void)
|
2006-12-18 23:17:53 +00:00
|
|
|
* which will contain old messages. Then read the kernel messages
|
|
|
|
* from the message pseudo-file into this fresh buffer.
|
|
|
|
*/
|
|
|
|
- memset(log_buffer, '\0', sizeof(log_buffer));
|
|
|
|
- if ( (rdcnt = read(kmsg, log_buffer, sizeof(log_buffer)-1)) < 0 )
|
|
|
|
+ memset(log_buffer, '\0', log_buf_size);
|
|
|
|
+ if ( (rdcnt = read(kmsg, log_buffer, log_buf_size-1)) < 0 )
|
|
|
|
{
|
|
|
|
if ( errno == EINTR )
|
|
|
|
return;
|
2022-10-19 12:09:25 +00:00
|
|
|
@@ -971,6 +973,44 @@ static void LogProcLine(void)
|
2006-12-18 23:17:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static void SetBufSize(void)
|
|
|
|
+
|
|
|
|
+{
|
|
|
|
+ auto int n, sz;
|
|
|
|
+
|
|
|
|
+ n = ksyslog(10, NULL, 0); /* read ringbuffer size */
|
|
|
|
+ if (n > 0) {
|
|
|
|
+ log_buf_size = n;
|
|
|
|
+ log_buffer = (char *) malloc(log_buf_size);
|
|
|
|
+ if (!log_buffer) {
|
|
|
|
+ perror("ksyslog");
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!log_buf_size) {
|
|
|
|
+ sz = LOG_BUFFER_SIZE;
|
|
|
|
+ while (1) {
|
|
|
|
+ log_buffer = (char *) malloc(sz+8);
|
|
|
|
+ if (!log_buffer) {
|
|
|
|
+ perror("ksyslog");
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ n = ksyslog(3, log_buffer, sz+8);
|
|
|
|
+ if (n < sz+8 || sz >= (1<<22))
|
|
|
|
+ break;
|
|
|
|
+ free(log_buffer);
|
|
|
|
+ sz <<= 1;
|
|
|
|
+ }
|
|
|
|
+ log_buf_size = sz;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (n < 0) {
|
|
|
|
+ perror("ksyslog");
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
|
|
int main(argc, argv)
|
|
|
|
|
2022-10-19 12:09:25 +00:00
|
|
|
@@ -1049,6 +1089,8 @@ int main(argc, argv)
|
2006-12-18 23:17:53 +00:00
|
|
|
console_log_level = *log_level - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /* get/probe for the kernel ring buffer size */
|
|
|
|
+ SetBufSize();
|
|
|
|
|
|
|
|
#ifndef TESTING
|
|
|
|
/*
|