History log of /freebsd-head/usr.sbin/newsyslog/newsyslog.c
Revision Date Author Comments
5a174e46329c2f9969e68650631da418edd481b7 22-Feb-2019 dab <dab@FreeBSD.org> Fix several Coverity-detected issues in newsyslog.

- CID 1394815, CID 1305673: Dereference before null check - memory was
allocated and the allocation checked for NULL with a call to errx()
if it failed. Code below that was guaranteed that the pointer was
non-NULL, but there was another check for NULL at the exit of the
function (after the memory had already been referenced). Eliminate
the useless NULL check.

- CID 1007452: Resource leak - Storage intended to be allocated and
returned to the caller was never freed. This was the result of a
regression in the function signature introduced in r208648 (2010)
(thanks for that find, @cem!). Fixed by altering the function
signature and passing the allocated memory to the caller as
intended. This also fixes PR158794.

- CID 1008620: Logically dead code in newsyslog.c - This was a direct
result of CID 1007452. Since the memory allocated as described there
was not returned to the caller, a subsequent check for the memory
having been allocated was dead code. Returning the memory
re-animates the code that is the subject of this CID.

- CID 1006131: Unused value - in parsing a configuration file, a
pointer to the end of the last field was saved, but not used after
that. Rewrite to use the pointer value. This could have been fixed
by avoiding the assignment altogether, but this solutions more
closely follows the pattern used in the preceding code.

PR: 158794
Reported by: Coverity, Ken-ichi EZURA <k.ezura@gmail.com> (PR158794)
Reviewed by: cem, markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D19105
b9af2aaaa30720e40246db8b0ab3d9996688e9d6 22-Feb-2019 dab <dab@FreeBSD.org> Revert r344389 & r343906 - Fix Coverity errors in newsyslog

It was pointed out that a couple of the "memory leak" CIDs that I
fixed were arguably Coverity errors rather than errors in the
newsyslog code and the cure was worse than the disease. Revert both
changes. The first change, which included fixes for other Coverity
errors, will be re-worked to omit the troublesome changes and then
re-committed with the remaining fixes.

Reported by: bde
Sponsored by: Dell EMC Isilon
229dccf1255f78f9063ad193b32163afacfdf6cb 20-Feb-2019 dab <dab@FreeBSD.org> Complete fix for CID 1007454, CID 1007453: Resource leak in newsyslog

The result of a strdup() was stored in a global variable and not freed
before program exit. This is a follow-up to r343906. That change
attempted to plug these resource leaks but managed to miss a code path
on which the leak still occurs. Plug the leak on that path, too.

MFC after: 3 days
Sponsored by: Dell EMC Isilon
a78d5046266fa69d9e75784a0409c33a3c2aa29c 08-Feb-2019 dab <dab@FreeBSD.org> Fix several Coverity-detected issues in newsyslog.

- CID 1394815, CID 1305673: Dereference before null check - memory was
allocated and the allocation checked for NULL with a call to errx()
if it failed. Code below that was guaranteed that the pointer was
non-NULL, but there was another check for NULL at the exit of the
function (after the memory had already been referenced). Eliminate
the useless NULL check.

- CID 1007454, CID 1007453: Resource leak - The result of a strdup()
was stored in a global variable and not freed before program exit.

- CID 1007452: Resource leak - Storage intended to be allocated and
returned to the caller was never freed. This was the result of a
regression in the function signature introduced in r208648 (2010)
(thanks for that find, @cem!). Fixed by altering the function
signature and passing the allocated memory to the caller as
intended. This also fixes PR158794.

- CID 1008620: Logically dead code in newsyslog.c - This was a direct
result of CID 1007452. Since the memory allocated as described there
was not returned to the caller, a subsequent check for the memory
having been allocated was dead code. Returning the memory
re-animates the code that is the subject of this CID.

- CID 1006131: Unused value - in parsing a configuration file, a
pointer to the end of the last field was saved, but not used after
that. Rewrite to use the pointer value. This could have been fixed
by avoiding the assignment altogether, but this solutions more
closely follows the pattern used in the preceding code.

PR: 158794
Reported by: Coverity, Ken-ichi EZURA <k.ezura@gmail.com> (PR158794)
Reviewed by: cem, markj
MFC after: 1 week
Sponsored by: Dell EMC Isilon
5a406f9a507ca6e0694fb2890e2216bc3967dd08 29-Nov-2018 markj <markj@FreeBSD.org> Fix age_old_log() after r337468.

We can no longer use sizeof() to get the path buffer's size. Apply
a straightforward fix for now with the aim of MFCing soon.

PR: 233633
Submitted by: Katsuyuki Miyoshi <katsu@miyoshi.matsuyama.ehime.jp>
MFC after: 3 days
b35b6ea1322568b5b4ba0ef08c93caeffff580e4 21-Aug-2018 cem <cem@FreeBSD.org> newsyslog(8): Reject configurations that specify setuid or executable logs

Prevent some classes of foot-shooting that may result in permissions
problems.

Reviewed by: dab, delphij, vangyzen (earlier version)
Relnotes: yes (behavior change)
Sponsored by: Dell EMC Isilon
Differential Revision: D16831
f21f9cc77ce76ec0f662ade5ae17d82bddfc27fd 08-Aug-2018 markj <markj@FreeBSD.org> Simplify compression code.

- Remove the compression suffix macros and move them directly into the
compress_type array.
- Remove the hardcoded sizes on the suffix and compression args arrays.
- Simplify the compression args arrays at the expense of a __DECONST
when calling execv().
- Rewrite do_zipwork. The COMPRESS_* macros can directly index the
compress_types array, so the outer loop is not needed. Convert
fixed-length strings into asprintf or sbuf calls.

Submitted by: Dan Nelson <dnelson_1901@yahoo.com>
Reviewed by: gad
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16518
a86549a7332b291420cda1b007aa29b781590339 04-Aug-2018 markj <markj@FreeBSD.org> Fix a flag collision introduced in r327451.

PR: 230350
MFC after: 3 days
2e6b904ec58369f0f70a064b47fb05cfbbf5beb1 01-Aug-2018 markj <markj@FreeBSD.org> Remove ARGS_NUM, accidentally left over after r337050.
59ae15e1bd1c1c22fbe1286bc12614713840e434 01-Aug-2018 markj <markj@FreeBSD.org> Don't hard-code the number of compression utility arguments.

The zstd invocation constructed by newsyslog contains one more parameter
than invocations for the other supported compression utilities. However,
the maximum number of arguments was hard-coded, leading to an
out-of-bounds array access when using zstd compression.
c562453022669453a7f0d56c2ff004d97e502310 30-Jul-2018 bapt <bapt@FreeBSD.org> newsyslog: fix compression arglist construction

Reuse of the index variable in two nested loops resulted in only the first
argument in the list being used (fine for gzip, not fine for zstd). Also
add tests for xz and zstd, and fix the COMPRESS_SUFFIX_MAXLEN macro.

Submitted by: dnelson_1901_yahoo.com
Differential Revision: https://reviews.freebsd.org/D16509
0bb8232d504bfa71acf71cd3d8f615ff99b3fbe4 08-Jul-2018 ed <ed@FreeBSD.org> Use the FQDN in the newsyslog log message when RFC 5424 is enabled.

The RFC 5424 spec mentions that logging FQDNs over short hostnames is
preferred. Alter this code, so that the hostname doesn't get truncated
on startup. Keep track of the length of the short hostname, so that
fprintf() can do the truncation where necessary.

MFC after: 1 month
a910215b9bf4c347fec72d5a800f2d3051fa771d 31-Dec-2017 eadler <eadler@FreeBSD.org> newsyslog: implement 'p' flag

Implement the 'p' flag for newsyslog from NetBSD. This flag results in
the first log file for a given file to not be compressed.

While here, don't change file attributes during a no-op run

PR: 162798
Submitted by: heas@shrubbery.net
MFC After: 1 month
83ea734edb7b620f36bfdca3f656db9353b4e824 18-Dec-2017 bapt <bapt@FreeBSD.org> newsyslog: Fix issues after r326616

When building the command to execute for compression, newsyslog was modifying
the generic arguments array instead of its own copy.
Meaning on the second file to compress with the same arguments, the command line
was not the one expected.
Fix it by creating one copy of the arguments per execution and modifying that
copy.

While here, print the command line executed in verbose mode.

