Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 02 Sep 2023 15:25:35 +0900
From:      KIRIYAMA Kazuhiko <kiri@truefc.org>
To:        current@freebsd.org
Cc:        freebsd-rc@freebsd.org
Subject:   Re: Announce /etc/rc.d/sendmail does not work in default should be made at use time.
Message-ID:  <202309020625.3826PaNR066435@kx.truefc.org>
In-Reply-To: <ZONJohmv60J_3ZUl@elch.exwg.net>
References:  <202308210638.37L6c9PJ074335@kx.truefc.org> <ZONJohmv60J_3ZUl@elch.exwg.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi, lists

On Mon, 21 Aug 2023 20:25:22 +0900,
Christoph Moench-Tegeder wrote:
> 
> ## KIRIYAMA Kazuhiko (kiri@truefc.org):
> 
> > But there are nothing pointers to be changed default MTA
> > changed to dma from sendmail ;-(
> 
> There is: UPDATING 20221205.

To aware default MTA is dma, I added
required_vars_defin_files variable used by
check_required_before function in /etc/rc.subr.

For example in this sendmail case, required_vars_defin_files
defines in /etc/rc.d/sendmail like this:

required_vars_defin_files="sendmail:/usr/libexec/sendmail/sendmail /etc/mail/mailer.conf"

This means "If sendmail -> /usr/libexec/sendmail/sendmail
does not define in /etc/mail/mailer.conf, warn this".

diff --git a/libexec/rc/rc.d/sendmail b/libexec/rc/rc.d/sendmail
index 68803a957952..f14da832d8f2 100755
--- a/libexec/rc/rc.d/sendmail
+++ b/libexec/rc/rc.d/sendmail
@@ -17,6 +17,7 @@ name="sendmail"
 desc="Electronic mail transport agent"
 rcvar="sendmail_enable"
 required_files="/etc/mail/${name}.cf"
+required_vars_defin_files="${name}:/usr/libexec/${name}/${name} /etc/mail/mailer.conf"
 start_precmd="sendmail_precmd"
 
 load_rc_config $name
diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr
index 17ca904ff1e7..1816df26ef67 100644
--- a/libexec/rc/rc.subr
+++ b/libexec/rc/rc.subr
@@ -2140,7 +2140,7 @@ find_system_scripts() {
 #
 check_required_before()
 {
-	local _f
+	local _f _vars
 
 	case "$1" in
 	start)
@@ -2170,6 +2170,60 @@ check_required_before()
 				fi
 			fi
 		done
+
+		IFS=$'\n'
+		for _f in $required_vars_defin_files; do
+			_vars=${_f% *}
+			_f=${_f##* }
+			if [ ! -f "${_f}" ]; then
+				warn "${_f} is not found."
+				return 1
+			fi
+			_vars=$(awk -v vars="$_vars" -v file=$_f '
+				BEGIN {
+					n = split(vars, v, /[[:space:]]+/)
+					for (i = 1; i <= n; i++) {
+						split(v[i], w, /:/)
+						var[w[1]] = w[2]
+					}
+					s = ""
+					found = 0
+				}
+				{
+					for (i in var) {
+						if (match($0, "^" i "[[:space:]]+")) {
+							t = substr($0, RSTART + RLENGTH)
+							if (var[i] == t) {
+								delete var[i]
+								n--
+								break
+							}
+						}
+					}
+					if (n <= 0) { 
+						found = 1
+						exit
+					}
+				}
+				END {
+					if (! found) {
+						for (i in var) { s = s ? s " " i "->" var[i] : i "->" var[i] }
+						if (n == 1) {
+							print "\"" s "\" is"
+						} else {
+							print "\"" s "\" are"
+						}
+					}
+					exit ! found
+				}' $_f)
+			if [ $? -ne 0 ]; then
+				warn "${_vars} not defined in ${_f}."
+				if [ -z "$rc_force" ]; then
+					return 1
+				fi
+			fi
+		done
+		unset IFS
 		;;
 	esac

Regards

---
Kazuhiko Kiriyama



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202309020625.3826PaNR066435>