Commit Graph

319 Commits

Author SHA1 Message Date
Maxim Sobolev
023653459a Fix another logic bug that came out of recent syslogd refactoring and exposed by
the r316874: don't call shutdown(2) on all sockets, but only net ones, which seems
to be the behaviour existed before that refactoring. Also don't call listen(2)
in datagram sockets and fix misplaced debug messages while I am here.

Reported by: peter
2017-04-15 18:20:11 +00:00
Maxim Sobolev
b98582b146 Since shutdown(2) on datagram socket is no longer a NOP after rev 316874
don't bother to select/recv on that socket. This prevents syslogd(8)
from spinning endlessly when started with the -s option (default).

Reported by:	peter
2017-04-15 02:24:22 +00:00
Hiroki Sato
f7f99edf3f Fix a regression which prevented an IPv6 address in a -b option from
working.

PR:	217939
Differential Revision:	https://reviews.freebsd.org/D10064
2017-03-20 17:46:33 +00:00
Enji Cooper
b79299b5e7 syslogd: try to print out a more helpful message in socksetup(..) if/when
getaddrinfo fails

If the asprintf call fails, fall back to the old code (as a last ditch effort
to provide the end-user with helpful output).

Sponsored by:	Dell EMC Isilon
2017-03-20 06:12:55 +00:00
Enji Cooper
9c2aa0a0a3 syslogd: fix dprintf in socksetup(..)
- Make the explanation more complete
- Correct a minor grammar nit with verb tense.
- Don't emit the message if `pe->pe_name` is NULL (it doesn't
  have much value).

MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-03-20 05:12:27 +00:00
Enji Cooper
4863f2fc55 syslogd: don't leak f on failure in cfline(..)
Free `f` if an unknown priority or facility is parsed with the function.

MFC after:	1 week
Reported by:	Coverity
CID:		1368068
Sponsored by:	Dell EMC Isilon
2017-03-20 04:25:40 +00:00
Enji Cooper
a393b6c82f syslogd: fix memory leaks in main(..) and allowaddr(..)
- main(..): free memory assigned to fdsr before calling die(..).
- allowaddr(..): free memory assigned to ap before returning from the
  function early. Add a `err` goto label to reduce freeaddrinfo/free(ap)
  logic duplication.

MFC after:	1 week
X-MFC notes:	some of this is dependent on refactoring not MFCed
Reported by:	clang static analyzer, Coverity
CID:		1367750 (ap leakage in allowaddr(..))
Submitted by:	Tom Rix <trix@juniper.net>
Reviewed by:	ngie
Sponsored by:	Dell EMC Isilon, Juniper
Differential Revision:	D10004
2017-03-15 18:15:30 +00:00
Enji Cooper
6dbd2714db Correct nuance of -a :service -> "*" in r314563, r314585
My attempt to correct the sender/receiver behavior was incorrect.
The source port of the sender for forwarded datagrams is filtered
with -a, and my change in r314585 didn't clarify that point at all.

Wording is based on suggestion by hrs.

MFC after:	28 days
X-MFC with:	r314563, r314585
Reported by:	hrs
In collaboration with:	hrs, rgrimes
Sponsored by:	Dell EMC Isilon
2017-03-04 06:19:41 +00:00
Enji Cooper
3dd94b6769 Correct verb change for service => * after r314563
`*` means that packets will be received from a remote peer on any port.
Since the point of interest is the syslogd instance (not the remote peer),
the appropriate verb is "received", not "sent".

MFC after:	1 month
X-MFC with:	r314563
Sponsored by:	Dell EMC Isilon
2017-03-03 06:13:59 +00:00
Enji Cooper
bc4536df9d Wordsmith syslogd(8)
- Clarify -p/-S options by using appropriate subject-verb modifiers
  (verb and modifiers suggested that the subject should have been
  singular).
