Page MenuHomeFreeBSD

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

Authored by alex_kaworu.ch on Oct 21 2015, 1:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 4, 10:17 PM
Unknown Object (File)
Wed, Dec 4, 10:17 PM
Unknown Object (File)
Nov 24 2024, 2:06 PM
Unknown Object (File)
Oct 10 2024, 10:46 PM
Unknown Object (File)
Oct 10 2024, 3:59 AM
Unknown Object (File)
Oct 5 2024, 8:53 AM
Unknown Object (File)
Oct 5 2024, 6:36 AM
Unknown Object (File)
Oct 2 2024, 5:34 PM
Subscribers

Details

Summary

Before this patch, signals in newsyslog.conf must be configured using the number (e.g. 30 for SIGUSR1). This patch add the possibility to write the signal name (e.g. SIGUSR1) and adapt the man page accordingly.

Test Plan

none

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 875
Build 875: arc lint + arc unit

Event Timeline

alex_kaworu.ch retitled this revision from to newsyslog.conf: allow configure the signal using the signal name..
alex_kaworu.ch updated this object.
alex_kaworu.ch edited the test plan for this revision. (Show Details)
alex_kaworu.ch added a reviewer: bapt.

signame_to_signum taken from kill(1), manpage changes based on OpenBSD's newsyslog.conf.

head/usr.sbin/newsyslog/newsyslog.c
1360

I think the whole logic of validating signal should reuse something like https://svnweb.freebsd.org/base/head/usr.bin/timeout/timeout.c?view=markup&pathrev=278810#l103
It would simplify lots of things

head/usr.sbin/newsyslog/newsyslog.c
1360

Sure, let me patch/test and update the diff :)

alex_kaworu.ch edited edge metadata.

Cleanup the signal parsing as requested by @bapt