Reported by: many
b9ad6236040ba916d3c61347db48f312d681f77b 06-Dec-2017 bapt <bapt@FreeBSD.org> Really fix typo and improve wording of the comment
eb7252a3e9a975d6c4164a83e31b419763411cc2 06-Dec-2017 bapt <bapt@FreeBSD.org> Fix typo

Reported by: danfe
19f5c9ddd5636a49b0bd38f2f17c27f27e13d851 06-Dec-2017 bapt <bapt@FreeBSD.org> Allow newsyslog to execute compression commands which
have a semantic different than the traditional gzip(1)

This is done to allow to use zstd(1) as a compression tool without
having to patch it to change its default behavior.
09536a56e6baa14a0a48b326a37a10ac2b0917aa 26-May-2017 dab <dab@FreeBSD.org> Add newsyslog capability to write RFC5424 compliant rotation message.

This modification adds the capability to newsyslog to write the
rotation message in a format that is compliant with RFC5424. This
capability is enabled on a per-log file basis through a new value
("T") in the flags field in newsyslog.conf. This is useful on systems
that use the RFC5424 format for log files so that the rotation message
format matches that of the other log messages. There has been recent
mention of adding an RFC5424 compliant mode to syslogd and at least
one alternative system log daemon (rsyslogd) that already has the
capability to use that format.

Reviewed by: vangyzen, ngie
Approved by: vangyzen (mentor)
MFC after: 2 months
Relnotes: yes
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D10253
7453e3e0ef159d1eea9f12c54d0e9f5ace767e1a 15-Apr-2017 bapt <bapt@FreeBSD.org> Add a new Y flag to newsyslog.conf

This makes newsyslog use zstandard to compress log files.

Given Z is already taken for gzip and zstandard compression level stands in
between gzip and xz (which has the X flag) chosing Y sounds ok :)
30f99dbeefc844112679b1d34c674426abfb24c8 08-Nov-2016 bdrewery <bdrewery@FreeBSD.org> Fix improper use of "its".

Sponsored by: Dell EMC Isilon
d9c54409f04742bf0a4546b681e99aea66a18f6e 09-Sep-2016 ed <ed@FreeBSD.org> Properly patch up dirname()/basename() calls to not clobber ent->log.

It turns out that we had a couple of more calls to dirname()/basename()
in newsyslog(8) that assume the input isn't clobbered. This is bad,
because it apparently breaks log rotation now that the new dirname()
implementation has been merged.

Fix this by first copying the input and then calling
dirname()/basename(). While there, improve the naming of variables in
this function a bit.

Reported by: Ryan Steinmetz, gjb
Reviewed by: bdrewery, allanjude
Differential Revision: https://reviews.freebsd.org/D7838
90506dd628d30d984d6533918328911cb2b387b3 28-Jul-2016 ed <ed@FreeBSD.org> Clean up use of basename() and dirname().

Pull copies of the input pathname string before calling basename() and
dirname() to make this comply to POSIX. Free these copies at the end of
this function. While there, remove the duplication of the 's' ->
'logfname' string. There is no need for this.
9c6df47b0b5a693febb34753474f22cbc8e6cdc4 15-Jun-2016 vangyzen <vangyzen@FreeBSD.org> MFC r301532

newsyslog: Eliminate unnecessary sleep(10) when -R and -s are specified

After going through the signal work list, during which do_sigwork()
is called and essentially does nothing because -s and -R were
specified on the command line, newsyslog will sleep for 10 seconds
as the (verbose) code says: "Pause 10 seconds to allow daemon(s)
to close log file(s)".

However, the man page verbiage for -R (and -s) seems quite clear
that this sleep() is unnecessary because the daemon was expected
to have already closed the log file before calling newsyslog.

PR: 210020
Submitted by: David A. Bright <david_a_bright@dell.com>
Sponsored by: Dell Inc.
87e8d06bb3496ce8cee485108c02ddfba7c046c5 06-Jun-2016 vangyzen <vangyzen@FreeBSD.org> newsyslog: Eliminate unnecessary sleep(10) when -R and -s are specified

After going through the signal work list, during which do_sigwork()
is called and essentially does nothing because -s and -R were
specified on the command line, newsyslog will sleep for 10 seconds
as the (verbose) code says: "Pause 10 seconds to allow daemon(s)
to close log file(s)".

However, the man page verbiage for -R (and -s) seems quite clear
that this sleep() is unnecessary because the daemon was expected
to have already closed the log file before calling newsyslog.

PR: 210020
Submitted by: David A. Bright <david_a_bright@dell.com>
MFC after: 1 week
Sponsored by: Dell Inc.
Differential Revision: https://reviews.freebsd.org/D6727
00d578928eca75be320b36d37543a7e2a4f9fbdb 27-May-2016 grehan <grehan@FreeBSD.org> Create branch for bhyve graphics import.
dc83b58bbee523b7400472f573a44887cbd0642a 07-Jan-2016 bdrewery <bdrewery@FreeBSD.org> MFC r289677:

Fix a ton of speelling errors
cab8578a147d77880fe77357266fc36b42e943e3 31-Oct-2015 bapt <bapt@FreeBSD.org> newsyslog: treat 'c' flag in the config as 'C'

When -C was introduced in r114137 the plan was to have -C and -c being used for
"create" due to a typo in FreeBSD <= 4.8 a temporary compatibility hack has been
added to make -c being like -G aka GLOB and a warning was issued for the user to
be aware of the futur change for -c.

12 years later it is more than time to remove that hack and finish the what was
intent in r114137

Submitted by: Alexandre Perrin <alex@kaworu.ch>
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4000
7c18e94a5c2e23df12dac914a4c112c7ed4c61a7 31-Oct-2015 bapt <bapt@FreeBSD.org> MFC: 289879

newsyslog.conf: allow to configure the signal using the signal name.

Submitted by: Alexandre Perrin <alex@kaworu.ch>
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D3961
a0408328fb41458bd3321f1c45dfca1514da512e 24-Oct-2015 bapt <bapt@FreeBSD.org> newsyslog.conf: allow to configure the signal using the signal name.

Submitted by: Alexandre Perrin <alex@kaworu.ch>
MFC after: 1 week
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D3961
21a3003f8f5c49c0acbcb49462e5b221076076d0 21-Oct-2015 eadler <eadler@FreeBSD.org> Fix a ton of speelling errors

arc lint is helpful

Reviewed By: allanjude, wblock, #manpages, chris@bsdjunk.com
Differential Revision: https://reviews.freebsd.org/D3337
8a1641d7862ee12fd3dd4c98e7057eacc0bfbdb6 23-Oct-2014 markj <markj@FreeBSD.org> MFC r272763:
If we fail to send a signal after rotation, print the pidfile from which
the corresponding PID was obtained.

PR: 194143
ae5107476ab582f60b16e243c2a8dd2fa4e985bc 08-Oct-2014 markj <markj@FreeBSD.org> If we fail to send a signal after rotation, print the pidfile from which
the corresponding PID was obtained.

PR: 194143
Submitted by: Lyndon Nerenberg <lyndon@orthanc.ca>
MFC after: 1 week
eb1a5f8de9f7ea602c373a710f531abbf81141c4 21-Feb-2014 gjb <gjb@FreeBSD.org> Move ^/user/gjb/hacking/release-embedded up one directory, and remove
^/user/gjb/hacking since this is likely to be merged to head/ soon.

Sponsored by: The FreeBSD Foundation
92000681d74b0aa6a7484fbba39edf34a2ec6a96 17-Feb-2014 bdrewery <bdrewery@FreeBSD.org> MFC r261401:

Fix newsyslog(8) to use the size of the file instead of the blocks it
takes on disk, as advertised in newsyslog.conf(5).

Approved by: bapt (mentor, implicit)
2a0c06b06734af87b60753f6646870c393aeb126 13-Feb-2014 markj <markj@FreeBSD.org> MFC r257600:
Initialize the struct tm before handing it to strptime(3).
ed4da825525de3a4b12e335efccbd2d92474fb19 02-Feb-2014 bdrewery <bdrewery@FreeBSD.org> Fix newsyslog(8) to use the size of the file instead of the blocks it
takes on disk, as advertised in newsyslog.conf(5).

This fixes newsyslog(8) on ZFS with compression enabled to not have
large files compared to the expected rotation size.

