History log of /freebsd-current/lib/libc/gen/syslog.c
Revision Date Author Comments
# dc36d6f9 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

lib: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 2ce3ef55 03-Jan-2023 Eugene Grosbein <eugen@FreeBSD.org>

syslog: fix PID of forking process

Do not cache PID for a process that does not fabricate it,
calls openlog() before forking and does not call exec() thereafter.

PR: 268666
Fixes: e9ae9fa93745669b7dd0341d333257ad6cfe8e37
Tested by: kp
MFC after: 3 days


# 6ab555cf 01-Jan-2023 Eugene Grosbein <eugen@FreeBSD.org>

syslog(3): expand a commentary adding a reference to RFC 3164.


# e9ae9fa9 08-Aug-2022 Eugene Grosbein <eugen@FreeBSD.org>

syslog(3): unbreak log generation using fabricated PID

Recover application ability to supply fabricated PID
embedded into ident that was lost when libc switched
to generation of RFC 5424 log messages, for example:

logger -t "ident[$$]" -p user.notice "test"

It is essential for long running scripts.
Also, this change unbreaks matching resulted entries
by ident in syslog.conf:

!ident
*.* /var/log/ident.log

Without the fix, the log (and matching) was broken:

Aug 1 07:36:58 hostname ident[123][86483]: test

Now it works as expected and worked before breakage:

Aug 1 07:39:40 hostname ident[123]: test

Differential: https://reviews.freebsd.org/D36005
MFC after: 2 weeks


# ddc68905 24-Jun-2022 Gleb Smirnoff <glebius@FreeBSD.org>

libc/syslog: deprecate use of "/var/run/logpriv"

This additional socket was created in 2e89951b6f20 and 240d5a9b1ce76
to try workaround problems with classic PF_UNIX/SOCK_DGRAM sockets.

With recent changes in kernel this trick is no longer needed, so the
trick can be reverted.

In syslogd(8) we would still create the socket for the next several
major releases for compatibility.

Differential revision: https://reviews.freebsd.org/D35305


# f9e62cba 24-Jun-2022 Gleb Smirnoff <glebius@FreeBSD.org>

libc/syslog: fully deprecate and don't try to open "/dev/log"

The "/dev/log" socket existed in pre-FreeBSD times. Later it was
substituted to a compatibility symlink. The symlink creation was
deprecated in FreeBSD 10.2 and 9-STABLE.

Reviewed by: markj
Differential revision: https://reviews.freebsd.org/D35304


# 88105995 22-Mar-2021 Dmitry Wagin <dmitry.wagin@ya.ru>

libc: Some enhancements to syslog(3)

This is a re-application of commit
2d82b47a5b4ef18550565dd55628d51f54d0af2e, which was reverted since it
broke with syslog daemons that don't adjust the /dev/log recv buffer
size. Now that the default is large enough to accomodate 8KB messages,
restore support for large messages.

PR: 260126


# 943c4466 30-Nov-2021 Alan Somers <asomers@FreeBSD.org>

Revert "libc: Some enhancements to syslog(3)"

This reverts commit 2886c93d1bca231260ebc01d4205743ca781f3c7.
The original commit has two problems:

* It sets SO_SNDBUF to be as large as MAXLINE. But for unix domain
sockets, the send buffer is bypassed. Packets go directly to the
peer's receive buffer, so setting and querying SO_SNDBUF is
ineffective. To ensure that the socket can accept messages of a
certain size, it would be necessary to add a SO_PEERRCVBUF socket
option that could query the connected peer's receive buffer size.

* It sets MAXLINE to 8 kB, which is larger than the default sockbuf size
of 4 kB. That's ok for the builtin syslogd, which sets its recvbuf
to 80 kB, but not ok for alternative sysloggers, like rsyslogd, which
use the default size.

As a consequence, writing messages of more than 4 kB with syslog() as a
non-root user while running rsyslogd would cause the logging application
to spin indefinitely within syslog().

PR: 260126
MFC: 2 weeks
Sponsored by: Axcient
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D33199


# 9bd73452 22-Mar-2021 Dmitry Wagin <dmitry.wagin@ya.ru>

libc: Some enhancements to syslog(3)

