Commit Graph

139 Commits

Author SHA1 Message Date
Tim Kientzle
8f95d0d822 Fix -Wunsequenced
Submitted by:	dt71@gmx.com
2013-06-29 15:58:03 +00:00
Mark Johnston
950ff8e4dd 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
2013-06-02 01:10:49 +00:00
Mark Johnston
3cc26586e6 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
2013-05-12 01:58:04 +00:00
Mark Johnston
91ba008fc5 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
2013-03-26 23:11:30 +00:00
Mark Johnston
6a82e4291b 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
2013-01-27 06:03:57 +00:00
Mark Johnston
6df0ff43f0 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
2013-01-27 06:02:38 +00:00
Mark Johnston
3b58eef59e 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
2013-01-27 06:01:35 +00:00
Mark Johnston
9df22a6e88 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
2013-01-03 16:14:51 +00:00
Mark Johnston
468d206524 Have -n imply -r, since dry-run mode obviously doesn't require root
privileges.

Approved by:	rstone (co-mentor)
MFC after:	1 week
2013-01-03 16:12:48 +00:00
Mark Johnston
220936938f Fix a typo in an error message.
Approved by:	rstone (co-mentor)
MFC after:	1 week
2013-01-03 16:11:24 +00:00
Ed Schouten
eccad22277 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.
2012-10-20 10:33:15 +00:00
Andrey V. Elsukov
131f6ef034 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
2012-07-09 07:37:10 +00:00
Gleb Kurtsou
0bb2aabf26 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
2012-05-19 12:44:27 +00:00
Gleb Smirnoff
7be124b0a8 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
2012-03-21 06:51:45 +00:00
Ulrich Spörlein
f7bcc1c411 Further fix a typo and spelling classic correctly in function names,
too.

Submitted by:	Ben Kaduk <minimarmot@gmail.com>
2012-01-05 21:36:36 +00:00
Ed Schouten
b3608ae18f 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.
2012-01-03 18:51:58 +00:00
Ulrich Spörlein
3df5ecac8c Spelling fixes for usr.sbin/ 2011-12-30 10:58:14 +00:00
Eitan Adler
520374b5aa - Remove extraneous null ptr deref checks
- Fix memory leak

Submitted by:	Slono Slono <slonoman2011@yandex.ru>
Approved by:	jhb
MFC after:	1 week
2011-12-21 20:27:41 +00:00
Maxim Sobolev
ea640d778b 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
2011-05-14 03:00:55 +00:00
Simon L. B. Nielsen
449590b192 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
2011-04-21 16:31:05 +00:00
Ruslan Ermilov
b17e9548f8 Sync manpage's SYNOPSIS with program's usage. 2011-03-09 17:07:36 +00:00
Maxim Sobolev
8c6269ba81 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.
2011-02-22 09:11:47 +00:00
Martin Matuska
d90914ca73 Add xz(1) support to newsyslog.
Rewrite and simplify logfile compression code.

Approved by:	gad
MFC after:	3 weeks
2011-01-31 10:57:54 +00:00
Brian Somers
2921193efd Make -S functional.
MFC after:	1 week
2010-12-31 01:10:42 +00:00
Simon L. B. Nielsen
c86bcbb3a7 Fix a typo in a comment.
MFC after:	3 days
2010-11-21 11:50:16 +00:00
Brian Somers
318a43da85 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
2010-07-23 09:11:47 +00:00
Simon L. B. Nielsen
872e964d07 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
2010-07-22 11:23:18 +00:00
Gordon Tetlow
82c00be8ee 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
2010-05-29 22:55:59 +00:00
Gordon Tetlow
a40596d77a Convert newsyslog to using queue(3) macros instead of a home rolled version.
Reviewed by:	gad@
Approved by:	wes@ (mentor)
MFC after:	2 months
2010-05-29 22:52:17 +00:00
Xin LI
ccc28f774a 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
2010-01-20 01:07:38 +00:00
Xin LI
f65917cdc3 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
2009-12-21 20:12:01 +00:00
Xin LI
874f1f4efe Fix two typos. 2008-01-30 22:11:59 +00:00
Xin LI
ccb43d66aa Use same signedness for i and matched_c. This should make
newsyslog(8) WARNS=6 clean.
2006-08-17 18:15:43 +00:00
Maxim Sobolev
7697c5e483 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
2006-07-21 22:13:06 +00:00
Garance A Drosehn
656f773000 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
2006-06-27 22:14:09 +00:00
Garance A Drosehn
a04de8fa95 Remove the "oldorder" processing. The "neworder" processing has
been the default for two years now, without any problems reported.

MFC after:	3 weeks
2006-06-27 00:18:15 +00:00
Garance A Drosehn
616270cb21 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
2006-01-20 05:18:01 +00:00
Maxim Sobolev
4fd87db95a Fix logic error which causes <null> to be printed instead of the
actual file name in error message.

MFC After:	2 weeks
2005-12-01 03:47:01 +00:00
Brooks Davis
deea909a70 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
2005-03-03 15:47:32 +00:00
Xin LI
9e3daa8dcf 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
2005-01-04 02:24:01 +00:00
Brooks Davis
5616e1bc20 Mention "-d directory" in usage().
Pointy hat to:	brooks
2004-10-06 04:47:37 +00:00
Brooks Davis
59fdf30f92 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.
2004-10-05 22:16:31 +00:00
Brooks Davis
842ba60ee2 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.
2004-10-04 23:35:13 +00:00
Maxim Sobolev
ea6902220d 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
2004-07-04 17:24:12 +00:00
Garance A Drosehn
fbb4e16a3b Fix the format-string in a call to err(). It was causing a warning if
compiled on 4.x-stable.
2004-06-20 17:26:47 +00:00
Garance A Drosehn
5ff798ca5f 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
2004-06-19 03:28:42 +00:00
Garance A Drosehn
c8fd7c3227 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
2004-06-12 19:53:08 +00:00
Garance A Drosehn
4559c1817b 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
2004-06-07 21:18:09 +00:00
Garance A Drosehn
aa6904eb66 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
2004-06-07 21:09:58 +00:00
Garance A Drosehn
7f5b34d7c0 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
2004-06-07 02:10:10 +00:00