# grep remotes/messages /etc/newsyslog.conf
/var/log/remote/messages root:info 640 5 500 * JC
# ls -alh /var/log/remote/messages
-rw-r----- 1 root info 3.2M Jan 31 20:02 /var/log/remote/messages
# newsyslog -vN|grep remote/messages
/var/log/remote/messages <5J>: size (Kb): 464 [500] --> skipping
# stat -f "st_size: %z st_blocks: %b" /var/log/remote/messages
st_size: 3372627 st_blocks: 928
# zfs get -H compressratio zroot/syslogs
zroot/syslogs compressratio 3.77x -

With fix:

# newsyslog -v | grep remote/messages
/var/log/remote/messages <5J>: size (Kb): 3338 [500] --> trimming log....

Approved by: bapt (mentor)
PR: docs/150877
Reported by: Joshua Isom <jrisom@gmail.com>
MFC after: 2 weeks
6b01bbf146ab195243a8e7d43bb11f8835c76af8 27-Dec-2013 gjb <gjb@FreeBSD.org> Copy head@r259933 -> user/gjb/hacking/release-embedded for initial
inclusion of (at least) arm builds with the release.

Sponsored by: The FreeBSD Foundation
cce38458350be2a85af7d032ebf800cc009a9ab8 04-Nov-2013 markj <markj@FreeBSD.org> Initialize the struct tm before handing it to strptime(3).

PR: 183550
MFC after: 2 weeks
d8a47ede296b27f8740c6467ebda9d12636b93d1 29-Jun-2013 kientzle <kientzle@FreeBSD.org> Fix -Wunsequenced

Submitted by: dt71@gmx.com
44ec97062dafc83b639c425da20387c8c7fb2d8b 02-Jun-2013 markj <markj@FreeBSD.org> We want to stat the archived log file rather than the logfile itself.

PR: bin/179122
Submitted by: Oliver Fromme <olli@secnetix.de>
MFC after: 3 days
dbafd2120ecdd8ad26f05193bfb3f6604453df7d 12-May-2013 markj <markj@FreeBSD.org> Some filesystems (NFS in particular) do not fill out the d_type field when
returning directory entries through readdir(3). In this case we need to
obtain the file type ourselves; otherwise newsyslog -t will not be able to
find archived log files and will fail to both delete old log files and to
do interval-based rotations properly.

Reported by: jilles
Reviewed by: jilles
MFC after: 2 weeks
3110b3975c872ef7583196d2e4f1574de133c826 26-Mar-2013 markj <markj@FreeBSD.org> Fix interval-based rotations when the -t flag is used. In this case, find
the most-recently archived logfile and use its mtime to determine whether
or not to rotate, as in the non-timestamped case.

Previously we would just try to use the mtime of <logfile>.0, which always
results in a rotation since it generally doesn't exist in the -t case.

PR: bin/166448
Approved by: emaste (co-mentor)
Tested by: Marco Steinbach <coco executive-computing.de>
MFC after: 2 weeks
d68a3343d31b1149ae1176d0f0b5f8c92408461a 27-Jan-2013 markj <markj@FreeBSD.org> Rename the run_cmd field to sw_runcmd to make it consistent with the
other fields in struct sigwork_entry.

Approved by: rstone (co-mentor)
MFC after: 1 week
6491a8b5991985e7ef0979e248b1f54555b5e997 27-Jan-2013 markj <markj@FreeBSD.org> Ensure that newsyslog -n prints the correct message for a rotation rule
that uses the 'R' flag.

Reviewed by: gad
Approved by: rstone (co-mentor)
MFC after: 1 week
eb5455fa48e6e07315efde38fa7c532224892515 27-Jan-2013 markj <markj@FreeBSD.org> When the 'R' flag is used with a newsyslog.conf entry, some fields of
the corresponding struct sigwork_entry were left uninitialized,
potentially causing an early return from do_sigwork(). Ensure that these
fields are initialized, and handle the 'R' flag properly in
do_sigwork().

PR: bin/175330
Reviewed by: gad
Approved by: rstone (co-mentor)
MFC after: 1 week
fe63c3a52ae03ef9724b8d4af06597b8a77e7064 03-Jan-2013 markj <markj@FreeBSD.org> Make sure to update the mtime of a logfile after archiving it. This
ensures that the next rotation happens at the correct time when using
interval-based rotations.

PR: bin/174438
Reviewed by: gad
Approved by: rstone (co-mentor)
MFC after: 1 week
e8588e6c07393ac104cb6bf5e726e1dea408f9aa 03-Jan-2013 markj <markj@FreeBSD.org> Have -n imply -r, since dry-run mode obviously doesn't require root
privileges.

Approved by: rstone (co-mentor)
MFC after: 1 week
f951ee4fbb0a0c110c0f3777dfc6c3e118bdc37b 03-Jan-2013 markj <markj@FreeBSD.org> Fix a typo in an error message.

Approved by: rstone (co-mentor)
MFC after: 1 week
c23d2a42d74060bd07f9ee272b392868da7abea2 20-Oct-2012 ed <ed@FreeBSD.org> More -Wmissing-variable-declarations fixes.

In addition to adding missing `static' keywords:
- bin/dd: Pull in `extern.h' to guarantee consistency with source file.
- libexec/rpc.rusersd: Move shared globals into an extern.h.
- libexec/talkd: Move `debug' and `hostname' into extern.h.
- usr.bin/cksum: Put counters in extern.h, as they are used by ckdist/mtree.
- usr.bin/m4: Move `end_result' into extern.h.
- usr.sbin/services_mkdb: Move shared globals into an extern.h.
b3b0c82b64def2fad4b38ca0d29dea22fd3421c4 09-Jul-2012 ae <ae@FreeBSD.org> We don't need to check the result of sending signal when -R option is
specified.

Submitted by: Ilya A. Arkhipov
MFC after: 1 week
53af2dbdcaab2b0af0595c7972b876b8ef9e9ae6 19-May-2012 gleb <gleb@FreeBSD.org> Hide DIR definition by making it an opaque struct typedef.

Introduce dirfd() libc exported symbol replacing macro with same name,
preserve _dirfd() macro for internal use.

Replace dirp->dd_fd with dirfd() call. Avoid using dirfd as variable
name to prevent shadowing global symbol.

Sponsored by: Google Summer Of Code 2011
14f4e1dc58ba19c127f80a6cbbac9e1e23e552e2 21-Mar-2012 glebius <glebius@FreeBSD.org> Don't run through time checks when entry is definitely oversized. This
leads to newsyslog rotating on (size OR time) if both are specified.

PR: 100018, 160432
b5c7b0dfe9b8e88376b3dc765231155b450c8e0e 05-Jan-2012 uqs <uqs@FreeBSD.org> Further fix a typo and spelling classic correctly in function names,
too.

Submitted by: Ben Kaduk <minimarmot@gmail.com>
e7e5b53bf16ab3b35646f0580b36fa7d7afa9678 03-Jan-2012 ed <ed@FreeBSD.org> Replace index() and rindex() calls with strchr() and strrchr().

The index() and rindex() functions were marked LEGACY in the 2001
revision of POSIX and were subsequently removed from the 2008 revision.
The strchr() and strrchr() functions are part of the C standard.

This makes the source code a lot more consistent, as most of these C
files also call into other str*() routines. In fact, about a dozen
already perform strchr() calls.
415a3a9b966c1522657d435a1785904f41accc78 30-Dec-2011 uqs <uqs@FreeBSD.org> Spelling fixes for usr.sbin/
3c01e31040c2984c114ac9977789b76185e726e6 21-Dec-2011 eadler <eadler@FreeBSD.org> - Remove extraneous null ptr deref checks
- Fix memory leak

Submitted by: Slono Slono <slonoman2011@yandex.ru>
Approved by: jhb
MFC after: 1 week
1bbc0ba66b71452ff4076c6945e569556fba45ab 14-May-2011 sobomax <sobomax@FreeBSD.org> Add new modifier - "R", when it is specified the path to pid file
will be considered as a path to a binary or a shell script to be executed
after rotation has been completed instead of sending signal to the process
id in that file.

Sponsored by: Sippy Software, Inc.
From the: FreeBSD hacking lounge at BSDCan
5a46569c8d5ce5e53e7a60289af3986857568c7f 21-Apr-2011 simon <simon@FreeBSD.org> Fix an old bug in newsyslog where we kept one log file more than was
requested in newsyslog.conf. This was only the case using the non-time
based filenames (.0, .1, .2 etc.).

The change also makes newsyslog clean clean up the old extra logfile so
users don't end up with a single stale logfile which won't be rotated
out.

This change also cleans up some code a bit to avoid more copy / paste
code and removes some old copy / paste code in the process.

PR: bin/76697
MFC after: 2 weeks
23b678467d3c13550b83748f55274f9b067b2e94 09-Mar-2011 ru <ru@FreeBSD.org> Sync manpage's SYNOPSIS with program's usage.
271f830ef22b26ec4140984b2b25025abd7ec30d 22-Feb-2011 sobomax <sobomax@FreeBSD.org> Make code more friendly to the non-C99 compilers - don't allocate
local variables in the `for' loop declaration. This allows trunk
newsyslog.c to be compiled on 7.x. This change should be no-op from
the functional POV.
0d3cc98e60a50dc1cbc84d2580769245c7c7ae6e 31-Jan-2011 mm <mm@FreeBSD.org> Add xz(1) support to newsyslog.
Rewrite and simplify logfile compression code.

