Bug 145399 - [patch] rc.d scripts are unable to start/stop programs whose name contains '-'
Summary: [patch] rc.d scripts are unable to start/stop programs whose name contains '-'
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: 8.0-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-05 05:20 UTC by Daniel V. Klein
Modified: 2018-01-03 05:16 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel V. Klein 2010-04-05 05:20:02 UTC
	I wanted to write an rc.d script for Cfengine3 that would start
	"cf-execd" (and stop a few more programs), and attempted to use the
	generic start-stop functions (what I tried to do was call my script
	cfengine3.sh, and in that script define command="/usr/sbin/cf-execd").

	However, there is a "feature" in /etc/rc.subr which overwrites the
	command name if the command has a '-' in it (the actual bug is in the
	eval which creates the _override_command variable).

	I found a workaround wherein I created a cfengine3_start() that
	starts ${_saved_command} and another cfengine3_stop() function to
	stop the various components that are run by the main daemon (I would
	have needed this anyway, but the bug was on start).  This was no big
	deal, but it was "interesting" that I can't reference the command
	"cf-execd" using the standard "start" and "stop" functions.

Fix: 

#!/bin/sh
    #
    # REQUIRE: networking syslog
    # PROVIDE: cfengine3
    #
    # Add the following line to /etc/rc.conf to enable cfengine:
    #
    # cfengine3_enable="YES"
    #

    . /etc/rc.subr

    name="cfengine3"
    components="cf-execd cf-agent cf-serverd cf-monitord cf-report cf-know"
    command="/usr/sbin/cf-execd"
    rcvar=`set_rcvar`

    # There is a bug in /etc/rc.subr which destroys the command name if the
    # command has a '-' in it (the bug is in the eval which creates the
    # _override_command variable.  So we write our own kludgy cfengine3_start
    _saved_command="/var/cfengine/bin/cf-execd"

    stop_cmd="cfengine3_stop"
    start_cmd="cfengine3_start"

    cfengine3_start()
    {
	    if [ ! -x ${_saved_command} ]; then
		    warn "cannot run $_saved_command"
		    return 1
	    fi
	    $_saved_command
    }

    cfengine3_stop()
    {
	    echo "Stopping cfengine components: ${components}"
	    pkill ${components}
    }

    load_rc_config "$name"
    cfengine3_enable=${cfengine3_enable-"NO"}

    run_rc_command "$1"
How-To-Repeat: 
    #!/bin/sh
    #
    # REQUIRE: networking syslog
    # PROVIDE: cfengine3
    #
    # Add the following line to /etc/rc.conf to enable cfengine:
    #
    # cfengine3_enable="YES"
    #

    . /etc/rc.subr

    name="cfengine3"
    command="/usr/sbin/cf-execd"
    rcvar=`set_rcvar`

    load_rc_config "$name"
    cfengine3_enable=${cfengine3_enable-"NO"}

    run_rc_command "$1"
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2010-04-05 05:40:26 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-rc

Over to maintainer(s).
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:57 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped