From 6f76920c94c2299240112b3ce9bd3238b9726989 Mon Sep 17 00:00:00 2001 From: thompsa Date: Fri, 12 Mar 2010 14:14:15 +1300 Subject: Use pgrep/pkill to save a bit of cpu. --- etc/inc/filter.inc | 2 +- etc/inc/interfaces.inc | 10 ++++------ etc/inc/pfsense-utils.inc | 4 ++-- etc/inc/rrd.inc | 2 +- etc/inc/services.inc | 2 +- etc/inc/shaper.inc | 4 ++-- 6 files changed, 11 insertions(+), 13 deletions(-) (limited to 'etc') diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index ac22ba6..c787e33 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -118,7 +118,7 @@ function filter_pflog_start() { } mute_kernel_msgs(); $pid = 0; - $pid = `ps awwwux | grep -v "grep" | grep "tcpdump -s 256 -v -l -n -e -ttt -i pflog0" | awk '{ print $2 }'`; + $pid = `/bin/pgrep -f "tcpdump -s 256 -v -l -n -e -ttt -i pflog0"`; if(!$pid) mwexec_bg("/usr/sbin/tcpdump -s 256 -v -l -n -e -ttt -i pflog0 | logger -t pf -p local0.info"); unmute_kernel_msgs(); diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index c31e259..7dd1ef6 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -985,7 +985,7 @@ function interface_ppp_configure($ifcfg,$edit=false) { } // Launch specified ppp instance if( (!$edit || $g['booting']) && file_exists("/dev/{$orig_dev}")){ - $running = `ps awux | grep ppp | grep -v grep | grep $orig_dev`; + $running = `/bin/pgrep -f "ppp .* $orig_dev"`; if(!$running) mwexec_bg("/usr/sbin/ppp -background {$orig_dev}"); } @@ -1750,18 +1750,16 @@ EOD; } function kill_hostapd($interface) { - return "/bin/ps awwuxx | grep hostapd | grep $interface | awk '{ print \$2 }' | xargs kill\n"; + return "/bin/pkill -f \"hostapd .*{$interface}\"\n"; } function kill_wpasupplicant($interface) { - return "/bin/ps awwuxx | grep wpa_supplicant | grep $interface | awk '{ print \$2 }' | xargs kill\n"; + return "/bin/pkill -f \"wpa_supplicant .*{$interface}\"\n"; } function find_dhclient_process($interface) { if($interface) { - $pid = `ps awwwux | grep dhclient | grep -v grep | grep {$interface} | awk '{ print \$2 }'`; - $pid = explode("\n", $pid); - $pid = $pid[0]; + $pid = `/bin/pgrep -xf "dhclient: {$interface}"`; } return $pid; } diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index bf7587c..60382d5 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -444,7 +444,7 @@ function get_carp_interface_status($carpinterface) { function get_pfsync_interface_status($pfsyncinterface) { $result = does_interface_exist($pfsyncinterface); if($result <> true) return; - $status = exec_command("/sbin/ifconfig {$pfsyncinterface} | /usr/bin/grep \"pfsync:\" | /usr/bin/cut -d\" \" -f5"); + $status = exec_command("/sbin/ifconfig {$pfsyncinterface} | /usr/bin/awk '/pfsync:/ {print \$5}'"); return $status; } @@ -1543,7 +1543,7 @@ function load_glxsb() { ******/ function isvm() { $virtualenvs = array("vmware", "parallels", "qemu", "bochs", "plex86"); - $bios_vendor = strtolower(`/bin/kenv | /usr/bin/grep "bios.vendor" | /usr/bin/cut -d"=" -f2`); + $bios_vendor = strtolower(`/bin/kenv | /usr/bin/awk -F= '/smbios.bios.vendor/ {print $2}'`); if(in_array($bios_vendor, $virtualenvs)) return true; else diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc index fa0500f..0bfc8f3 100644 --- a/etc/inc/rrd.inc +++ b/etc/inc/rrd.inc @@ -634,7 +634,7 @@ function enable_rrd_graphing() { } function kill_traffic_collector() { - mwexec("ps awwwux | grep '/[u]pdaterrd.sh' | awk '{print $2}' | xargs kill 2>&1"); + mwexec("/bin/pkill -f '/[u]pdaterrd.sh'"); } /* This xml 2 array function is courtesy of the php.net comment section on xml_parse. diff --git a/etc/inc/services.inc b/etc/inc/services.inc index cd2c7b6..2cb6988 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -40,7 +40,7 @@ function services_parse_dhcpd_hostnames() { global $config; - $ps = `ps awux | grep isc | grep -v grep | grep parse | awk '{ print $2 }'`; + $ps = `/bin/pgrep -f rc.parse-isc-dhcpd`; if($ps) exec("kill {$ps}"); // Launch if option enabled diff --git a/etc/inc/shaper.inc b/etc/inc/shaper.inc index a9475e9..ff6df14 100644 --- a/etc/inc/shaper.inc +++ b/etc/inc/shaper.inc @@ -3442,7 +3442,7 @@ class layer7 { } function delete_l7c() { - $l7pid = `/bin/ps -ax | /usr/bin/grep ipfw-classifyd | /usr/bin/grep ". $l7rules->GetRPort() . " | /usr/bin/grep -v grep | /usr/bin/awk '{ print $1 }'`; + $l7pid = `"/bin/pgrep -f 'ipfw-classifyd .* -p ". $l7rules->GetRPort() . "'"`; mwexec("/bin/kill {$l7pid}"); unset_l7_object_by_reference($this->GetRName()); cleanup_l7_from_rules($this->GetRName()); @@ -3608,7 +3608,7 @@ function layer7_start_l7daemon() { unset($l7pid); /* Only reread the configuration rather than restart to avoid loosing information. */ - exec("/bin/ps -ax | /usr/bin/grep ipfw-classifyd | /usr/bin/grep ". $l7rules->GetRPort() . " | /usr/bin/grep -v grep | /usr/bin/awk '{ print $1}'", $l7pid); + exec("/bin/pgrep -f 'ipfw-classifyd .* -p ". $l7rules->GetRPort() . "'", $l7pid); if (count($l7pid) > 0) { log_error("Sending HUP signal to {$l7pid[0]}"); mwexec("/bin/kill -HUP {$l7pid[0]}"); -- cgit v1.1