Approved by: gad
MFC after: 3 weeks
c9b13950ebc880ab4836c78d38d7d19bec506d79 31-Dec-2010 brian <brian@FreeBSD.org> Make -S functional.

MFC after: 1 week
63a10f10ab5a74e40ad28c3f8de32e75b390c48f 21-Nov-2010 simon <simon@FreeBSD.org> Fix a typo in a comment.

MFC after: 3 days
09f9c897d33c41618ada06fbbcf1a9b3812dee53 19-Oct-2010 jamie <jamie@FreeBSD.org> A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.
c77452c8de7227230017ce6d96aa4e7c069c7b0f 23-Jul-2010 brian <brian@FreeBSD.org> Add a -S switch to override the default syslog pid file. This can be useful
if syslogd's -P switch or a syslogd alternative is being used.

MFC after: 3 weeks
1af623ef424b8231643c3777ef9d2da8bfd0ca0a 22-Jul-2010 simon <simon@FreeBSD.org> Add support for creating the archived log filenames using a time-stamp
instead of the traditional simple counter.

Using the time-stamp based file-names, once a log file is archived, it
will not change name until it is deleted. This means that many backup
systems will only perform one backup of the archived log file, instead
for performing a new backup of the logfile upon each logfile rotation.

This implementation is separate from the patches in the mentioned PR,
as I wasn't aware of the existence of the PR until after I had
implemented the same functionality as the patches in the PR provide.
Unlike the PR, this new code does honor the 'log count' in
newsyslog.conf so old logfiles are deleted. This new code does not
currently support never deleting the archived logfiles.

PR: bin/29363
MFC after: 3 weeks
4fcdf7caa6f2ed8e431b4fbd876afa5df3db6669 29-May-2010 gordon <gordon@FreeBSD.org> Add file include processing for newsyslog.

Format for the include line in /etc/newsyslog.conf is:
<include> /etc/defaults/newsyslog.conf

Other notes of interest:
Globbing is supported in <include> statements.
Properly detect circular include loop dependencies.

Reviewed by: gad@
Approved by: wes@ (mentor)
MFC after: 2 months
5224579be48d87a661720ded4bf970a3c4490ba9 29-May-2010 gordon <gordon@FreeBSD.org> Convert newsyslog to using queue(3) macros instead of a home rolled version.

Reviewed by: gad@
Approved by: wes@ (mentor)
MFC after: 2 months
f1216d1f0ade038907195fc114b7e630623b402c 19-Mar-2010 delphij <delphij@FreeBSD.org> Create a custom branch where I will be able to do the merge.
4a32e61c7194d6066d53ab2352ca5967efc78173 03-Feb-2010 delphij <delphij@FreeBSD.org> MFC r202668+r200806:

Don't consider non-existence of a PID file an error, we should be able
to proceed anyway as this most likely mean that the process has been
terminated. [1]

Add a new option, -P, which reverts newsyslog(8) to the old behavior,
which stops to proceed further, as it is possible that processes which
fails to create PID file get screwed by rotation. [2]

PR: bin/140397
Submitted by: Dan Lukes [1]
Requested by: stas [2]
bf268284cce6c4d1d3fbd8d52be2340ef8d83629 20-Jan-2010 delphij <delphij@FreeBSD.org> Add a new option, -P, which reverts newsyslog(8) to the old behavior,
which stops to proceed further, as it is possible that processes which
fails to create PID file get screwed by rotation.

Requested by: stas
MFC after: 2 weeks
X-MFC with: r200806
5fbacdf9a7b061873353d677a41c07409b749c7e 21-Dec-2009 delphij <delphij@FreeBSD.org> Don't consider non-existence of a PID file an error, we should be able
to proceed anyway as this most likely mean that the process has been
terminated.

PR: bin/140397
Submitted by: Dan Lukes <dan obluda cz>
MFC after: 1 month
19b6af98ec71398e77874582eb84ec5310c7156f 22-Nov-2008 dfr <dfr@FreeBSD.org> Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
performance in Xen's HVM mode.
cf5320822f93810742e3d4a1ac8202db8482e633 19-Oct-2008 lulf <lulf@FreeBSD.org> - Import the HEAD csup code which is the basis for the cvsmode work.
a90c69e689d0e226eb954ea9ad90d51c950c919f 08-Mar-2008 delphij <delphij@FreeBSD.org> MFC revision 1.108
date: 2008/01/30 22:11:59; author: delphij; state: Exp; lines: +2 -2
Fix two typos.
bec3e9f048f38d20d682f01deddc24b32ece74d6 08-Mar-2008 delphij <delphij@FreeBSD.org> MFC revision 1.108
date: 2008/01/30 22:11:59; author: delphij; state: Exp; lines: +2 -2
Fix two typos.
bf18e9a1d927e9bce1322e310e5d7c5a5df8768f 30-Jan-2008 delphij <delphij@FreeBSD.org> Fix two typos.
e0f5f00d16681f26cedce15ea5b8b834a788eea4 17-Aug-2006 delphij <delphij@FreeBSD.org> Use same signedness for i and matched_c. This should make
newsyslog(8) WARNS=6 clean.
3cd908da509c3d1443c7899abefbfd2aa2d32cba 17-Aug-2006 sobomax <sobomax@FreeBSD.org> MFC:
Remove mention of the `W' flag, which has been turned to no-op by the
neworder change. Keep the option in a config file parser, to not
violate POLA.
5b5ff3e4d5b58bc058e39da44b6a16192ca87071 24-Jul-2006 gad <gad@FreeBSD.org> MFC 1.104->1.105: Remove the "oldorder" processing, and replace
three strncpy's with strlcpy's.
9d70629cbaaea9865d9f6ec1bac456ba1a85d373 21-Jul-2006 sobomax <sobomax@FreeBSD.org> Remove mention of the `W' flag, which has been turned to no-op by the
neworder change. Keep the option in a config file parser, to not
violate POLA.

MFC after: 2 weeks
d2142779331d06b574cd72888ca940d8d5de1b9a 27-Jun-2006 gad <gad@FreeBSD.org> Remove the last three calls to strncpy(), two of which would have
been bugs if the source had ever been too big for the destination.

MFC after: 3 weeks
0163469d207d7f1029f08fad9c1daf2974b78e23 27-Jun-2006 gad <gad@FreeBSD.org> Remove the "oldorder" processing. The "neworder" processing has
been the default for two years now, without any problems reported.

MFC after: 3 weeks
751980ab6f1ece30dcb873b7f653ec5ea16fcc3c 25-Jan-2006 gad <gad@FreeBSD.org> MFC 1.103: Improve the handling of errors that might happen with the fork()
done to compress files after they have been rotated.
5f9b2961c344fae5d18e1938377ac1cd2fef24a5 20-Jan-2006 gad <gad@FreeBSD.org> Improve error-handling related to the fork() done to compress files after
they have been rotated. Among other things, use warnx() instead of warn()
for some messages where the value if errno is irrelevant to the problem
being reported.

MFC after: 5 days
52480b0ed09048256e9de891d34d304b7c1db16b 29-Dec-2005 sobomax <sobomax@FreeBSD.org> MFC: fix logic error which causes <null> to be printed instead of the
actual file name in error message.
c404290d4297e01b104f13fc03d7844429b34e85 01-Dec-2005 sobomax <sobomax@FreeBSD.org> Fix logic error which causes <null> to be printed instead of the
actual file name in error message.

MFC After: 2 weeks
9b003d6928c7213b295225a61c5e7ae6bdb2d04d 03-Mar-2005 brooks <brooks@FreeBSD.org> Add the -N option to not rotate any files. This is to be used in
cojunction with -C and is used by /etc/rc.d/newsyslog.

I forgot that this was in my perforce tree and not my running system and
thus committed a non-working newsyslog script.

Reported by: des
Pointy hat: brooks
985415fefc94c4c0cdd2234db820330801ecde00 04-Jan-2005 delphij <delphij@FreeBSD.org> Because the `permission' field in conf_entry is intended to be used as
parameter 2 in chmod(2), which is a mode_t (and in turn a __uint_16_t),
it's more likely that it should be defined as an unsigned variable.

This commit should make newsyslog WARNS=6 clean, but don't bump the knob
until I have a universe build.

MFC After: 1 month
0f55bc1d4550e3abc0817c1b963dd66bebcbb74f 06-Oct-2004 brooks <brooks@FreeBSD.org> Mention "-d directory" in usage().

Pointy hat to: brooks
626003d7272828ee3551b129c2815f2acff54be3 05-Oct-2004 brooks <brooks@FreeBSD.org> Don't prepend the directory specified by -d when the file is a relative
path. Doing so makes no sense. I'm not sure allowing relative paths
makes sense either, but I'm not going to break that now.
a8b1fd9efbf31e6a704f5f931cf33e9a689d5aac 04-Oct-2004 brooks <brooks@FreeBSD.org> Add a new -d argument which is used to specify an alternate root for log
files similar to DESTDIR in the BSD make process. This only affects log
file paths not config file (-f) or archive directory (-a) paths.
bee9cba70cb678cdd927bc761766011085e3d20c 04-Jul-2004 sobomax <sobomax@FreeBSD.org> Nothing says that /var/log can't be not a directory but a symbolic link
to a directory. Therefore, use stat(2) instead of lstat(2) to check if
/var/log exists.

MFC after: 7 days
5c21bd33720a99e6cf3c62eec27d5d2dc648a7e3 20-Jun-2004 gad <gad@FreeBSD.org> Fix the format-string in a call to err(). It was causing a warning if
compiled on 4.x-stable.
04ef458020d3773ca90efb24e46cf8750413f049 19-Jun-2004 gad <gad@FreeBSD.org> Fix the check for a "duplicate filename to compress", so that we're checking
the *filename* and not the pid_file(!). Stupid brain-fault on my part.
This could cause a segfault under -neworder if newsyslog had to rotate
multiple files, and later ones had specifed the 'N' flag.

Bug first reported by: le
MFC after: 3 days
a1214ecb7b3a5536b459a68adb96489226a904ad 12-Jun-2004 gad <gad@FreeBSD.org> Switch to using the "neworder" for rotating log files, by default. The
main advantage of this is that daemon's are only signalled once per run,
instead of once for each file that is rotated.

MFC after: 2 weeks
217bb961dbcafb033404a3a249ee50691ff5bd88 07-Jun-2004 gad <gad@FreeBSD.org> Add an "oldorder" option, so that when the default changes to "neworder",
people have a way to drop back to the previous logic.

MFC after: 13 days
717539c68068661ebd0d828db4a5585753bcba9f 07-Jun-2004 gad <gad@FreeBSD.org> In "neworder" processing, reduce the delay between signals to separate
processes, and balance that by adding a 10-second delay after all the
processes have been signaled. Also improvement a few messages printed
with `-n' or `-v' processing (mostly signal-related messages).

MFC after: 13 days
f0a68c5d24ee761f311d908d1356100bcd990d91 07-Jun-2004 gad <gad@FreeBSD.org> Major re-ordering of the steps that newsyslog will use when processing
files to rotate. The new order will first rotate all files that need
to be rotated, and then send a single signal to each process which
needs to be signaled, and finally it will compress all the files which
were rotated.

This means daemons will be signaled once per run of newsyslog, instead
of once per file rotated. Also, files will be compressed in order of
file-size (smallest to largest). Also, it waits for each file to be
completely compressed before starting the next one (effectively as if
the 'w' flag is specified for all entries in newsyslog.conf). This
avoids the situation of having 10 gzip's going at the same time (each
with a log.0 and a log.0.gz file active), and it also means that file
attributes can be reliably set on files after they are compressed.

