Bug 223132

Summary: /etc/rc.d/sendmail status returns the wrong exit code
Product: Base System Reporter: Jim Pirzyk <pirzyk>
Component: confAssignee: freebsd-rc (Nobody) <rc>
Status: Open ---    
Severity: Affects Some People CC: 0mp, eugen, gshapiro, jilles
Priority: --- Keywords: patch
Version: 11.1-RELEASEFlags: 0mp: maintainer-feedback-
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Proposed patch to return non zero error code.
none
Proposed patch to return non zero error code (2nd try) none

Description Jim Pirzyk freebsd_committer freebsd_triage 2017-10-20 17:05:32 UTC
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
Comment 1 Jim Pirzyk freebsd_committer freebsd_triage 2017-10-20 17:06:25 UTC
Created attachment 187329 [details]
Proposed patch to return non zero error code.
Comment 2 Jilles Tjoelker freebsd_committer freebsd_triage 2017-10-25 20:42:10 UTC
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.
Comment 3 Jim Pirzyk freebsd_committer freebsd_triage 2017-10-28 17:59:40 UTC
Created attachment 187544 [details]
Proposed patch to return non zero error code (2nd try)

Updated
Comment 4 Jim Pirzyk freebsd_committer freebsd_triage 2017-10-28 18:00:06 UTC
Updated the patch with the suggestions but changed the references to _ret to $_ret
Comment 5 Eugene Grosbein freebsd_committer freebsd_triage 2020-08-01 09:42:58 UTC
Dear maintainer, please take a look.