- Simplify/correct -a description:
-- Be more terse when describing IPv4 (the "usual dotted notation"
   isn't necessarily well understood by the reader). Being blunt and
   saying "IPv4 address" with an optional netmask is.
-- prefixlen is the appropriate terminology for IPv6.
-- mask/prefixlen is optional, not required (as noted later on in the
   section).
-- split up IPv4/IPv6 use so to clarify both forms.
-- Fix wordiness when describing the optional "service" specifier.
- -T: Use "cannot" instead of "can't" [*].

Bump .Dd for the changes.

MFC after:	1 month
Reported by:	igor [*]
Reviewed by:	hrs
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D9855
2017-03-02 18:07:19 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Enji Cooper
15f0eea574 Parameterize out the length of struct filed->f_lasttime as MAXDATELEN
This removes the hardcoded value for the field (16) and the equivalent
hardcoded lengths in logmsg(..).

This change is being done to help stage future work to add RFC5424/RFC5434
support to syslogd(8).

Obtained from:	Isilon OneFS (dcd33d13da) (as part of a larger change)
Submitted by:	John Bauman <john.bauman@isilon.com>
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
2017-02-25 00:12:29 +00:00
Enji Cooper
8fe70bb8f2 Use SRCTOP instead of .CURDIR relative paths with ".."
This simplifies pathing in make/displayed output

MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-02-24 21:35:59 +00:00
Enji Cooper
916aa57754 Sort sys/ #includes some more
MFC after:	1 week
X-MFC with:	r313358
Sponsored by:	Dell EMC Isilon
2017-02-07 01:28:55 +00:00
Enji Cooper
688e4de4e7 Sort sys/ #includes and zap an unnecessary trailing space nearby
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-02-07 00:47:33 +00:00
Enji Cooper
72e282471c Use a flexible array for TypeNames instead of hardcoding the array length
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-02-07 00:42:55 +00:00
Enji Cooper
bc64f428ad Fix typos in comments (returing -> returning)
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-02-07 00:09:48 +00:00
Hiroki Sato
2f1c643658 Fix a bug which caused not to create AF_LOCAL sockets when family
is specified.

Spotted by:	Alex Deiter
2017-01-28 13:09:18 +00:00
Hiroki Sato
b4d60f9802 Add more #ifdef INET and INET6. 2017-01-11 07:21:59 +00:00
Hiroki Sato
8ffb87bf8c - Use more descriptive names for variables.
- Set O_CLOEXEC to the signal pipe and /dev/klog.
- Use a single signal handler to catch both SIGHUP and SIGCHLD.
- Fix a bug which did FD_SET() the writer-end of the pipe.
2016-12-31 13:15:52 +00:00
Hiroki Sato
00f6082b98 Remove extra NULL-check before free(3). 2016-12-31 09:52:00 +00:00
Hiroki Sato
34694ebe05 Replace two fat signal handlers with function calls in
the main I/O multiplex loop.  select() now watches
a pipe which is written by the new skinny signal
handlers and the received signals are handled inside
the loop sequencially.

This eliminates a complex signal mask to guarantee
async-signal safety.
2016-12-31 06:23:05 +00:00
Hiroki Sato
407cd97826 Retry to open an F_PIPE process when it dies unexpectedly.
Reported by:	Eugene Grosbein
PR:		215335
2016-12-31 03:07:48 +00:00
Hiroki Sato
77e315c975 - Fix -N flag (NoBind) for AF_LOCAL sockets.
- Do setsockopt(SO_RCVBUF) for AF_LOCAL sockets regardless of -s flag.
2016-12-24 23:29:50 +00:00
Enji Cooper
d97b8afd73 Unbreak syslogd after r310494
Don't close all file descriptors greater than STDERR_FILENO (2) in
waitdaemon(..) -- only close fd (file descriptor for /dev/null used in
subsequent calls to dup2) if it's greater than STDERR_FILENO.

Reported by:	subbsd@gmail.com, danny@cs.huji.ac.il
Pointyhat to:	hrs
X-MFC with:	r310494
2016-12-24 12:50:17 +00:00
Hiroki Sato
4c06e939f8 - Remove unused code.
- Use closefrom().
2016-12-24 07:13:33 +00:00
Hiroki Sato
acdd9d6a0d - More ifdef INET and INET6.
- Use STDERR_FILENO + 1 instead of "3".
- Fix dprintf() in cvthname().
2016-12-23 06:29:24 +00:00
Hiroki Sato
a3dc138e75 mdoc and style fixes. 2016-12-23 04:59:22 +00:00
Hiroki Sato
732c7a256c - Fix a use-after-free bug when dq_timeout == 1 and
sending SIGTERM to the process failed.  It is an
  unusual situation but it can happen.
- Split deadq_remove() into deadq_remove() and
  deadq_removebypid().
- Normalize variable names of struct deadq_entry *.
2016-12-22 13:46:17 +00:00
Hiroki Sato
066f8db8f3 Add a missing "default:" case. 2016-12-22 05:57:45 +00:00
Hiroki Sato
dd87e05952 Initialize a structure by using a compound literal to avoid forgetting
to zero unspecified members.
2016-12-22 05:55:44 +00:00
Hiroki Sato
1ef75d66c8 Fix debug log in the case of AF_INET6. 2016-12-22 05:28:30 +00:00
Hiroki Sato
cb7c842281 - Simplify masklen->netmask conversion for AF_INET6.
- Use iov[N] by array index instead of using pointer v = &iov[0] to
  make the compiler catch an out-of-range access of the array.
2016-12-22 05:23:38 +00:00
Hiroki Sato
bbe85c3834 Simplify type casting of struct sockaddr_in. 2016-12-21 07:05:34 +00:00
Hiroki Sato
e46b059e46 - Initialize deadq_head statically.
- Fix indent.
- Add missing -S flag into usage().
- Use nitems() for an iov array instead of a macro.
2016-12-21 06:49:21 +00:00
Hiroki Sato
e5610451b2 - Add fklog into struct socklist. Files and local/remote sockets are
now processed in struct socklist in a consistent manner.
- Add helper functions to add a new entry of struct socklist, filed, or peer.
- Use the same routine for -l, -p, and -S.
- Close /dev/klog when read(2) failed.
2016-12-21 06:42:30 +00:00
Hiroki Sato
c532386291 - Use fnmatch(3) for domanname matching of -a options.
- Document the patten matching.
- Document -S flag in SYNOPSIS.
2016-12-21 05:45:59 +00:00
Hiroki Sato
97456b7413 Escape punctuation characters. 2016-12-20 08:49:13 +00:00
Hiroki Sato
2e0ef629ee Add a NULL check. 2016-12-20 04:05:21 +00:00
Hiroki Sato
27efdcd869 Add a default socket bound to *:514 when no -b option is specified.
This was accidentally removed at r309933.

Spotted by:	Michael Butler
2016-12-20 03:41:40 +00:00
Hiroki Sato
a5636d2a3e Add a missing STAILQ_INSERT_TAIL() for allowaddr rule. 2016-12-19 17:10:30 +00:00
Hiroki Sato
442f3ba311 Remove an extra "break" which could incorrectly terminate an
STAILQ_FOREACH() loop when an AF_INET6 rule matched.

Spotted by:	cem
2016-12-13 20:55:46 +00:00
Hiroki Sato
dc96a41b44 - Refactor listening socket list. All of the listening sockets are
now maintained in a single linked-list in a transport-independent manner.
- Use queue.h for linked-list structure.
- Use linked-list for AllowedPeers.
- Use getaddrinfo(8) even for Unix Domain sockets.
- Use macros to type-casting from/to struct sockaddr{,_in,_in6}.
- Define fu_* macro for union f_un to shorten the member names.
- Remove an extra #include <sys/type.h>.
- Add "static" to non-exported symbols.
- !INET support is still incomplete but will be fixed later.

There is no functional change except for some minor debug messages.
2016-12-12 19:33:40 +00:00
Hiroki Sato
8555a6e0a4 Temporarily backout the previous commit because it was totally broken due to
unresolved merge conflicts.

Pointy hat to:	hrs
2016-12-12 19:24:52 +00:00
Hiroki Sato
783e461c73 - Refactor listening socket list. All of the listening sockets are
now maintained in a single linked-list in a transport-independent manner.
- Use queue.h for linked-list structure.
- Use linked-list for AllowedPeers.
- Use getaddrinfo(8) even for Unix Domain sockets.
- Use macros to type-casting from/to struct sockaddr{,_in,_in6}.
- Define fu_* macro for union f_un to shorten the member names.
- Remove an extra #include <sys/type.h>.
- Add "static" to non-exported symbols.
- !INET support is still incomplete but will be fixed later.

There is no functional change except for some minor debug messages.
2016-12-12 19:10:14 +00:00
Baptiste Daroussin
8ecd7189a4 Properly initialize nextp
MFC after:	1 day
2016-11-27 19:27:13 +00:00
Baptiste Daroussin
dd83a7df85 initialize *nextp which could be left uninitialized in case the configuration
file cannot be open/read

Reported by:	Coverity via cem
MFC after:	2 days
CID:		1365665
2016-11-26 15:49:59 +00:00
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