Here is a sample test session using the -v (verbose) and -n (don't trim but print actions) options.

At first, we have a simple test config using a signal number (and also an executable path to test compatibility) and see the result with /usr/sbin/newsyslog (testing on 10.2-RELEASE-p5). Then we include a rotation using the signal name and run the patched newsyslog command. As a result it seems to interpret correctly both the signum and shellcmd lines (as the non-patched version does), while successfully parsing and executing the signame line.

[alex@smaug.kaworu.ch /tmp/newsyslog] % cat test.conf 
# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
/tmp/newsyslog/signum-test.log          644  1     1    *     J     /var/run/rspamd/rspamd.pid 30
/tmp/newsyslog/cmd-test.log             644  1     1    *     JR    /bin/ls
[alex@smaug.kaworu.ch /tmp/newsyslog] % /usr/sbin/newsyslog -vn -f ./test.conf 
Processing ./test.conf
/tmp/newsyslog/signum-test.log <1J>: size (Kb): 1 [1] --> trimming log....
        rm -f /tmp/newsyslog/signum-test.log.1
        rm -f /tmp/newsyslog/signum-test.log.1.gz
        rm -f /tmp/newsyslog/signum-test.log.1.bz2
        rm -f /tmp/newsyslog/signum-test.log.1.xz
        rm -f /tmp/newsyslog/signum-test.log.0
        rm -f /tmp/newsyslog/signum-test.log.0.gz
        rm -f /tmp/newsyslog/signum-test.log.0.bz2
        rm -f /tmp/newsyslog/signum-test.log.0.xz
        ln /tmp/newsyslog/signum-test.log /tmp/newsyslog/signum-test.log.0
        touch /tmp/newsyslog/signum-test.log.0          # Update mtime for 'when'-interval processing
        chmod 644 /tmp/newsyslog/signum-test.log.0
Start new log...
        mktemp /tmp/newsyslog/signum-test.log.zXXXXXX
        chmod 644 /tmp/newsyslog/signum-test.log.zXXXXXX
        mv /tmp/newsyslog/signum-test.log.zXXXXXX /tmp/newsyslog/signum-test.log
/tmp/newsyslog/cmd-test.log <1J>: size (Kb): 1 [1] --> trimming log....
        rm -f /tmp/newsyslog/cmd-test.log.1
        rm -f /tmp/newsyslog/cmd-test.log.1.gz
        rm -f /tmp/newsyslog/cmd-test.log.1.bz2
        rm -f /tmp/newsyslog/cmd-test.log.1.xz
        rm -f /tmp/newsyslog/cmd-test.log.0
        rm -f /tmp/newsyslog/cmd-test.log.0.gz
        rm -f /tmp/newsyslog/cmd-test.log.0.bz2
        rm -f /tmp/newsyslog/cmd-test.log.0.xz
        ln /tmp/newsyslog/cmd-test.log /tmp/newsyslog/cmd-test.log.0
        touch /tmp/newsyslog/cmd-test.log.0             # Update mtime for 'when'-interval processing
        chmod 644 /tmp/newsyslog/cmd-test.log.0
Start new log...
        mktemp /tmp/newsyslog/cmd-test.log.zXXXXXX
        chmod 644 /tmp/newsyslog/cmd-test.log.zXXXXXX
        mv /tmp/newsyslog/cmd-test.log.zXXXXXX /tmp/newsyslog/cmd-test.log
Signal all daemon process(es)...
        kill -30 20617          # /var/run/rspamd/rspamd.pid
        sleep 1
        sh -c '/bin/ls 1'
        sleep 10
Compress all rotated log file(s)...
        bzip2 /tmp/newsyslog/cmd-test.log.0
        chmod 644 /tmp/newsyslog/cmd-test.log.0.bz2
        bzip2 /tmp/newsyslog/signum-test.log.0
        chmod 644 /tmp/newsyslog/signum-test.log.0.bz2
[alex@smaug.kaworu.ch /tmp/newsyslog] % echo "/tmp/newsyslog/signame-test.log         644  1     1    *     J     /var/run/nginx.pid SIGUSR1" >> test.conf
[alex@smaug.kaworu.ch /tmp/newsyslog] % cat test.conf 
# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
/tmp/newsyslog/signum-test.log          644  1     1    *     J     /var/run/rspamd/rspamd.pid 30
/tmp/newsyslog/cmd-test.log             644  1     1    *     JR    /bin/ls
/tmp/newsyslog/signame-test.log         644  1     1    *     J     /var/run/nginx.pid SIGUSR1
[alex@smaug.kaworu.ch /tmp/newsyslog] % ./newsyslog.patched -vn -f ./test.conf 
Processing ./test.conf
/tmp/newsyslog/signum-test.log <1J>: size (Kb): 1 [1] --> trimming log....
        rm -f /tmp/newsyslog/signum-test.log.1
        rm -f /tmp/newsyslog/signum-test.log.1.gz
        rm -f /tmp/newsyslog/signum-test.log.1.bz2
        rm -f /tmp/newsyslog/signum-test.log.1.xz
        rm -f /tmp/newsyslog/signum-test.log.0
        rm -f /tmp/newsyslog/signum-test.log.0.gz
        rm -f /tmp/newsyslog/signum-test.log.0.bz2
        rm -f /tmp/newsyslog/signum-test.log.0.xz
        ln /tmp/newsyslog/signum-test.log /tmp/newsyslog/signum-test.log.0
        touch /tmp/newsyslog/signum-test.log.0          # Update mtime for 'when'-interval processing
        chmod 644 /tmp/newsyslog/signum-test.log.0
Start new log...
        mktemp /tmp/newsyslog/signum-test.log.zXXXXXX
        chmod 644 /tmp/newsyslog/signum-test.log.zXXXXXX
        mv /tmp/newsyslog/signum-test.log.zXXXXXX /tmp/newsyslog/signum-test.log
/tmp/newsyslog/cmd-test.log <1J>: size (Kb): 1 [1] --> trimming log....
        rm -f /tmp/newsyslog/cmd-test.log.1
        rm -f /tmp/newsyslog/cmd-test.log.1.gz
        rm -f /tmp/newsyslog/cmd-test.log.1.bz2
        rm -f /tmp/newsyslog/cmd-test.log.1.xz
        rm -f /tmp/newsyslog/cmd-test.log.0
        rm -f /tmp/newsyslog/cmd-test.log.0.gz
        rm -f /tmp/newsyslog/cmd-test.log.0.bz2
        rm -f /tmp/newsyslog/cmd-test.log.0.xz
        ln /tmp/newsyslog/cmd-test.log /tmp/newsyslog/cmd-test.log.0
        touch /tmp/newsyslog/cmd-test.log.0             # Update mtime for 'when'-interval processing
        chmod 644 /tmp/newsyslog/cmd-test.log.0
Start new log...
        mktemp /tmp/newsyslog/cmd-test.log.zXXXXXX
        chmod 644 /tmp/newsyslog/cmd-test.log.zXXXXXX
        mv /tmp/newsyslog/cmd-test.log.zXXXXXX /tmp/newsyslog/cmd-test.log
/tmp/newsyslog/signame-test.log <1J>: size (Kb): 1 [1] --> trimming log....
        rm -f /tmp/newsyslog/signame-test.log.1
        rm -f /tmp/newsyslog/signame-test.log.1.gz
        rm -f /tmp/newsyslog/signame-test.log.1.bz2
        rm -f /tmp/newsyslog/signame-test.log.1.xz
        rm -f /tmp/newsyslog/signame-test.log.0
        rm -f /tmp/newsyslog/signame-test.log.0.gz
        rm -f /tmp/newsyslog/signame-test.log.0.bz2
        rm -f /tmp/newsyslog/signame-test.log.0.xz
        ln /tmp/newsyslog/signame-test.log /tmp/newsyslog/signame-test.log.0
        touch /tmp/newsyslog/signame-test.log.0         # Update mtime for 'when'-interval processing
        chmod 644 /tmp/newsyslog/signame-test.log.0
Start new log...
        mktemp /tmp/newsyslog/signame-test.log.zXXXXXX
        chmod 644 /tmp/newsyslog/signame-test.log.zXXXXXX
        mv /tmp/newsyslog/signame-test.log.zXXXXXX /tmp/newsyslog/signame-test.log
Signal all daemon process(es)...
        kill -30 20617          # /var/run/rspamd/rspamd.pid
        sleep 1
        kill -30 30969          # /var/run/nginx.pid
        sleep 1
        sh -c '/bin/ls 1'
        sleep 10
Compress all rotated log file(s)...
        bzip2 /tmp/newsyslog/signame-test.log.0
        chmod 644 /tmp/newsyslog/signame-test.log.0.bz2
        bzip2 /tmp/newsyslog/cmd-test.log.0
        chmod 644 /tmp/newsyslog/cmd-test.log.0.bz2
        bzip2 /tmp/newsyslog/signum-test.log.0
        chmod 644 /tmp/newsyslog/signum-test.log.0.bz2
[alex@smaug.kaworu.ch /tmp/newsyslog] %
bapt edited edge metadata.
This revision is now accepted and ready to land.Oct 24 2015, 1:53 PM
This revision was automatically updated to reflect the committed changes.