[syslog-ng]pipe() under hpux-11 and timestamp

Balazs Scheidler bazsi@balabit.hu
Fri, 5 Jul 2002 10:15:40 +0200


--Dxnq1zWXvFF0Q93v
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline

On Thu, Jul 04, 2002 at 01:28:18PM +0200, Trapp, Michael wrote:
> hi,
> 
> i am running syslog-ng 1.5.18 on hpux 11.00
> with the following options:
>                 use_time_recvd(yes);
>                 use_fqdn(yes);
>                 sync(0);
>                 use_dns(yes);
>                 dns_cache(yes);
>                 dns_cache_size(10000);
>                 dns_cache_expire(3600);
>                 dns_cache_expire_failed(300);
>                 keep_hostname(no);
>                 chain_hostnames(no);
>                 gc_idle_threshold(50);
>                 gc_busy_threshold(5000);
>                 log_fifo_size(2000);
> 
> reading from udp() and pipe()
> 
> 
> as far as i can see the pipe("/dev/log") isn't working correct.
> with a simple fgets() i can see that the messages are
> '0' terminated strings, but syslog-ng reads the whole message
> obviously each message has 4096 bytes and print out several
> lines filled up with characters from the buffer behind the string
> termination.
> 
> i have also configured use_time_recvd(yes) but there are a few messages
> which don't have the right timestamp or are not in the right order (just a
> few seconds).
> in adition the day field of this lines has a leading '0'.
> 
> has anybody experienced these problems?
> are there further options to improve the performance,
> as i can see syslog-ng still miss some packets.

Attached you'll find a patch, which should solve your HP-UX logging
problems. You only need to set pad_size in this way:

source s_hpux { pipe("/dev/log" pad_size(2048)); };

Please test the patch, and if you find it working I'll release 1.5.19.

-- 
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1

--Dxnq1zWXvFF0Q93v
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: attachment; filename="hpux-pipe.diff"

Index: affile.c
===================================================================
RCS file: /var/cvs/syslog-ng/syslog-ng/src/affile.c,v
retrieving revision 1.50
diff -u -r1.50 affile.c
--- affile.c	26 Apr 2002 09:43:53 -0000	1.50
+++ affile.c	5 Jul 2002 08:06:15 -0000
@@ -145,6 +145,7 @@
        (flags . UINT32)
        (src object io_fd)
        (prefix pointer UINT8)
+       (pad_size . UINT32)
        (name string)))
 */
 
@@ -161,7 +162,7 @@
 	if (do_open_file(self->name, flags, -1, -1, -1, -1, -1, -1, 0, &fd)) {
 		lseek(fd, 0, SEEK_END);
 		self->src = io_read(make_io_fd(cfg->backend, fd, ol_string_use(self->name)), 
-			make_log_reader(0, self->prefix, cfg->log_msg_size, c), 
+			make_log_reader(0, self->prefix, cfg->log_msg_size, self->pad_size, c), 
 			NULL);
 		self->res = REMEMBER_RESOURCE(cfg->resources, &self->src->super.super);
 		return ST_OK | ST_GOON;
@@ -186,7 +187,7 @@
   		KILL_RESOURCE_NODE(cfg->resources, self->res);
 }
 
-struct log_source_driver *make_affile_source(const char *name, int flags, UINT8 *prefix)
+struct log_source_driver *make_affile_source(const char *name, int flags, UINT8 *prefix, UINT32 pad_size)
 {
 	NEW(affile_source, self);
   
@@ -196,6 +197,7 @@
 	self->name = c_format_cstring("%z", name);
 	self->flags = flags;
 	self->prefix = prefix;
+	self->pad_size = pad_size;
 	return &self->super;
 }
 
@@ -856,7 +858,7 @@
 		{ "MESSAGE", M_MESSAGE },
 		{ "SOURCEIP", M_SOURCE_IP }
 	};
-	char format[MAX_EXPANDED_MACRO], *format_ptr = format;
+	char format[cfg->log_msg_size + 1], *format_ptr = format;
 	int left = sizeof(format);
 	int i, j;
 
Index: affile.h
===================================================================
RCS file: /var/cvs/syslog-ng/syslog-ng/src/affile.h,v
retrieving revision 1.18
diff -u -r1.18 affile.h
--- affile.h	19 Mar 2002 09:26:16 -0000	1.18
+++ affile.h	5 Jul 2002 08:06:15 -0000
@@ -63,7 +63,7 @@
 void affile_set_template_escape(struct log_dest_driver *c, int enable);
 void affile_set_remove_if_older(struct log_dest_driver *c, int interval);
 
