syslogd/sysklogd-1.4.1-ksyslogsize.diff

95 lines
2.3 KiB
Diff
Raw Normal View History

---
klogd.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 47 insertions(+), 5 deletions(-)
--- klogd.c
+++ klogd.c 2022-10-14 13:17:38.386601331 +0000
@@ -309,8 +309,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;
@@ -932,8 +934,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)-1)) < 0 )
+ memset(log_buffer, '\0', log_buf_size);
+ if ( (rdcnt = ksyslog(2, log_buffer, log_buf_size-1)) < 0 )
{
if ( errno == EINTR )
return;
@@ -957,8 +959,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;
@@ -971,6 +973,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)
@@ -1049,6 +1089,8 @@ int main(argc, argv)
console_log_level = *log_level - '0';
}
+ /* get/probe for the kernel ring buffer size */
+ SetBufSize();
#ifndef TESTING
/*