Bug 2070496

Summary: syslog postrotate instruction terminates the service when POSIXLY_CORRECT env variable is set
Product: Red Hat Enterprise Linux 8 Reporter: Dariusz Wojewódzki <dwojewod>
Component: rsyslogAssignee: Attila Lakatos <alakatos>
Status: CLOSED ERRATA QA Contact: Dalibor Pospíšil <dapospis>
Severity: low Docs Contact: Jan Fiala <jafiala>
Priority: unspecified    
Version: 8.5CC: alakatos, dapospis, rsroka
Target Milestone: rcKeywords: AutoVerified, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: rsyslog-8.2102.0-13.el8 Doc Type: Bug Fix
Doc Text:
.`logrotate` no longer incorrectly signals Rsyslog in log rotation Previously, the argument order was incorrectly set in the `logrotate` script, which caused a syntax error. This resulted in `logrotate` not correctly signaling Rsyslog during log rotation. With this update, the order of the arguments in `logrotate` is fixed and `logrotate` signals Rsyslog correctly after log rotation even when the `POSIXLY_CORRECT` environment variable is set.
Story Points: ---
Clone Of:
: 2124488 (view as bug list) Environment:
Last Closed: 2023-05-16 08:36:49 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2124488    

Description Dariusz Wojewódzki 2022-03-31 09:42:36 UTC
Version-Release number of selected component (if applicable):

rsyslog-8.2102.0-5.el8.x86_64
bash-4.4.20-2.el8.x86_64



#cat /etc/logrotate.d/syslog

/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
    missingok
    sharedscripts
    postrotate
        /usr/bin/systemctl kill -s HUP rsyslog.service >/dev/null 2>&1 || true
    endscript
}



How reproducible:



[root@rhel85 ~]# echo $POSIXLY_CORRECT

[root@rhel85 ~]# /usr/bin/systemctl kill -s HUP rsyslog.service
[root@rhel85 ~]# systemctl status rsyslog.service
● rsyslog.service - System Logging Service
   Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2022-03-31 11:18:04 CEST; 10min ago
     Docs: man:rsyslogd(8)
           https://www.rsyslog.com/doc/
 Main PID: 877 (rsyslogd)
    Tasks: 3 (limit: 23464)
   Memory: 2.5M
   CGroup: /system.slice/rsyslog.service
           └─877 /usr/sbin/rsyslogd -n

Mar 31 11:18:04 rhel85.example.com systemd[1]: Starting System Logging Service...
Mar 31 11:18:04 rhel85.example.com systemd[1]: Started System Logging Service.
Mar 31 11:18:04 rhel85.example.com rsyslogd[877]: [origin software="rsyslogd" swVersion="8.2102.0-5.el8" x-pid=">
Mar 31 11:18:04 rhel85.example.com rsyslogd[877]: imjournal: journal files changed, reloading...  [v8.2102.0-5.e>
Mar 31 11:22:23 rhel85.example.com rsyslogd[877]: [origin software="rsyslogd" swVersion="8.2102.0-5.el8" x-pid=">
Mar 31 11:28:12 rhel85.example.com rsyslogd[877]: [origin software="rsyslogd" swVersion="8.2102.0-5.el8" x-pid=">



[root@rhel85 ~]# export POSIXLY_CORRECT=1

[root@rhel85 ~]# /usr/bin/systemctl kill -s HUP rsyslog.service
Failed to kill unit -s.service: Unit -s.service not loaded.
Failed to kill unit HUP.service: Unit HUP.service not loaded.

[root@rhel85 ~]# systemctl status rsyslog.service
● rsyslog.service - System Logging Service
   Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2022-03-31 11:28:47 CEST; 4s ago
     Docs: man:rsyslogd(8)
           https://www.rsyslog.com/doc/
  Process: 877 ExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 877 (code=exited, status=0/SUCCESS)

Mar 31 11:18:04 rhel85.example.com systemd[1]: Starting System Logging Service...
Mar 31 11:18:04 rhel85.example.com systemd[1]: Started System Logging Service.
Mar 31 11:18:04 rhel85.example.com rsyslogd[877]: [origin software="rsyslogd" swVersion="8.2102.0-5.el8" x-pid=">
Mar 31 11:18:04 rhel85.example.com rsyslogd[877]: imjournal: journal files changed, reloading...  [v8.2102.0-5.e>
Mar 31 11:22:23 rhel85.example.com rsyslogd[877]: [origin software="rsyslogd" swVersion="8.2102.0-5.el8" x-pid=">
Mar 31 11:28:12 rhel85.example.com rsyslogd[877]: [origin software="rsyslogd" swVersion="8.2102.0-5.el8" x-pid=">
Mar 31 11:28:47 rhel85.example.com rsyslogd[877]: [origin software="rsyslogd" swVersion="8.2102.0-5.el8" x-pid=">
Mar 31 11:28:47 rhel85.example.com rsyslogd[877]: [origin software="rsyslogd" swVersion="8.2102.0-5.el8" x-pid=">
Mar 31 11:28:47 rhel85.example.com systemd[1]: rsyslog.service: Succeeded.

Comment 1 Attila Lakatos 2022-04-05 11:47:49 UTC
Hello,

To me, it does not seem like a bug in rsyslog, when the POSIXLY_CORRECT=1 env variable is set.
If you take a look at the command output lines:
Failed to kill unit -s.service: Unit -s.service not loaded.
Failed to kill unit HUP.service: Unit HUP.service not loaded.

You can see that it is not capable of determining which parameter represents the signal. Firstly, it tries the "-s.service"(don't know why), which probably does not exist. From the systemctl man page: --signal: When used with kill, choose which signal to send to selected processes. Must be one of the well-known signal specifiers such as SIGTERM, SIGINT or SIGSTOP. If omitted, defaults to SIGTERM.
As it was unable to process the signal part, the default is used, which is the SIGTERM signal. In that case, it is delivered to the rsyslog service. Thus, rsyslog will terminate.

Feel free to correct me if I am wrong.

Comment 2 Dariusz Wojewódzki 2022-04-06 08:08:14 UTC
Hello, This command is in the official rsyslog package in the /etc/logrotate.d/syslog file.

As you stated, systemctl wants to kill both the -s and HUP services that do not exist and sends a SIGTERM signal to all parameters after kill, rather than interpreting -s as a switch.

On the other hand:
 "/usr/bin/systemctl -s HUP kill rsyslog.service >/dev/null 2>&1 || true" works with POSIXLY_CORRECT.

Comment 3 Attila Lakatos 2022-04-07 08:38:23 UTC
Hello,

Now I can see the difference between the two commands:
1.  /usr/bin/systemctl kill -s HUP rsyslog.service
2.  /usr/bin/systemctl -s HUP kill rsyslog.service

So in case the POSIXLY_CORRECT=1 env var is set, only the second option is correct. Both versions work when the mentioned env variable is not set. Although I do not know the reason behind it.

According to the manual page, the syntax should be the following:
  systemctl [OPTIONS...] COMMAND [NAME...]

Thanks for noticing it.

Comment 19 errata-xmlrpc 2023-05-16 08:36:49 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (rsyslog bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2831