-struct log_source_driver *make_affile_source(const char *name, int flags, UINT8 *prefix);
+struct log_source_driver *make_affile_source(const char *name, int flags, UINT8 *prefix, UINT32 pad_size);
 struct log_dest_driver *make_affile_dest(const char *name, int flags);
 
 #endif
Index: afinet.c
===================================================================
RCS file: /var/cvs/syslog-ng/syslog-ng/src/afinet.c,v
retrieving revision 1.18
diff -u -r1.18 afinet.c
--- afinet.c	29 May 2002 09:42:35 -0000	1.18
+++ afinet.c	5 Jul 2002 08:06:15 -0000
@@ -89,13 +89,13 @@
 		notice("AF_INET client connected from %S, port %i\n", 
 		       inet->ip, inet->port);
 		io_read(self->client, 
-			make_log_reader(0, NULL, cfg->log_msg_size, c), 
+			make_log_reader(0, NULL, cfg->log_msg_size, 0, c), 
 			make_afsocket_source_close_callback(self));
 	}
 	else {
 		/* SOCK_DGRAM */
 		io_read(self->client, 
-			make_log_reader(1, NULL, cfg->log_msg_size, c), 
+			make_log_reader(1, NULL, cfg->log_msg_size, 0, c), 
 			make_afsocket_source_close_callback(self));
 	}
 	
Index: afunix.c
===================================================================
RCS file: /var/cvs/syslog-ng/syslog-ng/src/afunix.c,v
retrieving revision 1.21
diff -u -r1.21 afunix.c
--- afunix.c	26 Apr 2002 09:43:54 -0000	1.21
+++ afunix.c	5 Jul 2002 08:06:15 -0000
@@ -51,7 +51,7 @@
 	CAST(afsocket_source_connection, self, c);
 
 	io_read(self->client, 
-		make_log_reader(0, NULL, cfg->log_msg_size, c), 
+		make_log_reader(0, NULL, cfg->log_msg_size, 0, c), 
 		make_afsocket_source_close_callback(self));
 	
 	return ST_OK | ST_GOON;
Index: cfg-grammar.y
===================================================================
RCS file: /var/cvs/syslog-ng/syslog-ng/src/cfg-grammar.y,v
retrieving revision 1.54
diff -u -r1.54 cfg-grammar.y
--- cfg-grammar.y	10 Jun 2002 07:24:10 -0000	1.54
+++ cfg-grammar.y	5 Jul 2002 08:06:15 -0000
@@ -46,6 +46,7 @@
 static struct log_source_driver *last_source_driver;
 static struct log_dest_driver *last_dest_driver;
 UINT8 *last_prefix = NULL;
+UINT32 last_pad_size;
 
 UINT8 *
 get_last_log_prefix(void)
@@ -85,7 +86,7 @@
 %token KW_COMPRESS KW_MAC KW_AUTH KW_ENCRYPT
 %token KW_DNS_CACHE KW_DNS_CACHE_SIZE
 %token KW_DNS_CACHE_EXPIRE KW_DNS_CACHE_EXPIRE_FAILED
-%token KW_REMOVE_IF_OLDER KW_LOG_PREFIX
+%token KW_REMOVE_IF_OLDER KW_LOG_PREFIX KW_PAD_SIZE
 
 /* filter items*/
 %token KW_FACILITY KW_LEVEL KW_NETMASK KW_HOST KW_MATCH
@@ -215,12 +216,12 @@
 source_affile
 	: KW_FILE '(' string source_affile_options ')'		
           { 
-        	$$ = make_affile_source($3, 0, get_last_log_prefix()); 
+        	$$ = make_affile_source($3, 0, get_last_log_prefix(), last_pad_size); 
 		free($3); 
 	  }
 	| KW_PIPE '(' string source_affile_options ')'
 	  { 
-		$$ = make_affile_source($3, AFFILE_PIPE, get_last_log_prefix()); 
+		$$ = make_affile_source($3, AFFILE_PIPE, get_last_log_prefix(), last_pad_size); 
 		free($3); 
 	  }
 	;
@@ -232,6 +233,7 @@
 
 source_affile_option
 	: KW_LOG_PREFIX '(' string ')'				{ last_prefix = $3; }