NOTE: This commit does define NEWORDER (which you could get rid of if
you really don't trust this), but it does not flip the "-D neworder"
switch. So, at the moment none of these changes happen unless you
request them (perhaps by adding '<debug> neworder' in newsyslog.conf).

PR: bin/25070 inspired some parts of this
Submitted by: parts from bin/25070 done by Helge Oldach
MFC after: 14 days
3e7bce2995cac67f35775e81b4f6bd217fa587e6 07-Jun-2004 gad <gad@FreeBSD.org> A variety of minor changes. Allow users to set a debugging option via
the newsyslog.conf file. Rename one size-related variable, and move
another one from the stack into conf_entry. Add a routine to change
file-attributes (chown, chmod, chflags), instead of having several
places doing the same sequence of system-calls. A few cosmetic/style
changes.

These should not effect any users. Most of these probably look
pointless, but they are the "insignificant parts" of a much larger
update that I'll be committing soon. Doing these as a separate update
should make that update easier to read.

MFC after: 14 days
2769786f25c4cbe188b047d5be6a128be7c491c7 03-Jun-2004 gad <gad@FreeBSD.org> Style-istic fix to a number of #define's that were not followed by a tab...

MFC after: 16 days
848f68aacc771e36713004936dd584d0eacaf71c 03-Jun-2004 gad <gad@FreeBSD.org> Add a 'D' flag that can be specified on entries in newsyslog.conf.
If specified, the matching log files will have the NODUMP flag set
on them after they are created.

Submitted by: Sean Eric Fagan
MFC after: 16 days
2837207f16afd70fee442e874ae2e7acda55cc78 03-Jun-2004 gad <gad@FreeBSD.org> Change standard processing to use the newer createlog() routine
that had been written some months ago for other processing. This
should get rid of a few subtle situations where an existing log
file would not exist (for a short time) while it is being rotated.

MFC after: 16 days
4f0e537c28e63712270d1fc2aff09f1313e6497d 02-Jun-2004 gad <gad@FreeBSD.org> Improved versions of the is*ch() and tolowerch() macros that I like to use.
d731f360fab7c78caec572a49149caa7361869f2 02-Jun-2004 gad <gad@FreeBSD.org> When rotating some "blah.log" file, make sure that a chmod and
(if requested) a chown is done on the "blah.log.0" file.

PR: bin/67137
Submitted by: jeh
MFC after: 10 days
55f036c490e9ed18d690778930a1e786908a0d8f 04-Apr-2004 charnier <charnier@FreeBSD.org> Do not :-terminate err(3) string, one will be added anyway.
8dafe430a02604e433903c786d2161b805228379 23-Sep-2003 gad <gad@FreeBSD.org> Restructure the time processing routines, mainly to fix up the
"will trim at" message printed when the user requests '-v'. The
previous code would often print the wrong time, such as:
On Sept 22, run: newsyslog -nv /var/log/wtmp
And see: will trim at Mon Sep 1 05:00:00 2003
correct msg: will trim at Wed Oct 1 05:00:00 2003

MFC after: 20 days
60909145e3ca1c6c165667bea0e781fb1526585d 12-Sep-2003 gad <gad@FreeBSD.org> Move the parse8601 and parseDWM routines into a new ptime.c file. The
only code-change is to add a "next_time" parameter to both routines (and
that is not used yet). A later update will make "next_time" more useful.

MFC after: 20 days
f5048efe20920dddaaaa563ca567adb4a6865da6 09-Sep-2003 gad <gad@FreeBSD.org> Switch dotrim() to take advantage of the 'struct conf_entry' that
is already passed in, instead of having the caller copy values from
that struct into additional parameters.

MFC after: 22 days
d1e43a257d9013d667583ddac94ee5f10c844f87 09-Sep-2003 gad <gad@FreeBSD.org> Reduce the annoying compiler warnings that pop up when compiling with
gcc 3.3.x and -Wshadow. Just renames 'log' variables to be 'logname'.

MFC after: 22 days
53db1769f397482da865abe9484dd6a84689d7cf 09-Sep-2003 gad <gad@FreeBSD.org> Correct the comment about which timezone-change loses an hour...

MFC after: 23 days
51bcd038d34f50a21e8446c647ac2fbd470d1c7b 09-Sep-2003 gad <gad@FreeBSD.org> Add a '-D <something>' command line arg, which can be used to set
debugging options. Initial option is '-D TN=<time>', which can be
used to see how newsyslog would work if run at the specified time.
(time format is ISO 8601, since that is already supported).

MFC after: 23 days
164bfdbc091928c96e507b36e8d48d94a05f7f51 09-Sep-2003 gad <gad@FreeBSD.org> Use strtol() instead of strtoul() in parse8601, so we can detect
negative values. Mainly done to sync this routine with OpenBSD.

Obtained from: OpenBSD
MFC after: 23 days
a19d1825e0d42d6ddb11d92a766ebf6d87e49c7f 09-Sep-2003 gad <gad@FreeBSD.org> Fix typo in the previous commit. Was checking wrong variable...

MFC after: 23 days
f3d9171d82902bfbca4906e52ac0c0d3586a295f 09-Sep-2003 gad <gad@FreeBSD.org> Change parse8601 and parseDWM so they return an alternate error value
for invalid times, and have the caller print the error message.

MFC after: 23 days
5c44455e41c6cee4ee3c3f0d17ca3e7ab881c251 09-Sep-2003 gad <gad@FreeBSD.org> Cosmetic change to move parse8601 right next to parseDWM. No code
is changed. (that will come in later updates).

MFC after: 23 days
b21b4520edc240251c53099b6c14b637c9baf097 19-Aug-2003 gad <gad@FreeBSD.org> When checking the 'user:group' field in newsyslog.conf, freebsd's source
was mistakenly calling the standard isnumber() function to find out if
the given 'user' or 'group' were all numeric. This meant that only the
first character of the fields were actually checked, so a username of
(say) '3com' would look like a number, and thus get mapped to uid=3 (bin)
instead of username=3com.

This bug was introduced back in freebsd's v1.1. That initial import
almost matches netbsd's v1.9, except that an internal isnumber()
routine was removed in favor of the standard library version. The thing
is, that internal routine was checking the entire string, and not just
the first digit. In OpenBSD, isnumber() was eventually renamed to
isnumberstr() to make the distinction more obvious, and I'm going to
follow that lead.

I believe this also happens to remove the last references to isnumber()
in the entire freebsd base system.

Obtained from: OpenBSD, by a long circuitous route
MFC after: 5 days
ff880b993e6ccf0433a67419c42064845d6f008a 02-Aug-2003 gad <gad@FreeBSD.org> Fix an 'bad file descriptor' error which would come up when using
the 'C' flag on an entry that also specifies 'user:group' info.

Submitted by: Riccardo Torrini <riccardo@torrini.org> in -current
MFC after: 4 days
f191592855ce0c76451ec38fca54dfa09e3eb920 05-May-2003 gad <gad@FreeBSD.org> Fix age_old_log checking so that it will notice log files which were
rotated and then compressed with bzip2 instead of gzip. Otherwise,
any file which had a time-interval specified for 'when' and also
specified the 'J' flag would be rotated every time newsyslog was run.
(this is a quick-fix, trying to beat the code-freeze for 5.1-release)

PR: bin/51519
MFC after: 1 week
2e101cf42bcedd60b9f18df6082dffdf52b8ca77 05-May-2003 gad <gad@FreeBSD.org> Slightly improve the checking of the 'size' field, so people will get
a warning message if they switch the values for 'size' and 'when'.

MFC after: 1 week
7293a24a2b093fcb82ba80e14cb33ff03e2e24e8 03-May-2003 obrien <obrien@FreeBSD.org> Use __FBSDID over rcsid[]. Protect copyright[] where needed.
6a34ae85e96f461802aa265b42a3a69877f86a2e 27-Apr-2003 gad <gad@FreeBSD.org> Add a -C (create) option for newsyslog, and a 'C' flag for entries in the
config file. If the -C option is specified once, then newsyslog will create
any entries which specify the 'C' option. If -C is given twice, then
newsyslog will create all missing log files. Some of this code comes
from NetBSD, although this implementation does not exactly match theirs.

Reviewed by: freebsd-arch
MFC after: 10 days
cb92a79e4c40edd2ec78f17a9894efc9d43df6b3 09-Mar-2003 gad <gad@FreeBSD.org> Fix interactions between entries for a specific file vs entries for
a filename pattern, and also wrt filenames given on the command line.
Now if a file is listed as a specific entry, it will not *also* be
processed by an entry specifying a pattern. And filename-patterns
will now only match existing files (ignoring directories, etc).

MFC after: 3 weeks
f9db095419821df338531839b2723722d812b0ec 09-Mar-2003 gad <gad@FreeBSD.org> The processing of files given on the command-line will work a little better
if we return the entire worklist, instead of just the last entry. A minor
fix to revision 1.57.

MFC after: 15 days
1664ca4405c0ae8ca2f173edcfe621ce8a5e3bcc 08-Mar-2003 gad <gad@FreeBSD.org> Add a config-file flag of 'U' or 'u' to indicate that the pid-file
will contain the pid for a process group. This means the file must
contain a negative value (as would be needed in the 'kill' commmand).
I still need to write man-page update before MFC-ing.

This started by rewriting the get_pid() routine. Later I looked at
what OpenBSD has, and included a few ideas from their send_signal()
routine. So, parts of this change are from OpenBSD, even though
OpenBSD does not actually have a 'U' flag.

PR: bin/28435
Reviewed by: no objections on freebsd-arch
MFC after: 3 weeks
cce5f198e18c21219065f7e9302a3bc8eb2856ff 07-Mar-2003 gad <gad@FreeBSD.org> Prefix all -n (noaction) "unix cmds" with tab, thus making it much easier
to sort out noaction messages from -v (verbose) messages. This also
improves a few noaction messages.

Obtained from: OpenBSD
MFC after: 3 weeks
b746208d78fdf4aefd26241eadd4179ab5d6de37 07-Mar-2003 gad <gad@FreeBSD.org> Move the -s (nosignal) processing, as newsyslog needs to print out a
warning message if -s is specified and it rotates a file that expects
to be compressed. This warning message is not printed if -R is also
specified, because we assume a -sR request is coming from the process
which would have been signaled, and that it has already released the
logfile.

Indirectly noticed by: sheldonh
8b25734b0597b951f2979117d6d4848fbca61813 03-Mar-2003 gad <gad@FreeBSD.org> Add missing 'static' on two routines, so they match their declarations.

PR: 29363 (a small part of)
Submitted by: dinoex
MFC after: 3 weeks
89abc187caca4016205a2b42708a77cb54a36c9a 03-Mar-2003 gad <gad@FreeBSD.org> A variety of cosmetic changes, mostly to (slightly) reduce diffs with
OpenBSD. Except for one added '\n', the object code is not changed.

MFC after: 3 weeks
c0a96487f99a54006fa7b45ae7832af60a6d9f28 03-Mar-2003 gad <gad@FreeBSD.org> Collapse two more parameters to dotrim() into the 'ent' parameter that is
already there. This should not effect anything.

MFC after: 3 weeks
b65d7a6b080953574b968d5378e4ec75dabd1342 03-Mar-2003 gad <gad@FreeBSD.org> Change to using uid_t and gid_t instead of int. Also change this won't
bother doing a chmod() if neither of these two fields are set.

Obtained from: OpenBSD
MFC after: 3 weeks
3e73a1764719961722c5c9b51e701e7ff05e51fb 03-Mar-2003 gad <gad@FreeBSD.org> Fix the interactions between specific log files given on the command line,
and config-file entries which specify a filename-pattern (glob). It is
still not perfectly-right, but at least it isn't completely-wrong.

Reviewed by: no objections on freebsd-arch
MFC after: 3 weeks
MFC addendum: (or after the code-freeze of 4.x is lifted)
6133e17fe01863494a188956c48aac643dfa7736 02-Mar-2003 gad <gad@FreeBSD.org> Add a command-line option of '-R somename', which indicates that newsyslog
should rotate all files given on the command, even if they don't seem to
need to be rotated. This would be used by some other command that decides
the given log file(s) should be rotated, but wants the "how" of that rotation
to be determined by entries to newsyslog. Wes expects to change syslogd to
take advantage of this. Man page will be updated after we're sure this is
all working the way we want it to.

Reviewed by: no objections on freebsd-arch
MFC after: 3 weeks
MFC addendum: (or after the code-freeze of 4.x is lifted)
0b924719849b7e5814e306f2666f4f951f057407 02-Mar-2003 gad <gad@FreeBSD.org> Add a command-line option of '-s', which indicates that newsyslog should
not send a signal to any processes. Also add a config-file flag of 'N' or
'n', which indicates that the given logfile has no process which needs a
signal when it is rotated. Both of these are based on changes NetBSD
has made, although the implementation is somewhat different.

PR: bin/36553 (2nd half)
Reviewed by: no objections on freebsd-arch
Obtained from: NetBSD (in spirit, at least)
MFC after: 3 weeks
c45907ca760efec7ef6c240175eb9bca51039fb4 26-Feb-2003 gad <gad@FreeBSD.org> Fix an error which caused 'free(): error: chunk is already free'
if an entry in the config file included flag 'G'.

MFC after: 3 weeks
6f5632ffc0859abc21b1e7f8f07b45f4f69d0cad 24-Feb-2003 gad <gad@FreeBSD.org> Check the value given for number-of-logs to keep in config-file entries,
and error-out if the value is negative (avoiding an infinite loop).

PR: bin/30654 (part of it)
MFC after: 3 weeks
371919ba7e1991c5112be6f568369cd5e2a66d50 24-Feb-2003 gad <gad@FreeBSD.org> 1) Fix so -a honors the -n ("do nothing") option. Before, if the directory
given for -a did not exist, then newsyslog would always try to create
it, even if -n was specified.
2) When -a processing *does* create the directory, have it check the result
from mkdir(), and immediately error-out if that failed.

PR: bin/46974
MFC after: 3 weeks
0e9df41dbbb4f446aad10d3bc5c3c66d027ab14c 24-Feb-2003 gad <gad@FreeBSD.org> Minor style fix. Add parenthesis around 'return' values.

Reviewed by: md5
MFC after: 3 weeks
06f0413c15c9b30e7951763c79d1d49358f870f6 24-Feb-2003 gad <gad@FreeBSD.org> Add the idea of a "default rotate action", which will be used if a file is
specified at runtime, but that filename is not listed in the newsyslog.conf
file. This default-action can be changed by having a line in newsyslog.conf
with the filename of "<default>". Before this change, the program would
quietly ignore the given file. An update to the man page will be written
after I finish some other updates to newsyslog.c.

Reviewed by: no objections from freebsd-arch
MFC after: 3 weeks
629bbce50c5ed38c42c10a3eeb9533d8f06b0b39 21-Dec-2002 trhodes <trhodes@FreeBSD.org> Make newsyslog(8) print the correct date when the logs are turned over.

PR: 46395
Submitted by: maxim
MFC: eventually
233f99ac853934697c268615c66bbf40d63568a1 15-Dec-2002 sobomax <sobomax@FreeBSD.org> Add a new `W' flag, that when used in conjunction with the `Z' flag or the
`J' flag means that newsyslog should wait for previously started compression
jobs to complete before starting a new one for this entry. When it is used
along with the `G' flag, in the case when several logfiles match the pattern
and should be compressed, the newsyslog will compress logs one by one,
ensuring that only one compression job is running at a time.

This prevents newsyslog(8) from overloading system by starting several
compression jobs on big files simultaneously.

Sponsored by: Porta Software Ltd
MFC after: 2 weeks
aaf3d7c459bc6392a36f568d6996785a9870b9d8 11-Dec-2002 sobomax <sobomax@FreeBSD.org> - Allow comments to be placed at the end of configuration line.

Sponsored by: Porta Software Ltd
Approved by: re
MFC after: 2 weeks
cd8d065bddcd1323688daf80abbe75a950d217b9 14-Nov-2002 sobomax <sobomax@FreeBSD.org> Add a new newsyslog.conf flag - 'G', which if set tells newsyslog(8) that
the specified filename of the log to be rotated is in fact shell glob
pattern. In this case, all files matching this pattern will be rotated
using the same options. Useful in the case when there is no pre-defined
name for the logfiles (e.g. xtradius, samba etc).

Sponsored by: PortaOne Software Ltd
MFC after: 2 weeks
318aa50bf9b1879c25404ddd2b695248e215122f 16-Oct-2002 maxim <maxim@FreeBSD.org> Fix getopt(3) optstring: remove a flag we does not handle.

PR: bin/44066
Submitted by: Stefan Farfeleder <e0026813@stud3.tuwien.ac.at>
MFC after: 1 week
f6364a955e01d3049c475f7bc6ff1d911be69324 01-Jul-2002 maxim <maxim@FreeBSD.org> Remove the last EOF spaces I missed in rev. 1.43.

MFC after: 1 week
b187b4614074a352788adbb99557c8ca688051ca 03-May-2002 maxim <maxim@FreeBSD.org> style(9): sort includes, remove EOL spaces.

MFC after: 1 week
f4c5d520c3b2edd8d8be1b3c72f692e4159650da 03-May-2002 maxim <maxim@FreeBSD.org> wait(2) for compress_log() processes to complete before exit.

Spotted by: Grigoriy Strokin <grg@isabase.philol.msu.ru>
Reviewed by: -current
MFC after: 1 month
c6c6023da15f1b201e6592f54325f89bbd96a75b 10-Apr-2002 sheldonh <sheldonh@FreeBSD.org> Close a very small window during which new (empty) instances of rotated log
files are owned by the caller of newsyslog (usually root:wheel) even if
alternative ownerships were specified in newsyslog.conf.

Note that this is part of a wider problem which is fully addressed in
OpenBSD. Anyone with the time and inclination to incorporate the full
fix for the wider problem will receive no complaints from me and should
feel free to walk all over this delta.

PR: bin/36738
MFC after: 1 week
0ca247271e1c842f55e2ec2e09371da7ffce72c5 02-Apr-2002 cjc <cjc@FreeBSD.org> Produce a different error message for mktime(3) failure than for bad
newsyslog.conf syntax.

PR: bin/36641
6a18ede7cd38d3c8ddd08197fafced885dece4f3 05-Feb-2002 roam <roam@FreeBSD.org> Fix -F with logfiles rotated on time only.

Approved by: silence on -audit
MFC after: 1 month
baad1b4d27696fdb8c7c8ac265b1588d99ef2aad 14-Nov-2001 obrien <obrien@FreeBSD.org> Fix the type of the NULL arg to execl().
bee43330be72b370afc45a2cc59ef061a16cc349 31-Jul-2001 obrien <obrien@FreeBSD.org> jhb says a 10 line change containing casts is more invasive than a 28 line
change.
790155d37f7c36c6cc0fd236fa08d7541df88543 30-Jul-2001 obrien <obrien@FreeBSD.org> Use the POSIX syntax for chown.

Submmited by: garrett
22345dd98c6cb758fc140ada39411eec62ae1e64 30-Jul-2001 wollman <wollman@FreeBSD.org> Simplify (and hopefully clarify) some date-parsing arithmetic.
8f93713df5e70a630cf91db6f141a03b29821c5d 30-Jul-2001 obrien <obrien@FreeBSD.org> style(9)
76dec2511d5f3e66089d7b482d99ea22946ceee8 30-Jul-2001 obrien <obrien@FreeBSD.org> WARNS-2'ify.
(this included removing the funny "if (unsigned_var < 0)" test)
bce695d83a6b662c96bd81e2b732b673f3c9854d 30-Jul-2001 obrien <obrien@FreeBSD.org> Add the ability to Bzip2 your logs.

PR: 27901
Submitted by: Anders Nordby <anders@fix.no> (stylistic changes by me)
8636b161b333b18525b6f5ffc5139079c29c0d63 09-Jul-2001 brian <brian@FreeBSD.org> Fix the type of the NULL arg to execl()

Idea from: Theo de Raadt <deraadt@openbsd.org>
fca3b93cb33c66afb73b14b76d9e4ba823846eff 20-Jan-2001 jedgar <jedgar@FreeBSD.org> - Correct MAXPATHLEN/MAXHOSTNAMELEN usage
- Check return values of malloc() and strdup()
- Replace strcpy()/strcat()/sprintf() usage with strlcpy()/snprintf

