If you have a mail server that is running sendmail daemon (sendmail_enable=YES) and sendmail queue runner (sendmail_msp_queue=YES) and the sendmai daemon dies, /etc/rc.d/sendmail status does see the daemon is not running but returns 0 as the exit code. This prevents other programs (like puppet) from restarting sendmail to fix the issue. If the sendmail_msp_queue is not running, it will return non zero as the exit code: pirzyk@amigo:~ 2>sudo /etc/rc.d/sendmail status; echo $? sendmail is running as pid 874. sendmail_msp_queue is running as pid 877. 0 pirzyk@amigo:~ 3>sudo kill -9 874 pirzyk@amigo:~ 4>sudo /etc/rc.d/sendmail status; echo $? sendmail is not running. sendmail_msp_queue is running as pid 877. 0 pirzyk@amigo:~ 5>sudo /etc/rc.d/sendmail restart sendmail not running? (check /var/run/sendmail.pid). Starting sendmail. pirzyk@amigo:~ 6>sudo /etc/rc.d/sendmail status; echo $? sendmail is running as pid 6189. sendmail_msp_queue is running as pid 877. 0 pirzyk@amigo:~ 7>sudo kill -9 877; pirzyk@amigo:~ 8>sudo /etc/rc.d/sendmail status; echo $? sendmail is running as pid 6189. sendmail_msp_queue is not running. 1
Created attachment 187329 [details] Proposed patch to return non zero error code.
The idea seems good but adding exit statuses does not seem appropriate. I suggest the maximum instead: exit $(( _ret > $? ? _ret : $? )) The semicolon after exit is unnecessary and the style is to leave it off.
Created attachment 187544 [details] Proposed patch to return non zero error code (2nd try) Updated
Updated the patch with the suggestions but changed the references to _ret to $_ret
Dear maintainer, please take a look.
Not in progress obviously.
Undo previous change made by mistake.
I've taken a look at the script and I don't see a way to address this bug properly. A rewrite is the best option. For the time being, I agree that the submitted patch is a good temporary workaround that is not too invasive.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=d2e7bb630b83848a774d8213014a9e0747775019 commit d2e7bb630b83848a774d8213014a9e0747775019 Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2024-10-21 10:10:52 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2024-10-21 19:20:36 +0000 rc.d/sendmail: Return non-zero if the daemon fails to start or is not running If you have a mail server that is running sendmail daemon (sendmail_enable=YES) and sendmail queue runner (sendmail_msp_queue=YES) and the sendmail daemon dies, /etc/rc.d/sendmail status does see the daemon is not running but returns 0 as the exit code. This prevents other programs (like puppet) from restarting sendmail to fix the issue. Make sure that the exit code is propagated towards the end of the script if any of the sendmail services fail. This patch does not call exit directly but instead just sets the exit status code by calling exit in a subshell. This way we do not exit the current shell in case the service script is sourced (e.g., when rc_fast_and_loose is active). PR: 223132 MFC after: 2 weeks Reported by: pirzyk Discussed with: jilles, eugen Reviewed by: christos, gshapiro (previous version), markj Approved by: christos (mentor), markj (mentor) Differential Revision: https://reviews.freebsd.org/D46862 Co-authored-by: Jim Pirzyk <pirzyk@FreeBSD.org> libexec/rc/rc.d/sendmail | 6 ++++++ 1 file changed, 6 insertions(+)
Thanks!
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=4ff71ffaa79b4b609b70b60d716faffce768bb41 commit 4ff71ffaa79b4b609b70b60d716faffce768bb41 Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2024-10-21 10:10:52 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2024-11-04 14:55:40 +0000 rc.d/sendmail: Return non-zero if the daemon fails to start or is not running If you have a mail server that is running sendmail daemon (sendmail_enable=YES) and sendmail queue runner (sendmail_msp_queue=YES) and the sendmail daemon dies, /etc/rc.d/sendmail status does see the daemon is not running but returns 0 as the exit code. This prevents other programs (like puppet) from restarting sendmail to fix the issue. Make sure that the exit code is propagated towards the end of the script if any of the sendmail services fail. This patch does not call exit directly but instead just sets the exit status code by calling exit in a subshell. This way we do not exit the current shell in case the service script is sourced (e.g., when rc_fast_and_loose is active). PR: 223132 MFC after: 2 weeks Reported by: pirzyk Discussed with: jilles, eugen Reviewed by: christos, gshapiro (previous version), markj Approved by: christos (mentor), markj (mentor) Differential Revision: https://reviews.freebsd.org/D46862 Co-authored-by: Jim Pirzyk <pirzyk@FreeBSD.org> (cherry picked from commit d2e7bb630b83848a774d8213014a9e0747775019) libexec/rc/rc.d/sendmail | 6 ++++++ 1 file changed, 6 insertions(+)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=d36998a6cc6853e54066d476d146e1b510976418 commit d36998a6cc6853e54066d476d146e1b510976418 Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2024-10-21 10:10:52 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2024-11-04 14:55:55 +0000 rc.d/sendmail: Return non-zero if the daemon fails to start or is not running If you have a mail server that is running sendmail daemon (sendmail_enable=YES) and sendmail queue runner (sendmail_msp_queue=YES) and the sendmail daemon dies, /etc/rc.d/sendmail status does see the daemon is not running but returns 0 as the exit code. This prevents other programs (like puppet) from restarting sendmail to fix the issue. Make sure that the exit code is propagated towards the end of the script if any of the sendmail services fail. This patch does not call exit directly but instead just sets the exit status code by calling exit in a subshell. This way we do not exit the current shell in case the service script is sourced (e.g., when rc_fast_and_loose is active). PR: 223132 MFC after: 2 weeks Reported by: pirzyk Discussed with: jilles, eugen Reviewed by: christos, gshapiro (previous version), markj Approved by: christos (mentor), markj (mentor) Differential Revision: https://reviews.freebsd.org/D46862 Co-authored-by: Jim Pirzyk <pirzyk@FreeBSD.org> (cherry picked from commit d2e7bb630b83848a774d8213014a9e0747775019) libexec/rc/rc.d/sendmail | 6 ++++++ 1 file changed, 6 insertions(+)