Commit Graph

189 Commits

Author SHA1 Message Date
Baptiste Daroussin
fdec22c37d syslogd(8): add an 'include' keyword
All the '.conf' files not beginning with a '.' contained int he directory
following the keyword will be included.

This keyword can only be used in the first level configuration files.

Modify the default syslogd.conf to 'include' /etc/syslog.d and
/usr/local/etc/syslog.d

It simplify a lot handling of syslog from automation tools.

Reviewed by:	markj, kib (via irc)
Approved by:	markj
MFC after:	2 weeks
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D8402
2016-11-01 01:41:24 +00:00
Baptiste Daroussin
fafe86ce27 Directly set the O_NONBLOCK flags via open(2) 2016-09-11 18:58:44 +00:00
Alan Somers
f32e43a6a8 syslogd: Enable repeated line compression for lines of any length.
Enable repeated line compression for lines of any length, instead of only
short lines. AFAICT repeated line compression was limited to short lines as
a RAM optimization, which made sense when karels added it in 1988, but no
longer.  The penalty is a paltry 904B of RAM per file logged.

Reviewed by:	rpaulo
MFC after:	32 days
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D4475
2016-01-27 16:17:15 +00:00
Kurt Lidl
247027652e Have syslogd honor 'mesg' status when logging to users.
PR:		bin/196742
Submitted by:	jef at mail acme com
Approved by:	rpaulo (mentor)
Differential Revision:	https://reviews.freebsd.org/D4270
2015-11-25 20:01:11 +00:00
Xin LI
e54569ecca die() would never return, mark it as so.
MFC after:	2 weeks
2015-08-27 18:11:00 +00:00
Enji Cooper
c1987c2852 Set f_file to -1/F_UNUSED when after closing when possible
This will help ensure we don't trash file descriptors that get used later on
in the daemon

Found via internal Coverity scan

MFC after: 2 weeks
Discussed with: cem, ed, markj
Differential Revision: https://reviews.freebsd.org/D3081
Submitted by: Miles Ohlrich <miles.ohlrich@isilon.com>
Sponsored by: EMC / Isilon Storage Division
2015-08-05 03:17:06 +00:00
Rui Paulo
baa557331e syslogd: re-read the timezone when receive a SIGHUP.
syslogd already re-reads the configuration file and the hostname when
receiving a SIGHUP, so it makes sense to reset the timezone.
Special care was taken to ensure we don't break installations running
with a custom TZ variable.

PR:		196905
Submitted by:	Kurt Lidl <lidl pix.net>
Sponsored by:	Pi-Coral, Inc.
2015-06-16 22:42:19 +00:00
Rui Paulo
e87161769c syslogd: don't leak finet0.
Submitted by:	Kurt Lidl <lidl pix.net>
Sponsored by:	Pi-Coral, Inc.
2015-06-16 22:31:38 +00:00
Rui Paulo
38076b4ba5 syslogd: support multiple -b options.
It's now possible to bind multiple sockets to different IP addresses.

PR:		159305
Submitted by:	Kurt Lidl <lidl pix.net>
Sponsored by:	Pi-Coral, Inc.
2015-06-16 22:26:22 +00:00
Sergey Kandaurov
fb0e21cfe8 Update .Dd, sync usage() for -F. Missed in previous change. 2015-03-03 20:23:59 +00:00
Rui Paulo
36285e787f Add and document an option to cause syslogd to run in the
foreground.

This allows a separate process to monitor when and how
syslogd exits. That process can then restart syslogd if needed.

Differential Revision:	https://reviews.freebsd.org/D1985
Submitted by:	Ravi Pokala
Reviewed by:	allanjude (man page)
2015-03-03 20:07:59 +00:00
Ed Schouten
0f0d5f6e45 Make syslogd work in case shutdown() is POSIX-ly correct.
On POSIX conformant systems, shutdown() should return ENOTCONN when not
connected. We attempted to fix this once (kern/84761), but this change
got backed out because it 'breaks code' (r150155).

I just reapplied the patch and indeed, syslogd fails on startup. Make it
easier to re-enable this change in the future by paching up syslogd to
do the right thing.

MFC after:	3 weeks
Sponsored by:	Nuxi
2015-02-19 18:56:39 +00:00
Dimitry Andric
bd496ef499 Fix two clang 3.6.0 warnings in usr.sbin/syslogd:
usr.sbin/syslogd/syslogd.c:1023:10: error: address of array 'f->f_prevline' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
                    f->f_prevline && !strcmp(msg, f->f_prevline) &&
                    ~~~^~~~~~~~~~
usr.sbin/syslogd/syslogd.c:1178:16: error: address of array 'f->f_prevline' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
        } else if (f->f_prevline) {
               ~~  ~~~^~~~~~~~~~

In both cases, the f_prevline field of struct filed is a char array, so
it can never be null.  Remove the checks.

Reviewed by:	jilles
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D1716
2015-02-05 22:28:00 +00:00
Andrey V. Elsukov
cf93a6321a Increase the buffer size to keep the list of programm names when
parsing programm specification. It is safe to not check out of bounds
access, because !isprint(p[i]) check will stop reading, when '\0'
character will be read from the input string.

Obtained from:	Yandex LLC
MFC after:	1 week
Sponsored by:	Yandex LLC
2014-12-12 11:29:54 +00:00
Ian Lepore
f0c7dfca42 Add ENETUNREACH and EADDRNOTAVAIL to the list of errors that are potentially
transient and shouldn't result in closing the socket and giving up forever.
2013-11-13 01:04:02 +00:00
Ian Lepore
6a3e86ff22 This fixes 3 problems in syslogd related to sizing receive buffers...
- A call was misplaced at the wrong level of nested if blocks, so that
  the buffers for unix domain sockets (/dev/log, /dev/klog) were never
  increased at all; they remained at a way-too-small default size of 4096.

- The function that was supposed to double the size of the buffer
  sometimes did nothing, and sometimes installed a wildly-wrong buffer
  size (either too large or too small) due to an unitialized 'slen'
  variable passed to getsockopt().  Most often it doubled the UDP buffers
  from 40k to 80k because accidentally there would be harmless stack
  garbage in the unitialized variables.

- The whole concept of blindly doubling a socket's buffer size without
  knowing what size it started at is a design flaw that has to be called a
  bug.  If the double_rbuf() function had worked at all (I.E., if the
  other two bugs didn't exist) this would lead to UDP sockets having an
  80k buffer while unix dgram sockets get an 8k buffer.  There's nothing
  about the problem being solved that requires larger buffers for UDP than
  for unix dgram sockets -- the buffering requirements are the same
  regardless of socket type.

This change renames the double_rbuf() function to increase_rbuf() and
increases the buffer size on all types of sockets to 80k.  80k was
chosen only because it appears to be the size the original change was
shooting for, and it certainly seems to be reasonably large (I might
have picked 64k in the absence of any historical guidance).

PR:		160433
Submitted by:	me, in 2011.
2013-11-13 01:01:15 +00:00
Jilles Tjoelker
f35bb1a01e syslogd: Use closefrom() instead of getdtablesize()/close() loop.
When syslogd forks a process for '|' destinations, it closes all file
descriptors greater than 2.

Use closefrom() for this instead of a getdtablesize()/close() loop because
it is both faster and avoids leaving file descriptors open because the limit
was lowered after they were opened.

MFC after:	1 week
2013-04-27 13:26:35 +00:00
Mark Johnston
f26612d3ac - Make sure that errno isn't modified before calling logerror() in error
conditions.
- Don't check for AF_INET6 when compiled without INET6 support.

PR:		bin/173930
Submitted by:	Garrett Cooper <yanegomi@gmail.com>
Approved by:	rstone (co-mentor)
MFC after:	1 week
2012-12-20 23:21:20 +00:00
Ed Schouten
39893d565a Add missing const keywords. 2012-10-19 14:29:03 +00:00
Baptiste Daroussin
2c0a5e3cee Add support for ipv6 addresses as destination
PR:		bin/150530
Submitted by:	andy white <andywhite@gmail.com>
Tested by:	Olivier Cochard-Labbe <olivier@cochard.me>
MFC after:	1 month
2012-09-12 10:39:47 +00:00
Xin LI
35741267c0 Add a new option, -N to disable the default and recommended syslogd(8)
behavior, which binds to the well known UDP port.

This option implies -s.

MFC after:	2 months
2011-07-14 07:33:53 +00:00
David Malone
98d1f19ba2 Here v->iov_len has been assigned the return value from snprintf.
Checking if it is > 0 doesn't make sense, because snprintf returns
how much space is needed if the buffer is too small. Instead, check
if the return value was greater than the buffer size, and truncate
the message if it was too long.

It isn't clear if snprintf can return a negative value in the case
of an error - I don't believe it can. If it can, then testing
v->iov_len won't help 'cos it is a size_t, not an ssize_t.

Also, as clang points out, we must always increment v here, because
later code depends on the message being in iov[5].
2011-01-19 17:17:37 +00:00
Oliver Fromme
974835c956 syslogd(8) already supports *sending* log messages to non-
standard ports, but it can't *receive* them (port 514 is
hardcoded).  This commit adds that missing feature.

(NB:  I actually needed this feature for a server farm where
multiple jails run with shared IP addresses, and every jail
should have its own syslogd process.)

As a side effect, syslogd now compiles with WARNS=6.

Approved by:	des (mentor)
MFC after:	3 weeks
2010-08-07 16:20:12 +00:00
Ed Schouten
b5810e9449 Port all applications in usr.sbin/ from libulog to utmpx. 2010-01-13 18:17:53 +00:00
Ed Schouten
2734cf8c82 Let syslogd use utmpx.
Because strings are guaranteed to be null terminated, there is no need
for excessive copying of strings, such as the line name.
2009-12-24 18:05:33 +00:00
Attilio Rao
7a7043c787 Avoid sshd, cron, syslogd and inetd to be killed under high-pressure swap
environments.
Please note that this can't be done while such processes run in jails.

Note: in future it would be interesting to find a way to do that
selectively for any desired proccess (choosen by user himself), probabilly
via a ptrace interface or whatever.

Obtained from:	Sandvine Incorporated
Reviewed by:	emaste, arch@
Sponsored by:	Sandvine Incorporated
MFC:		1 month
2009-11-25 15:12:24 +00:00
Xin LI
7ad0654cff Constify 'name' field in struct funix. This commit makes syslogd(8)
WARNS?=6 on amd64 but I have not tested under universe so keep WARNS?=
level as-is for now.
2008-12-19 18:27:51 +00:00
Tai-hwa Liang
2db461e489 Fixing !INET6 builds after bumping WARNS to 3. 2008-12-18 04:03:29 +00:00
David E. O'Brien
58a841efc2 Use passed parameter rather than the #define.
(more accurate extraction of Juniper Networks change)
2008-12-17 16:55:58 +00:00
David E. O'Brien
97f37b322d Rather than hardcode the 'struct iovec iov' array size, use a #define.
While I'm here bump WARNS to 3.

Obtained from:	Juniper Networks
2008-12-17 16:51:40 +00:00
David Malone
cfcf794e5f Add a flag, -T, that tells syslogd to always replace the timestamp on
messages from the network. We already replace malformatted timestamps
and this option lets us replace timestamps that are correctly formatted
but wrong.

PR:		120891
Submitted by:	Thomas Vogt <thomas@bsdunix.ch>
MFC after:	1 week
2008-09-25 09:28:18 +00:00
David E. O'Brien
16d2cd9432 Remove extraneous NULL pointer check - the pointer is guaranteed to be non-NULL. 2008-09-01 15:10:03 +00:00
Maxim Sobolev
7e1535c571 Allow comment to be placed at the end of a configuration line.
MFC after:	2 weeks
2008-07-09 07:37:54 +00:00
Brian Somers
d7022add17 Add a -8 switch to syslogd to prevent it from mangling 8-bit data. 2008-05-14 00:22:21 +00:00
David Malone
6f540420dd Two no-op fixes to improve corretness of syslogd code:
1) Use [AP]F_LOCAL rather than [AP]F_UNIX.
2) When copying a pipe's name, use f->f_un.f_pipe.f_pname, not f->f_un.f_fname.

PR:		20889
Submitted by:	Damieon Stark
PR:		116642
Submitted by:	Jim Pirzyk
Reviewed by:	md5
2008-02-20 21:54:41 +00:00
David E. O'Brien
e7ec0d579b + Open ctty in non-blocking mode to avoid hangs during open and close(waiting
for the port to drain).
+ Handle "*" as a priority properly.
+ Test what is free'ed.
+ Dynamically determine length vs. hardcoding it.
+ Free the previous message buffer (f_prevline) only after logging all the
  messages and just before the process exit.  Also check f_prevline for NULL
  before using it.
+ The time displayed is not synchornized with the other log destinations.
+ Fix a comment.

Obtained from:	Juniper Networks
2007-12-11 06:10:10 +00:00
David E. O'Brien
817a9ffcc4 style(9) 2007-12-05 18:00:41 +00:00
Ruslan Ermilov
b3e2f7a6d8 Sync usage() with manpage's SYNOPSIS. 2006-09-29 17:36:38 +00:00
Julian Elischer
be389c75f0 Add the ability to log to an arbitrary udp port as well as the
standard syslog port. This allows syslog to easily export lines of interest to
an external logging system.
2006-04-17 20:12:35 +00:00
Christian S.J. Peron
ae4f0fc3a9 Currently, if writing out a log entry fails, we unlink that log entry from our
internal list of logfiles. So if writev(2) fails for potentially transient
errors like ENOSPC, syslogd requires a restart, even if the filesystem has
purged.

