Bug 194347 - Return an error when rc service is not enabled
Summary: Return an error when rc service is not enabled
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: 10.0-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: Fernando Apesteguía
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-14 11:14 UTC by roy
Modified: 2023-01-24 14:32 UTC (History)
1 user (show)

See Also:


Attachments
Return an error if service is not enabled. (497 bytes, patch)
2014-10-14 11:14 UTC, roy
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description roy 2014-10-14 11:14:22 UTC
Created attachment 148290 [details]
Return an error if service is not enabled.

Currently the rc service returns success when testing any function and it's not enabled.

# in rc.conf
ntpd_enable=NO  # or unset

# in a sample script
if /etc/rc.d/ntpd status >/dev/null 2>&1; then
   # ntpd is running but we changed it's config, lets restart it for the new one
   /etc/rc.d/ntpd restart
fi
Comment 1 Fernando Apesteguía freebsd_committer freebsd_triage 2023-01-24 14:32:45 UTC
rc is returning 0 because rc is not failing. This is one of the possible outputs considered by the rc script and it is not an error.

Compare that with this piece of code in which a force start is issued but somehow (the script doesn't know why), it fails:

        if ! /etc/rc.d/${_depend} forcestart; then 
                warn "Unable to force ${_depend}. It may already be running."
                return 1
        fi