- Defined MAXLINE constant (8192 octets by default instead 2048) for
centralized limit setting up. It sets maximum number of characters of
the syslog message. RFC5424 doesn't limit maximum size of the message.
Named after MAXLINE in syslogd(8).
- Fixed size of fmt_cpy buffer up to MAXLINE for rendering formatted
(%m) messages.
- Introduced autoexpansion of sending socket buffer up to MAXLINE.

MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D27205


# 2933cd31 13-Aug-2020 Bryan Drewery <bdrewery@FreeBSD.org>

syslog(3): Send proper NILVALUE if gethostname(3) fails.

RFC5424 defines NILVALUE as '-'. Replace its usage with a macro and
separate out the fields to be more clear. fputs(3) is used in some
places to avoid hiding possible format string problems in a macro.

Reviewed by: cem, vangyzen (earlier version)
Sponsored by: Dell EMC


# c1920558 03-Jul-2018 John Baldwin <jhb@FreeBSD.org>

Clean up the vcs ID strings in libc's gen/ directory.

- Move CSRG IDs into __SCCSID().
- When a file has been copied, consistently use 'From: <tag>' for strings
referencing the version of the source file copied from in the license
block comment.
- Some of the 'From:' tags were using $FreeBSD$ that was being expanded on
each checkout. Fix those to hardcode the FreeBSD tag from the file that
was copied at the time of the copy.
- When multiple strings are present list them in "chronological" order,
so CSRG (__SCCSID) before FreeBSD (__FBSDID). If a file came from
OtherBSD and contains a CSRG ID from the OtherBSD file, use the order
CSRG -> OtherBSD -> FreeBSD.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D15831


# 8129693e 06-Apr-2018 Ed Schouten <ed@FreeBSD.org>

Let syslog(3) use RFC 5424.

With r332099 changing syslogd(8) to parse RFC 5424 formatted syslog
messages, go ahead and also change the syslog(3) libc function to
generate them. Compared to RFC 3164, RFC 5424 has various advantages,
such as sub-second precision for log entry timestamps.

As this change could have adverse effects when not updating syslogd(8)
or using a different system logging daemon, add a notice to UPDATING and
increase __FreeBSD_version.

Differential Revision: https://reviews.freebsd.org/D14926


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# f3990417 17-Jun-2017 Konstantin Belousov <kib@FreeBSD.org>

Do not leak syslog_mutex on cancellation.

Make syslog(3) resilent to cancellation occuring in supported deferred
mode. Code must unlock syslog_mutex on cancel, install the cleanup
handler.

Diagnosed and tested by: eugen
Discussed with: dchagin
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

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


# 52e05d9a 25-Nov-2014 Xin LI <delphij@FreeBSD.org>

Reinstitate send() after syslogd restarts.

In r228193 the test of CONNPRIV have been moved to before the _usleep
and send in vsyslog(). When syslogd restarts, this would prevent the
message being logged after the disconnect/connect dance for
scenario #1.

PR: 194751
Submitted by: Peter Creath <pjcreath+freebsd gmail com>
Reviewed By: glebius
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D1227


# 0b89df4a 20-Oct-2013 Jilles Tjoelker <jilles@FreeBSD.org>

syslog: Use SOCK_CLOEXEC instead of separate fcntl() call.


# 05eb11cb 29-Sep-2012 Jilles Tjoelker <jilles@FreeBSD.org>

libc: Use O_CLOEXEC for various internal file descriptors.

This fixes a race condition where another thread may fork() before CLOEXEC
is set, unintentionally passing the descriptor to the child process.

This commit only adds O_CLOEXEC flags to open() or openat() calls where no
fcntl(fd, F_SETFD, FD_CLOEXEC) follows. The separate fcntl() call still
leaves a race window so it should be fixed later.


# 43be4ab0 24-Jun-2012 Eitan Adler <eadler@FreeBSD.org>

Remove the assert added in r237286
The use of assertions in libraries is not widely accepted.

Requested by: bde, scottl
Approved by: cperciva
MFC after: 3 days
X-MFC-With: r237286


# bf36cf8e 20-Jun-2012 Eitan Adler <eadler@FreeBSD.org>

Don't close an uninitialized descriptor. [1]
Add a sanity check for the validity of the passed fd.

PR: kern/139080 [1]
Submitted by: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua> [1]
Reviewed by: pjd (briefly)
Approved by: cperciva
MFC after: 1 week


# 05824745 01-Dec-2011 David E. O'Brien <obrien@FreeBSD.org>

Tweak the r137233 fix to r136283 -- Code was making two send() attempts
vs. the comment documented "If we are working with a privileged socket,
then take only one attempt". Make the code match.

Furthermore, critical privileged applications that [over] log a vast amount
can look like a DoS to this code. Given it's unlikely the single reattempted
send() will succeeded, avoid usurping the scheduler in a library API for a
single non-critical facility in critical applications.

Obtained from: Juniper Networks
Discussed with: glebius


# af478295 30-Mar-2011 Sergey Kandaurov <pluknet@FreeBSD.org>

Use FD_CLOEXEC explicitly.

MFC after: 3 days


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# c879ae35 08-Jan-2007 Warner Losh <imp@FreeBSD.org>

Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.


# 5b1deb3c 07-Aug-2006 Poul-Henning Kamp <phk@FreeBSD.org>

Return length from fwopen() file callback instead of zero.

The symptom is that syslog() fails to log anything but the "ident"
string if LOG_PERROR is specified to openlog(3) and the extensible
printf is in action.

For unclear, likely quaint historical reasons, syslog uses fwopen()
on a stack buffer, rather than using the more straightforward
and faster snprintf().

Along the way, fflush(3) is called, and since the callback writer
function returns zero instead of the length "written", __SERR
naturally gets set on the filedescriptor.

The extensible printf, in difference from the normal printf refuses
to output anything to an __SERR marked filedescriptor, and thus
the actual syslog message is supressed.

MFC: after 2 weeks


# 3a31b448 11-May-2006 David Xu <davidxu@FreeBSD.org>

Save errno before calling pthread_mutex_lock because pthread_mutex_lock
may change errno unexpectly.


# ed0b0abc 02-Aug-2005 Daniel Eischen <deischen@FreeBSD.org>

Make syslog() use the internal (non-cancellation point) _usleep().
Prior to this it was calling the cancellable usleep() while holding
a lock.


# fd42c4d8 08-Apr-2005 Stefan Farfeleder <stefanf@FreeBSD.org>

Use prototypes in the function definitions.


# 96575206 30-Dec-2004 Gleb Smirnoff <glebius@FreeBSD.org>

Make syslog(3) thread safe.

PR: bin/72394
Submitted by: Dan Nelson
Reviewed by: deischen
MFC after: 2 weeks


# 8ba85e77 24-Dec-2004 Gleb Smirnoff <glebius@FreeBSD.org>

Restore standard behavior: log to console only when normal logging
failed, not always.

PR: bin/75356
Submitted by: Mark Knight <markk knigma org>
Pointy hat to: glebius
MFC after: 3 days


# 240d5a9b 04-Nov-2004 Gleb Smirnoff <glebius@FreeBSD.org>

Protect against local flooder of /var/run/log. Do not loop forever in
syslog(3) if we are a priveleged program (sshd, su, etc.).

- Make syslogd open an additional socket /var/run/logpriv, with 0600
permissions.
- In libc, try to use this socket.
- Do not loop forever if we are using this socket (partial backout of 1.31)

Reviewed by: dwmalone, Andrea Campi <andrea webcom it>
Approved by: julian (mentor)
MFC after: 1 month


# 2e89951b 08-Oct-2004 Gleb Smirnoff <glebius@FreeBSD.org>

When send()ing to syslogd return ENOBUFS keep trying until success.

This fixes a case, when DoSed syslogd completely loses messages.

PR: bin/72366
Discussed with: dwmalone, millert@OpenBSD.org
Approved by: julian (mentor)
Obtained from: OpenBSD (rev. 1.17, 1.21 by millert)
MFC after: 3 months


# 857b57ea 10-May-2004 Diomidis Spinellis <dds@FreeBSD.org>

Remove a trailing newline, to behave as documented in syslog(3):
"A trailing newline is added if none is present."