+	| KW_PAD_SIZE '(' NUMBER ')'				{ last_pad_size = $3; }
 	;
 
 source_afsocket
Index: cfg-lex.l
===================================================================
RCS file: /var/cvs/syslog-ng/syslog-ng/src/cfg-lex.l,v
retrieving revision 1.23
diff -u -r1.23 cfg-lex.l
--- cfg-lex.l	26 Apr 2002 09:43:54 -0000	1.23
+++ cfg-lex.l	5 Jul 2002 08:06:15 -0000
@@ -99,6 +99,7 @@
 	{ "dns_cache_expire_failed", KW_DNS_CACHE_EXPIRE_FAILED },
 	{ "log_prefix",		KW_LOG_PREFIX },
 	{ "log_msg_size",	KW_LOG_MSG_SIZE },
+	{ "pad_size",		KW_PAD_SIZE },
 
 	/* source or destination items */
 	{ "file",		KW_FILE },
Index: sources.c
===================================================================
RCS file: /var/cvs/syslog-ng/syslog-ng/src/sources.c,v
retrieving revision 1.33
diff -u -r1.33 sources.c
--- sources.c	26 Apr 2002 09:43:54 -0000	1.33
+++ sources.c	5 Jul 2002 08:06:15 -0000
@@ -51,6 +51,8 @@
          (prefix pointer UINT8)
 	 (pos simple UINT32)
 	 (buffer space UINT8)
+	 (max_log_line simple UINT32)
+	 (pad_size simple UINT32)
          (next object log_handler)))
 */
 
@@ -82,11 +84,14 @@
 	size_t salen = sizeof(sabuf);
 
 	if (!closure->dgram) {
-		n = A_READ(read, MAX_LOG_LINE - closure->pos, closure->buffer + closure->pos);
+		if (closure->pad_size)
+			n = A_READ(read, MIN(closure->max_log_line, closure->pad_size), closure->buffer + closure->pos);
+		else
+			n = A_READ(read, closure->max_log_line - closure->pos, closure->buffer + closure->pos);
 		salen = 0;
 	}
 	else
-		n = A_RECV(read, MAX_LOG_LINE - closure->pos, closure->buffer + closure->pos, (abstract_addr *) &sabuf, &salen);
+		n = A_RECV(read, closure->max_log_line - closure->pos, closure->buffer + closure->pos, (abstract_addr *) &sabuf, &salen);
 
 	switch(n) {
 	case 0:
@@ -102,6 +107,11 @@
 	eol = memchr(closure->buffer, '\0', closure->pos);
 	if (eol == NULL)
 		eol = memchr(closure->buffer, '\n', closure->pos);
+	if (closure->pad_size && eol) {
+		do_handle_line(closure, eol - closure->buffer, closure->buffer, salen ? (abstract_addr *) &sabuf : NULL, salen);
+		closure->pos = 0;
+		return ST_OK | ST_GOON;
+	}
 	if (!eol && closure->pos) {
 		/* we don't have a terminating nl nor \0 */
 		do_handle_line(closure, closure->pos, closure->buffer, salen ? (abstract_addr *) &sabuf : NULL, salen);
@@ -139,6 +149,7 @@
 make_log_reader(UINT32 dgram, 
 		UINT8 *prefix,
 		UINT32 max_log_line,
+		UINT32 pad_size,
 		struct log_handler *next)
 {
 	NEW(log_reader, self);
@@ -147,6 +158,8 @@
 	self->dgram = dgram;
 	self->next = next;
 	self->prefix = prefix;
+	self->max_log_line = MAX(max_log_line, pad_size) + 1;
+	self->pad_size = pad_size;
 	self->buffer = ol_space_alloc(max_log_line);
 	
 	return &self->super;
Index: sources.h
===================================================================
RCS file: /var/cvs/syslog-ng/syslog-ng/src/sources.h,v
retrieving revision 1.14
diff -u -r1.14 sources.h
--- sources.h	26 Apr 2002 09:43:54 -0000	1.14
+++ sources.h	5 Jul 2002 08:06:15 -0000
@@ -64,6 +64,7 @@
 make_log_reader(UINT32 dgram, 
 		UINT8 *prefix,
 		UINT32 max_log_line,
+		UINT32 pad_size,
 		struct log_handler *next);
 
 struct log_source_group *make_source_group(const char *name, struct log_source_driver *drvs);

--Dxnq1zWXvFF0Q93v--