summaryrefslogtreecommitdiffstats
path: root/etc/inc/util.inc
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2008-02-22 00:02:36 +0000
committerScott Ullrich <sullrich@pfsense.org>2008-02-22 00:02:36 +0000
commit53aca1fdc3f7683efd90472ed7be78f793eb78bb (patch)
tree0aeeed9004cdf9d79847eb5e5f5a55aca04a9a43 /etc/inc/util.inc
parentaf57ba5fc00c54235d321095e4d467d07a41adc3 (diff)
downloadpfsense-53aca1fdc3f7683efd90472ed7be78f793eb78bb.zip
pfsense-53aca1fdc3f7683efd90472ed7be78f793eb78bb.tar.gz
Add process name and id checking functions
Diffstat (limited to 'etc/inc/util.inc')
-rw-r--r--etc/inc/util.inc35
1 files changed, 30 insertions, 5 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index 33cb2b1..c003c7f 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -34,19 +34,44 @@ function killbypid($pidfile) {
sigkillbypid($pidfile, "TERM");
}
+function isvalidpid($pid) {
+ $running = `ps -p $pid | wc -l`;
+ if(intval($running) > 1)
+ return true;
+ else
+ return false;
+}
+
+function isvalidproc($proc) {
+ $running = `ps awux | grep $proc | grep -v grep | wc -l`;
+ if(intval($running) > 1)
+ return true;
+ else
+ return false;
+}
+
/* sigkill a process by pid file */
+/* return 1 for success and 0 for a failure */
function sigkillbypid($pidfile, $sig) {
- if (file_exists($pidfile)) {
+ if (is_file($pidfile)) {
$pid = trim(file_get_contents($pidfile));
- mwexec("/bin/kill -s $sig {$pid}");
- } else {
- mwexec("/bin/kill -s $sig {$pidfile}");
+ if(isvalidpid($pid))
+ return mwexec("/bin/kill -s $sig {$pid}");
}
+
+ return 0;
+}
+
+/* kill a process by name */
+function sigkillbyname($procname, $sig) {
+ if(isvalidproc($procname))
+ return mwexec("/usr/bin/killall -{$sig} " . escapeshellarg($procname));
}
/* kill a process by name */
function killbyname($procname) {
- mwexec("/usr/bin/killall " . escapeshellarg($procname));
+ if(isvalidproc($procname))
+ mwexec("/usr/bin/killall " . escapeshellarg($procname));
}
/* return the subnet address given a host address and a subnet bit count */
OpenPOWER on IntegriCloud