The code in syslogd, stderr, and console output always adds a newline
at the EOL. However, the existing code never actually removed a
trailing newline, and apparently relied on syslogd to convert it
into a space character. Thus, the existing newline was converted
to a trailing space at the EOL by syslogd, while stderr, and console
output resulted in an empty line.

MFC after: 2 weeks


# e6cfb1cc 10-Feb-2003 Alfred Perlstein <alfred@FreeBSD.org>

Handle %%m properly in syslog format string. Previously it would expand
the %m into the errno and then vfprintf would expand the % and the first
character of the strerror(3) return causing possible data corruption.


# bedff4e8 13-Nov-2002 Ruslan Ermilov <ru@FreeBSD.org>

Reset LogTag to NULL in closelog(3). This fixes mysterious crashes
caused by dynamic PAM modules that call openlog(3) and closelog(3),
e.g. ports/security/pam_pwdfile.

What happened here is that the module first registered its "ident"
with openlog(3), then PAM library unloaded module with dlclose(3),
and the next call to syslog(3) resulted in SIGSEGV.

MFC after: 3 days


# a82bbc73 28-May-2002 Alfred Perlstein <alfred@FreeBSD.org>

Assume __STDC__, remove non-__STDC__ code.

Submitted by: keramida


# 4cd01193 29-Mar-2002 Mark Murray <markm@FreeBSD.org>

Do not use __progname directly (except in [gs]etprogname(3)).
Also, make an internal _getprogname() that is used only inside
libc. For libc, getprogname(3) is a weak symbol in case a
function of the same name is defined in userland.


# 94998878 09-Mar-2002 David Malone <dwmalone@FreeBSD.org>

If syslog fails to talk to syslogd, then it tries to write a message
to the console in a final attempt to log something. Make this final
attempt non-blocking so that a blocking console doesn't end up
blocking process which attempt to syslog something.

In particular, this means you should be able to su and fix the
problem if the console becomes blocking.

MFC after: 3 weeks


# b231cb39 31-Jan-2002 David E. O'Brien <obrien@FreeBSD.org>

* Remove __P and convert to ANSI prototypes.
* Remove 'register'. (some functions had 7+ register functions...)
* Fix SCM ID's.


# ab09ef00 25-Jan-2002 David Malone <dwmalone@FreeBSD.org>

Use ctime_r to build the timestamp for syslog, so that we don't
clobber a ctime buffer which is passed in.

PR: 34022
Submitted by: Hartmut Brandt <brandt@fokus.gmd.de>
MFC after: 2 weeks


# d201fe46 24-Jan-2001 Daniel Eischen <deischen@FreeBSD.org>

Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions. If the threads library is linked in, the real
pthread functions will pulled in.

Use the following convention for system calls wrapped by the
threads library:
__sys_foo - actual system call
_foo - weak definition to __sys_foo
foo - weak definition to __sys_foo

Change all libc uses of system calls wrapped by the threads
library from foo to _foo. In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde). All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes. <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.

Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE. We have recursive mutexes, but would like to avoid
using them if possible.

Remove uneeded includes of <errno.h> from a few files.

Add $FreeBSD$ to a few files in order to pass commitprep.

Approved by: -arch


# 9233c4d9 27-Jan-2000 Jason Evans <jasone@FreeBSD.org>

Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),
just use _foo() <-- foo(). In the case of a libpthread that doesn't do
call conversion (such as linuxthreads and our upcoming libpthread), this
is adequate. In the case of libc_r, we still need three names, which are
now _thread_sys_foo() <-- _foo() <-- foo().

Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(),
nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo().

Remove all internal libc usage of: creat(), pause(), sleep(), system(),
tcdrain(), wait(), and waitpid().

Make thread cancellation fully POSIX-compliant.

Suggested by: deischen


# 92927338 12-Jan-2000 Jason Evans <jasone@FreeBSD.org>

Add three-tier symbol naming in support of POSIX thread cancellation
points. For library functions, the pattern is __sleep() <--
_libc_sleep() <-- sleep(). The arrows represent weak aliases. For
system calls, the pattern is _read() <-- _libc_read() <-- read().


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 8d41a9ef 01-May-1998 Brian Somers <brian@FreeBSD.org>

