syslogd: allow the receiving buffer size to be set.
This allows the admin to try and avoid buffer overflow when a log of logging appears in bursts.
This commit is contained in:
parent
d3020a7e64
commit
0402a70e1e
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: syslogd.8,v 1.55 2017/07/03 21:35:32 wiz Exp $
|
||||
.\" $NetBSD: syslogd.8,v 1.56 2018/11/04 20:23:08 roy Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1986, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
|
@ -29,7 +29,7 @@
|
|||
.\"
|
||||
.\" from: @(#)syslogd.8 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd March 28, 2012
|
||||
.Dd November 4, 2018
|
||||
.Dt SYSLOGD 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -39,6 +39,7 @@
|
|||
.Nm
|
||||
.Op Fl dnrSsTUv
|
||||
.Op Fl b Ar bind_address
|
||||
.Op Fl B Ar buffer_length
|
||||
.Op Fl f Ar config_file
|
||||
.Op Fl g Ar group
|
||||
.Op Fl m Ar mark_interval
|
||||
|
@ -60,6 +61,10 @@ The options are as follows:
|
|||
Specify one specific IP address or hostname to bind to.
|
||||
If a hostname is specified, the IPv4 or IPv6 address
|
||||
which corresponds to it is used.
|
||||
.It Fl B Ar buffer_length
|
||||
Sets the receiving buffer length.
|
||||
The default is 16384 bytes.
|
||||
If syslogd reports buffer overflow, this needs increasing.
|
||||
.It Fl d
|
||||
Enable debugging to the standard output,
|
||||
and do not disassociate from the controlling terminal.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: syslogd.c,v 1.125 2018/05/06 19:16:36 christos Exp $ */
|
||||
/* $NetBSD: syslogd.c,v 1.126 2018/11/04 20:23:08 roy Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1988, 1993, 1994
|
||||
|
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993, 1994\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: syslogd.c,v 1.125 2018/05/06 19:16:36 christos Exp $");
|
||||
__RCSID("$NetBSD: syslogd.c,v 1.126 2018/11/04 20:23:08 roy Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -114,6 +114,7 @@ typedef struct deadq_entry {
|
|||
#define DQ_TIMO_INIT 2
|
||||
|
||||
#define RCVBUFLEN 16384
|
||||
int buflen = RCVBUFLEN;
|
||||
/*
|
||||
* Intervals at which we flush out "message repeated" messages,
|
||||
* in seconds after previous message is logged. After each flush,
|
||||
|
@ -315,11 +316,16 @@ main(int argc, char *argv[])
|
|||
/* should we set LC_TIME="C" to ensure correct timestamps&parsing? */
|
||||
(void)setlocale(LC_ALL, "");
|
||||
|
||||
while ((ch = getopt(argc, argv, "b:dnsSf:m:o:p:P:ru:g:t:TUv")) != -1)
|
||||
while ((ch = getopt(argc, argv, "b:B:dnsSf:m:o:p:P:ru:g:t:TUv")) != -1)
|
||||
switch(ch) {
|
||||
case 'b':
|
||||
bindhostname = optarg;
|
||||
break;
|
||||
case 'B':
|
||||
buflen = atoi(optarg);
|
||||
if (buflen < RCVBUFLEN)
|
||||
buflen = RCVBUFLEN;
|
||||
break;
|
||||
case 'd': /* debug */
|
||||
Debug = D_DEFAULT;
|
||||
/* is there a way to read the integer value
|
||||
|
@ -657,7 +663,8 @@ usage(void)
|
|||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: %s [-dnrSsTUv] [-b bind_address] [-f config_file] [-g group]\n"
|
||||
"usage: %s [-dnrSsTUv] [-b bind_address] [-B buffer_length]\n"
|
||||
"\t[-f config_file] [-g group]\n"
|
||||
"\t[-m mark_interval] [-P file_list] [-p log_socket\n"
|
||||
"\t[-p log_socket2 ...]] [-t chroot_dir] [-u user]\n",
|
||||
getprogname());
|
||||
|
@ -667,15 +674,15 @@ usage(void)
|
|||
static void
|
||||
setsockbuf(int fd, const char *name)
|
||||
{
|
||||
int buflen;
|
||||
int curbuflen;
|
||||
socklen_t socklen = sizeof(buflen);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buflen, &socklen) == -1) {
|
||||
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &curbuflen, &socklen) == -1) {
|
||||
logerror("getsockopt: SO_RCVBUF: `%s'", name);
|
||||
return;
|
||||
}
|
||||
if (buflen >= RCVBUFLEN)
|
||||
if (curbuflen >= buflen)
|
||||
return;
|
||||
buflen = RCVBUFLEN;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buflen, socklen) == -1) {
|
||||
logerror("setsockopt: SO_RCVBUF: `%s'", name);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue