syslogd/sysklogd-1.4.1-ksyslogsize.diff
Marcus Meissner 53bbc01f78 Accepting request 24994 from home:elvigia:branches:Base:System
Copy from home:elvigia:branches:Base:System/syslogd via accept of submit request 24994 revision 2.
Request was accepted with message:
ok

OBS-URL: https://build.opensuse.org/request/show/24994
OBS-URL: https://build.opensuse.org/package/show/Base:System/syslogd?expand=0&rev=10
2009-11-25 15:23:34 +00:00

93 lines
2.3 KiB
Diff

Index: klogd.c
===================================================================
--- klogd.c.orig 2009-11-24 18:12:53.393383000 +0100
+++ klogd.c 2009-11-24 18:12:54.840288000 +0100
@@ -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
/*