Bug 258089

Summary: net/mosquitto: ignores mosquitto_pidfile set in /etc/rc.conf
Product: Ports & Packages Reporter: Dan Langille <dvl>
Component: Individual Port(s)Assignee: Craig Leres <leres>
Status: Closed FIXED    
Severity: Affects Only Me CC: joe, leres
Priority: --- Flags: joe: maintainer-feedback+
Version: Latest   
Hardware: Any   
OS: Any   
Description Flags
fixes assignment of /etc/rc.conf variables joe: maintainer-approval+

Description Dan Langille freebsd_committer 2021-08-27 15:12:47 UTC
For demonstration, I added these lines to a fresh install of mosquitto-2.0.10_1 on FreeBSD 13.0-RELEASE-p4.

They are placed just before the 'run_rc_command' line in /usr/local/etc/rc.d/mosquitto :

echo mosquitto_enable=$mosquitto_enable
echo mosquitto_config=$mosquitto_config
echo mosquitto_user=$mosquitto_user
echo mosquitto_pidfile=$mosquitto_pidfile
echo pidfile=$pidfile

I am running with this configuration:

$ grep mosq /etc/rc.conf

$ sudo service mosquitto start
Starting mosquitto.

NOTE how pidfile has the wrong value but mosquitto_pidfile does.

Both files are created, but only one is correct.

$ sudo ls -l /var/run/mosquitto/mosquitto.pid /var/run/mosquitto.pid
-rw-r--r--  1 mosquitto  wheel      0 Aug 27 15:10 /var/run/mosquitto.pid
-rw-r--r--  1 mosquitto  mosquitto  5 Aug 27 15:10 /var/run/mosquitto/mosquitto.pid
Clearly, the value for mosquitto_pidfile is not being picked up from /etc/rc.conf

I'm submitting this now and may be able to work on finding a solution soon.
Comment 1 Dan Langille freebsd_committer 2021-08-27 16:48:20 UTC
The fix is to move "load_rc_config $name" before the variable assignments.

Credit to jrm via IRC and eborisch via Twitter for this.

[dan@gelt:/usr/local/etc/rc.d] $ diff -ruN mosquitto mosquitto.mine
--- mosquitto	2021-08-22 04:34:48.000000000 +0000
+++ mosquitto.mine	2021-08-27 16:45:52.963755000 +0000
@@ -19,6 +19,7 @@
+load_rc_config $name
@@ -40,5 +41,10 @@
 	install -o ${mosquitto_user} -m 644 /dev/null ${pidfile}
-load_rc_config $name
+echo mosquitto_enable=$mosquitto_enable
+echo mosquitto_config=$mosquitto_config
+echo mosquitto_user=$mosquitto_user
+echo mosquitto_pidfile=$mosquitto_pidfile
+echo pidfile=$pidfile
 run_rc_command "$1"
[dan@gelt:/usr/local/etc/rc.d] $
Comment 2 Dan Langille freebsd_committer 2021-08-27 18:20:54 UTC
Created attachment 227488 [details]
fixes assignment of /etc/rc.conf variables

Credit to jrm for this script.  Tested on my hosts.

NOTE: when setting mosquitto_pidfile in /etc/rc.conf, you must also set pid_file (note the underscore) to the same value within the mosquitto configuration file.
Comment 3 Dan Langille freebsd_committer 2021-08-27 21:43:16 UTC
Joe: I take it we have maintainer approval to proceed? Just to be explicit.  Thank you.
Comment 4 joe 2021-08-27 21:53:35 UTC
Yes, the changes seem very reasonable. -Joe
Comment 5 commit-hook freebsd_committer 2021-08-27 21:56:24 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=921e007cc543520bac1adf9e96de9483cb3e725e

commit 921e007cc543520bac1adf9e96de9483cb3e725e
Author:     Dan Langille <dvl@FreeBSD.org>
AuthorDate: 2021-08-27 21:35:40 +0000
Commit:     Dan Langille <dvl@FreeBSD.org>
CommitDate: 2021-08-27 21:55:16 +0000

    net/mosquitto: update rc.d script to fix mosquitto_pidfile override

    The default variables were being set before load_rc_config was invoked.

    jrm@FreeBSD.org did most of this work and all credit goes to him.
    I only found the problem. He helped tremendously.

    PR:             258089
    Reported by:    dvl
    Approved by:    joe@thrallingpenguin.com (maintainer)
    Obtained from:  jrm

 net/mosquitto/Makefile           |  2 +-
 net/mosquitto/files/mosquitto.in | 17 +++++------------
 2 files changed, 6 insertions(+), 13 deletions(-)
Comment 6 Dan Langille freebsd_committer 2021-08-27 22:00:23 UTC
Thank you both.