https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207811
Dave Baukus <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #13 from Dave Baukus <[email protected]> --- We hit this on 14-STABLE with www/tomcat101 and tracked it down. The bug is still present in main, stable/15, stable/14 and stable/13. Patch attached; it is a smaller change than attachment 257950. Cause ----- "service -e" and "service -R" do not run the rc.d scripts. For each script with a "^rcvar" line they eval its "^name=" and "^rcvar" lines: if grep -q ^rcvar $file; then eval `grep ^name= $file` eval `grep ^rcvar $file` ... checkyesno $rcvar 2>/dev/null && echo $file name and rcvar are never reset between scripts. If a script's "^name=" lines do not assign a literal name, they work on the previous script's name, and rcvar becomes "<previous script>_enable". That is comment 2's trace for isc-dhcpd ("name=${name##*/isc-}" gives "foreman_proxy"), and it is the tomcat case from comment 3: + grep '^name=' /usr/local/etc/rc.d/tomcat101 + eval 'name=${name##*/}' + name=sendmail + eval 'rcvar=${name}_enable' + rcvar=sendmail_enable So such a script is listed exactly when the script before it in rcorder order is enabled. Here tomcat101 (enabled) followed sendmail (sendmail_enable="NONE") and was left out; on another system tomcat9 followed an enabled service and was listed by luck. A "^rcvar" line that sets some other variable has the same problem with rcvar: libexec/rc/rc.d/cleartmp has 'rcvar1="clear_tmp_enable"', so it is listed whenever the previous script's rcvar is YES (gptboot_enable on one of our systems). This is probably why comment 11 could not reproduce with isc-dhcp44: since the port was added it carries a workaround for service(8), 'name="$file" ;', which takes the loop variable from service.sh. In the ports tree today, 20 rc scripts derive name from $0 or $name. Seven carry the 'name="$file" ;' workaround (isc-dhcpd, openvpn, openvpn-devel, knot3, ntpa, owntone, cardano_node). The rest do not, e.g. www/tomcat9, www/tomcat101, www/tomcat110, www/tomcat-devel, net/isc-dhcp44-server's isc-dhcrelay ('name=${name##*/isc-}'), games/ktx, misc/openhab, www/oauth2-proxy. (dns/register-dnsclient uses 'name=$(basename $0)', which inside service.sh gives "service"; no default in service.sh can fix that one.) How to reproduce ---------------- Install any port whose rc script derives name from $0 (www/tomcat9, www/tomcat101, ...), enable it, and look at the script just before it: # sysrc tomcat101_enable=YES # service tomcat101 enabled && echo enabled enabled # service -r | grep -B3 '/tomcat101$' # service -e | grep tomcat101 If the nearest script above tomcat101 with a "^rcvar" line is disabled, tomcat101 is missing from "service -e". Fix --- In the three loops (-R stop, -R start, -e), before the evals, set name to the script's path and clear rcvar: name=$file rcvar= - A script with a literal "name=" line overrides the default, as before. - A script that derives name from $0 now starts from the script's path, which is what $0 (or $_file, during boot) is when the script really runs, so "${name##*/}" gives "tomcat101" and "${name##*/isc-}" gives "dhcpd". This is the same default the ports' workaround supplies, so those scripts are unaffected. - No rc script in base or ports with a "^rcvar" line lacks a "name=" line, so the path default never reaches load_rc_config_var() as the final name. - cleartmp gets an empty rcvar and is no longer listed, which matches "service cleartmp enabled". The patch applies with "patch -p1" to main, stable/15 and stable/14, and to stable/13 with an offset. Testing: "service -e" was compared with "<script> enabled" for every script that has a "^rcvar" line. - 16.0-CURRENT (main-n291349) with isc-dhcp44-server and isc-dhcp44-relay installed, dhcpd and dhcrelay enabled. isc-dhcrelay follows isc-dhcpd6 (disabled). Unpatched, isc-dhcrelay was missing (rcvar=dhcpd6_enable) and cleartmp was listed although it is not enabled. Patched, both were right. isc-dhcpd, with the 'name="$file" ;' workaround, was listed with and without the patch. - 14.5-STABLE with tomcat101 enabled after sendmail (sendmail_enable="NONE"). Unpatched, tomcat101 was missing; patched, the list matched. "-R" was not run, since it restarts services; its hunks are the same change. Not covered by this patch: a script that sets its default inside the script, e.g. ports-mgmt/pkg's pkg_triggers (': ${pkg_triggers_enable:="YES"}', no rc.conf entry), is still left out of "service -e", with or without the patch. The grep loop cannot see such defaults; comment 7's sysctl, which has no rcvar at all, is similar. Only running the script, as attachment 257950 does, would catch them. About attachment 257950 ----------------------- Asking each script ("run_rc_script $file enabled") is correct for any script, but: - run_rc_script() unsets rcvar (and name) before sourcing the script, so the "rcvar=dummy" / "dummy=NO" default has no effect. That is likely what comment 5 ran into. A script that sets no rcvar ends up calling "checkyesno" with an empty name, which warns and fails. - It drops the "grep -q ^rcvar" filter, so -e and -R now source every rc.d script, including ones that are not rc.subr scripts. A local script that ignores "enabled" and exits 0 would be listed, and -R would run "stop" and "start" on it. -- You are receiving this mail because: You are on the CC list for the bug.
