From a9488104aa6981056001a941103dfe09fd1cf871 Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 30 Jan 2013 15:13:18 -0500 Subject: Bring in the RCFILEPREFIX as constant fixes from HEAD, since otherwise rc.stop_packages was globbing in the wrong dir and executing the wrong scripts. Also seems to have fixed the "bad fd" error. --- etc/inc/pkg-utils.inc | 10 +++++----- etc/inc/service-utils.inc | 23 +++++++++++------------ etc/rc.start_packages | 4 ++-- 3 files changed, 18 insertions(+), 19 deletions(-) (limited to 'etc') diff --git a/etc/inc/pkg-utils.inc b/etc/inc/pkg-utils.inc index f8dee3c..b34092e 100644 --- a/etc/inc/pkg-utils.inc +++ b/etc/inc/pkg-utils.inc @@ -951,7 +951,7 @@ function delete_package($pkg) { } function delete_package_xml($pkg) { - global $g, $config, $static_output, $pkg_interface, $rcfileprefix; + global $g, $config, $static_output, $pkg_interface; conf_mount_rw(); @@ -1024,7 +1024,7 @@ function delete_package_xml($pkg) { if($g['booting'] != true) stop_service($service['name']); if($service['rcfile']) { - $prefix = $rcfileprefix; + $prefix = RCFILEPREFIX; if (!empty($service['prefix'])) $prefix = $service['prefix']; if (file_exists("{$prefix}{$service['rcfile']}")) @@ -1257,11 +1257,11 @@ function stop_packages() { require_once("pfsense-utils.inc"); require_once("service-utils.inc"); - global $config, $g, $rcfileprefix; + global $config, $g; log_error("Stopping all packages."); - $rcfiles = glob("{$rcfileprefix}*.sh"); + $rcfiles = glob(RCFILEPREFIX . "*.sh"); if (!$rcfiles) $rcfiles = array(); else { @@ -1274,7 +1274,7 @@ function stop_packages() { foreach($config['installedpackages']['package'] as $package) { echo " Stopping package {$package['name']}..."; stop_service($package['name']); - unset($rcfiles["{$rcfileprefix}{$package['name']}.sh"]); + unset($rcfiles[RCFILEPREFIX . "{$package['name']}.sh"]); echo "done.\n"; } } diff --git a/etc/inc/service-utils.inc b/etc/inc/service-utils.inc index 7811635..9e65c3f 100644 --- a/etc/inc/service-utils.inc +++ b/etc/inc/service-utils.inc @@ -38,15 +38,15 @@ pfSense_MODULE: utils */ -$rcfileprefix = "/usr/local/etc/rc.d/"; +define("RCFILEPREFIX", "/usr/local/etc/rc.d/"); function write_rcfile($params) { global $g; - global $rcfileprefix; - if (!file_exists("{$rcfileprefix}{$params['file']}") && !touch("{$rcfileprefix}{$params['file']}")) + $rcfile_fullname = RCFILEPREFIX . $params['file']; + if (!file_exists($rcfile_fullname) && !touch($rcfile_fullname)) return false; - if (!is_writable("{$rcfileprefix}{$params['file']}") || empty($params['start'])) + if (!is_writable($rcfile_fullname) || empty($params['start'])) return false; $towrite = "#!/bin/sh\n"; @@ -72,15 +72,14 @@ function write_rcfile($params) { /* begin rcfile logic */ $towrite .= "case \$1 in\n\tstart)\n\t\trc_start\n\t\t;;\n\tstop)\n\t\trc_stop\n\t\t;;\n\trestart)\n\t\trc_stop\n\t\trc_start\n\t\t;;\nesac\n\n"; - file_put_contents("{$rcfileprefix}{$params['file']}", $towrite); - @chmod("{$rcfileprefix}{$params['file']}", 0755); + file_put_contents($rcfile_fullname, $towrite); + @chmod("{$rcfile_fullname}", 0755); return; } function start_service($name) { global $config; - global $rcfileprefix; if (empty($name)) return; @@ -89,15 +88,16 @@ function start_service($name) { stop_service($name); sleep(2); - if(file_exists("{$rcfileprefix}{$name}.sh")) { - mwexec_bg("/bin/sh {$rcfileprefix}{$name}.sh start"); + $rcfile_fullname = RCFILEPREFIX . $name . '.sh'; + if(file_exists($rcfile_fullname)) { + mwexec_bg("/bin/sh {$rcfile_fullname} start"); return; } if($config['installedpackages']['service']) { foreach($config['installedpackages']['service'] as $service) { if(strtolower($service['name']) == strtolower($name)) { if($service['rcfile']) { - $prefix = $rcfileprefix; + $prefix = RCFILEPREFIX; if (!empty($service['prefix'])) { $prefix =& $service['prefix']; } @@ -115,7 +115,6 @@ function start_service($name) { function stop_service($name) { global $config; - global $rcfileprefix; if (empty($name)) return; @@ -124,7 +123,7 @@ function stop_service($name) { foreach($config['installedpackages']['service'] as $service) { if(strtolower($service['name']) == strtolower($name)) { if($service['rcfile']) { - $prefix = $rcfileprefix; + $prefix = RCFILEPREFIX; if(!empty($service['prefix'])) { $prefix =& $service['prefix']; } diff --git a/etc/rc.start_packages b/etc/rc.start_packages index 0a56526..7fc2bea 100755 --- a/etc/rc.start_packages +++ b/etc/rc.start_packages @@ -42,7 +42,7 @@ log_error("Restarting/Starting all packages."); conf_mount_rw(); -$rcfiles = glob("{$rcfileprefix}*.sh"); +$rcfiles = glob(RCFILEPREFIX . "*.sh"); if (!$rcfiles) $rcfiles = array(); else { @@ -56,7 +56,7 @@ if (is_array($config['installedpackages']['package'])) { echo " Starting package {$package['name']}..."; sync_package($package['name']); start_service($package['name']); - unset($rcfiles["{$rcfileprefix}{$package['name']}.sh"]); + unset($rcfiles[RCFILEPREFIX . "{$package['name']}.sh"]); echo "done.\n"; } } -- cgit v1.1