Go back to version 1.16 - it was correct the way it was.
Pointed out by: bde


# e79dc52b 30-Apr-1998 Brian Somers <brian@FreeBSD.org>

connect() returns -1 on error - not 0.


# 0b3b961e 05-Mar-1998 Brian Somers <brian@FreeBSD.org>

We don't need to NUL terminate our sun_path.
Pointed out by: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>


# 0d41e7b8 05-Mar-1998 Brian Somers <brian@FreeBSD.org>

Nul terminate sockaddr_un::sun_path
Suggested by: Theo de Raadt <deraadt@openbsd.org>


# d584948e 05-Mar-1998 Brian Somers <brian@FreeBSD.org>

Make SyslogAddr a sockaddr_un rather than a sockaddr.
This wasn't a problem in practice as PATH_LOG and PATH_OLDLOG
are both < sizeof sockaddr::sa_data.


# cf49f439 20-Mar-1997 John Polstra <jdp@FreeBSD.org>

Add backward compatibility so that static executables built on
modern FreeBSD systems will syslog properly on older systems that
still name the logging socket "/dev/log". This includes pre-2.2
versions of FreeBSD as well as BSD/OS systems. If the connect to
"/var/run/log" fails, the function now tries to connect to
"/dev/log" as a fallback.


# adf6ad9e 11-Mar-1997 Peter Wemm <peter@FreeBSD.org>

Merge from Lite2:
filesystem include updates, duplicate group suppression, cleanups,
filesystem whiteout support (unionfs), bidir popen().


# 662909a7 11-Mar-1997 Peter Wemm <peter@FreeBSD.org>

Import CSRG 4.4BSD-Lite2 lib/libc onto vendor branch


# 7e546392 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 51295a4d 12-Jul-1996 Jordan K. Hubbard <jkh@FreeBSD.org>

General -Wall warning cleanup, part I.
Submitted-By: Kent Vander Velden <graphix@iastate.edu>


# 7e6ace85 02-Mar-1996 Peter Wemm <peter@FreeBSD.org>

If the send() to the AF_UNIX socket to the syslogd fails, attempt to
reconnect once using the saved openlog() parameters.

This helps one of the system startup race conditions. If syslogd takes too
long to get going, some daemons can fail the connection and forever log
to the console even though the syslogd is running. That is ..unfortunate..


# 8b102407 22-Oct-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Minor cleanup, mostly unused vars and missing #includes.


# fc370289 21-Oct-1995 Peter Wemm <peter@FreeBSD.org>

Add $Id$ since this version of the file has diverged from the BSD base a
fair bit. I forgot to add it when I made the fixes some time ago.


# 11e67a9f 04-Oct-1995 Peter Wemm <peter@FreeBSD.org>

Fix the problem that I aroused with the last commit..

What was happening, is if syslogd was not running, syslog() would do
a strcat("\r\n") on a non-null-terminated buffer, and write it to the console.

This meant that sometimes extra characters could be written to the console
during boot, depending on the stack contents.

This totally avoids the potential problem by using writev() like the rest
of the does, and avoid modifying the buffer after the trouble we've gone to
to carefully protect it.

This is actually a trivial fix, in spite of the long commit message.. :-)
It only appeared during boot and shutdown with syslogd stopped.


# 7c8e2aa4 15-Sep-1995 Peter Wemm <peter@FreeBSD.org>

Fix security bugs with a "new approach", using stdio's powerful buffer
control hooks.
It is similar to an unrolled multi-part snprintf(), in that a "FILE *" is
attached to a string buffer. There is also an optimisation for the case
where the syslog format string does not contain %m, which should improve
performance of "informational" logging, like from ftpd.


# 85b3ab58 29-Aug-1995 Andrey A. Chernov <ache@FreeBSD.org>

National date/time representation in syslog logfiles looks ugly,
change strftime to ctime. Logfiles must have default (english) date/time
representation for access/view from various places.


# ff17906b 02-May-1995 Andrey A. Chernov <ache@FreeBSD.org>

Fix bracket error for LogMask
Submitted by: Ruslan Belkin <rus@home2.UA.net>


# 58f0484f 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Lib Sources