bsdperimeter/pfsense — pull request #208 by phildd (2012-08-07 10:37:18+00:00)
Title: Change rcfileprefix to a constant

See forum report http://forum.pfsense.org/index.php/topic,52280.0.html
The problem with $rcfileprefix defined in service-utils.inc is that if there is a require_once("service_utils.inc") inside a function then the variable $rcfileprefix is a local variable in that function, not a global. But if the require_once("service_utils.inc") is outside of a function then $rcfileprefix becomes global.
Declaring variables in the hope that they will be included in an appropriate place and become global can go wrong, like here, different calling sequences with different ways of including the files can end up with the variable being global or local (or both?), resulting in confusion about how to reference it.
This solution uses a constant. Constants are always global (like functions). So after a require_once("service-utils.inc") happens, the constant is available globally. No need to worry about local/global scope of a variable.
I have tried installing packages, stopping, starting services, rebooting, removing services. The code is working in all these various cases.
Shutdown now outputs:
----------------------------------
pfSense will reboot. This may take a few minutes, depending on your hardware.

Do you want to proceed [y|n]? y

pfSense is rebooting now.
Stopping package pfBlocker...done.
Stopping package squid3...done.
Stopping package darkstat...done.
Stopping /usr/local/etc/rc.d/proxy_monitor.sh...done.
Stopping /usr/local/etc/rc.d/squid.sh...done.
Syntax error: Bad fd number

*** FINAL System shutdown message from root@test02.homedomain ***

System going down IMMEDIATELY
----------------------------------