Bug 2124488

Summary: syslog postrotate instruction terminates the service when POSIXLY_CORRECT env variable is set
Product: Red Hat Enterprise Linux 9 Reporter: Attila Lakatos <alakatos>
Component: rsyslogAssignee: Attila Lakatos <alakatos>
Status: CLOSED ERRATA QA Contact: Dalibor Pospíšil <dapospis>
Severity: low Docs Contact: Petr Hybl <phybl>
Priority: unspecified    
Version: 9.1CC: dapospis, dwojewod, jafiala, phybl, qe-baseos-security, rsroka
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: rsyslog-8.2102.0-109.el9 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: 2070496 Environment:
Last Closed: 2023-05-09 07:44:54 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: 2070496    
Bug Blocks:    
Deadline: 2023-01-17   

Description Attila Lakatos 2022-09-06 10:20:16 UTC
+++ This bug was initially created as a clone of Bug #2070496 +++

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.

--- Additional comment from Attila Lakatos on 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.

--- Additional comment from Dariusz Wojewódzki on 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.

--- Additional comment from Attila Lakatos on 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 12 errata-xmlrpc 2023-05-09 07:44:54 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:2303