Skip to content

Commit

Permalink
rc.d/sendmail: Return non-zero if the daemon fails to start or is not…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
0mp and Jim Pirzyk committed Oct 21, 2024
1 parent 0e3a211 commit d2e7bb6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libexec/rc/rc.d/sendmail
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ sendmail_precmd()
}

run_rc_command "$1"
_ret=$?

required_files=

Expand All @@ -214,13 +215,15 @@ if checkyesno sendmail_submit_enable; then
rcvar="sendmail_submit_enable"
_rc_restart_done=false
run_rc_command "$1"
_ret=$(( _ret > $? ? _ret : $? ))
fi

if checkyesno sendmail_outbound_enable; then
name="sendmail_outbound"
rcvar="sendmail_outbound_enable"
_rc_restart_done=false
run_rc_command "$1"
_ret=$(( _ret > $? ? _ret : $? ))
fi

name="sendmail_msp_queue"
Expand All @@ -229,3 +232,6 @@ pidfile="${sendmail_msp_queue_pidfile:-/var/spool/clientmqueue/sm-client.pid}"
required_files="/etc/mail/submit.cf"
_rc_restart_done=false
run_rc_command "$1"
_ret=$(( _ret > $? ? _ret : $? ))

(exit "$_ret")

0 comments on commit d2e7bb6

Please sign in to comment.