Reviewed by: -audit
2be7b9be57e2292a0500871746420dd9d218f2bf 15-Aug-2000 joe <joe@FreeBSD.org> When warning that a log file can't be compressed, tell the reader which
log file it was.
7d6740ec11e74d97fb52354e28552590cf2dc4ad 11-May-2000 des <des@FreeBSD.org> Allow user to specify which logs to rotate
aef627d63f70cc2aa92ca509a7119f7838f842d9 04-Apr-2000 hm <hm@FreeBSD.org> - implement logfile archivation to a separate, user
configurable directory
- implement alternate and more flexible way to specify
logfile rotation time in addition to the ISO 8601
restricted format
- cleanup the source which was a mix of several styles
of persons who maintained it so far, ran through
knfom script got from bde.

Reviewed by: (in part) sheldonh and garyj
b5fa5b4499a641e32e05a720e1d58880ea5fcc33 04-Apr-2000 hm <hm@FreeBSD.org> Run newsyslog source through knfom script obtained from Bruce Evans.
Joerg Wunsch suggested to do this to make the functional changes in
the next commit to newsyslog (which were run through the same script)
better visible.
b42951578188c5aab5c9f8cbcde4a743f8092cdc 02-Apr-2000 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'ALSA'.
efabb9ccb197b05958967dd035c279ba3bc19cb0 28-Aug-1999 peter <peter@FreeBSD.org> $Id$ -> $FreeBSD$
4bcf1a9e396b6d2e39d5dddd1d07ae0104160327 28-Jul-1999 obrien <obrien@FreeBSD.org> Go back to allowing ``.'' as a username.group separator for backward
compatibility. : is still the documented non-ambiguous approach. The
algorithm used will correctly parse david.obrien.staff as strrchar() is
used, and in my mind more people would use a ``.'' in the username than
the group name.

Convinced by argument and patch by: sheldonh (with slight changes by me)
d3ca6b9c8b4b19817adf7a30a13d910ba9726375 28-Jun-1999 obrien <obrien@FreeBSD.org> Syntax for user/group is changed from "user.group" to "user:group" to be
consistant with chown(8).
27719c46cd1486850c0576f2129a7fd6b5c6255b 22-Jan-1999 wollman <wollman@FreeBSD.org> A slight bit of code and doco cleanup, but mostly:

Add the much-needed and long-desired ability to force the log rotation
to take place on a specific day or time, and document same. This works
by extending the syntax of the `when' field to allow a restricted
ISO 8601 time specification, and performing the log rotation if newsyslog
is run during the same hour as is specified.
255d59c0a4640c263a6a77e9a6578565ea49c0c0 23-Dec-1998 peter <peter@FreeBSD.org> The largest PID is now 99999
Reported by: Ben Stuyts <ben@stuyts.nl>
5a975158614efb26c015a4ddb23a784a3d4fa6b4 09-Jun-1998 ache <ache@FreeBSD.org> Add optional config file field: signal number to send (defaulted to HUP)
F.e. apache restarts less agressively on USR1 then on HUP
25434404e971356b6700b748dbb7be9bbfb5472e 10-May-1998 hoek <hoek@FreeBSD.org> 1) kill -HUP syslog, even if compressing supposedly "binary" files
PR: docs/6385

2) -n (noaction) does not imply -r (run as non-root), since as of
Rev. 1.12 (ache), -r changes actual behaviour.

3) missing \n from if(noaction) messages.
0a7127e1cb6b6529c6403e04d4fcba1b120bc450 10-May-1998 hoek <hoek@FreeBSD.org> Arg! Someone fixed the synopsis in -stable's newsyslog.8, but not
in -current. However, they fixed both the ordering and the missing -F
flag. Merge from 22 and fix ordering here, too.
ff2ed8473c160dd743558c41a1ec2d0b28cf26db 10-May-1998 hoek <hoek@FreeBSD.org> Fix the usage here, too (-F option).

Typo fix in comment ("Force the tim now matter what" s/tim/trim/)
6e818c9e9f6757f39f1e3e8243b88624c1abb812 14-Mar-1998 pst <pst@FreeBSD.org> Add "-F" (force) flag to newsyslog.
Submitted by: Terry Lambert <terry@freebsd.org>
0506343883d62f6649f7bbaf1a436133cef6261d 11-Jan-1998 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'jb'.
7c6e96080c4fb49bf912942804477d202a53396c 10-Jan-1998 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'JB'.
725b6bc43bf6f6446f1c82a83d8c6cb464f79817 30-Nov-1997 ache <ache@FreeBSD.org> Sleep 10secs after kill -HUP instead of 3secs, some daemons like Apache
may have log time to re-configure
2e4411caecd2d8307c50b7a0d90ee217ec5f84fe 06-Oct-1997 charnier <charnier@FreeBSD.org> Cosmetic in err() strings.
213a2efd3a7c6eb44eec3a6ca67c84b9a8fad0dd 06-May-1997 brian <brian@FreeBSD.org> Allow a '-' flag as a placeholder so that path_to_pid_file
can be specified without the flags field.
Fix bogus "trail" left in parse routine where the code jumps
past the end of the line and wanders into oblivion.
40924e377c7624fb8a1a0f208e30a0364780684b 05-May-1997 ache <ache@FreeBSD.org> Do not kill -HUP syslog if running in user mode (-r), it allows
private user logs rotation without error diagnostics
28bcd2026c62c8edda454b1c0e276f1720f7937e 04-May-1997 ache <ache@FreeBSD.org> 1) Add yet one optional field: pid file to send SIGHUP to if log rotated
(good thing for apache f.e.) This change is backward compatible with old
newsyslog.conf files.

2) Do not compress log if SIGHUP sending failed for some reason
(f.e. pid file deleted). Newcoming messages will be lost
otherwise.

3) Misc cleanup while I am here.
691010efad5c05f7ee86a870abce217fe8e9b8d1 31-Mar-1997 imp <imp@FreeBSD.org> compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
b782f4df30a869a074431c7b185f0c7c69878254 22-Feb-1997 peter <peter@FreeBSD.org> Revert $FreeBSD$ to $Id$
808a36ef658c1810327b5d329469bcf5dad24b28 14-Jan-1997 jkh <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.
398ef266db7d9602f783d0c7bd43193b2c2222bb 09-Sep-1996 jkh <jkh@FreeBSD.org> Doh! Actually read the patch I applied and see what it was *trying* to do,
then make it do that.
Error-of-my-ways-pointed-out-by: Bob Willcox <bob@luke.pmr.com>
bbacb62fd0171e0396ab8ce90f23482d80c3dafc 06-Sep-1996 jkh <jkh@FreeBSD.org> PR#2724 in NetBSD notes that newsyslog save log files even if the number
of copies to save is zero. Incorporate suggested fix with some stylistic
cleanup to make the resulting code more readable.
Submitted-By: Kenneth Stailey <kstailey@dol-esa.gov>
285b22dc7aed66ce161ae1444dda4edff568dad9 08-Jun-1996 alex <alex@FreeBSD.org> Added function prototypes and removed in-line prototypes of standard
functions such as malloc and time.
ca53d12a6ed9cf8dbf38cc2f7b8131ba4ea25b1d 07-Jun-1996 alex <alex@FreeBSD.org> Fix uninitialized variable that caused a core dump if /etc/newsyslog.conf
was empty. Closes PR bin/1300.

Found by: Brian Tao <taob@io.org>
aa38c6724dcee99229e26b60534ac99da0e37f7a 16-Jan-1996 graichen <graichen@FreeBSD.org> Submitted by: charnier@lirmm.fr (Philippe Charnier)
1) correct MAX_PID according to system definition.
2) replace fprintf(stderr,...)/perror/exit by 4.4 equivalence.
3) make strings enough larger so they can't overflow: MAXHOSTNAMELEN for
host and MAXPATHLEN for filenames.
4) call execl with correct parameters (compress -> gzip).
cc0f623ba56c68c7ef13a714ce3042f2cebc2a4e 09-Jan-1996 graichen <graichen@FreeBSD.org> Obtained from: NetBSD (PR#1906)
removed date formatting glitch in newsyslog
adc7000016eb37741d426b9e5362a1894b12093a 05-Jan-1996 graichen <graichen@FreeBSD.org> Obtained from: NetBSD
imported the newsyslog command from NetBSD - it make the "rotation" of
the logfiles much simpler (it is currently done by "hand" in the
/etc/[daily,weekly,monthly] scripts) - now it will be done by invoking
newsyslog every hour which is very customizable via a
/etc/newsyslog.conf file