This change allows syslogd to ignore ENOSPC space errors, so that when the
filesystem is cleaned up, syslogd will automatically start logging again
without requiring the reset. This makes syslogd(8) a bit more reliable.

MFC after:	1 week
2006-03-30 21:04:52 +00:00
Pawel Jakub Dawidek
c503ddf2cc By default (for security reasons) syslogd(8) doesn't create log files
when they don't exist, but sometimes its quite useful (eg. we use
non-standard log files and memory backed /var/, which is populated on
boot).

Add -C option which tells syslogd(8) to create log files if they don't
exist.

Glanced at by:	phk
MFC after:	3 days
2006-03-06 10:36:33 +00:00
Warner Losh
327608b266 style(9) nitlet:
foo() {
}

to

foo()
{
}
2005-10-17 16:51:06 +00:00
Olivier Houchard
c825862e6c setsockopt() will return -1 on error, not 0.
Pointy hat to:	Jeremie Le Hen
2005-09-28 16:14:43 +00:00
Olivier Houchard
20c0b2d3c3 Use SO_REUSEADDR on the socket, to make the use of syslogd in jails easier.
Submitted by:   Jeremie Le Hen <jeremie le-hen org>
2005-09-28 16:05:13 +00:00
Pawel Jakub Dawidek
fa39391686 Use pidfile(3) in syslogd(8). 2005-08-24 17:26:26 +00:00
Christian S.J. Peron
8e56d2ee05 Add cases for ENOBUFS and ENETDOWN. We need to make sure that we
catch all transient errors. This fixes situations where transient
error conditions such as network interfaces losing carrier signals
or the system running out of mbufs would result in the permanent
removal of forwarding syslog messages.

MFC after:	1 week
2005-05-19 21:09:44 +00:00
Hajimu UMEMOTO
4f10131848 NI_WITHSCOPEID cleanup. Neither RFC 2553 nor RFC 3493 defines
NI_WITHSCOPEID, and our getaddrinfo(3) does nothing special
for it, now.
2005-05-13 16:31:11 +00:00
Hiroki Sato
15f3d79b55 Add -S option which allows to change the pathname of the privileged
socket /var/run/logpriv.

Reviewed by:	glebius and kensmith
MFC after:	2 days
2005-04-13 03:19:41 +00:00
Gleb Smirnoff
b4e852907f Check that supplied facility is not bigger than LOG_NFACILITIES.
PR:		bin/79260
Submitted by:	Shuichi KITAGUCHI
2005-03-28 10:59:19 +00:00
David Malone
f56bb70ae6 Allow ':' and '%' in hostname specifications so that we can specify IPv6
addresses and scope IDs.

MFC after:	3 weeks
2004-12-28 22:25:04 +00:00