91 lines
2.1 KiB
Diff
91 lines
2.1 KiB
Diff
--- klogd.c
|
|
+++ klogd.c 2004-07-27 11:53:48.985727118 +0000
|
|
@@ -299,8 +299,10 @@ static int use_syscall = 0,
|
|
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;
|
|
@@ -937,8 +939,8 @@ static void LogKernelLine(void)
|
|
* which will contain old messages. Then read the kernel log
|
|
* messages into this fresh buffer.
|
|
*/
|
|
- memset(log_buffer, '\0', sizeof(log_buffer));
|
|
- if ( (rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer))) < 0 )
|
|
+ memset(log_buffer, '\0', log_buf_size);
|
|
+ if ( (rdcnt = ksyslog(2, log_buffer, log_buf_size-1)) < 0 )
|
|
{
|
|
if ( errno == EINTR )
|
|
return;
|
|
@@ -962,8 +964,8 @@ static void LogProcLine(void)
|
|
* 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;
|
|
@@ -976,6 +978,44 @@ static void LogProcLine(void)
|
|
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)
|
|
|
|
@@ -1053,6 +1093,8 @@ int main(argc, argv)
|
|
console_log_level = *log_level - '0';
|
|
}
|
|
|
|
+ /* get/probe for the kernel ring buffer size */
|
|
+ SetBufSize();
|
|
|
|
#ifndef TESTING
|
|
/*
|