Sped up find_byname

This commit is contained in:
Jamie Cameron
2007-10-06 21:26:32 +00:00
parent 170ffc27be
commit 433d137fe0
2 changed files with 18 additions and 0 deletions

View File

@@ -75,3 +75,4 @@ Requests to the /unauthenticated URL can never execute CGI programs, to provide
Fixed XSS bugs in pam_login.cgi.
---- Changes since 1.370 ----
Hid the Jabber and Security Sentries modules by default, as the underlying software is no longer supported.
On Linux systems, sped up the function for finding processes so that it no longer has to launch 'ps' - instead, it reads /proc directly.

View File

@@ -924,6 +924,23 @@ else { return 0; }
# Finds a process by name, and returns a list of matching PIDs
sub find_byname
{
if ($gconfig{'os_type'} =~ /-linux$/ && -r "/proc/$$/cmdline") {
# Linux with /proc filesystem .. use cmdline files, as this is
# faster than forking
local @pids;
opendir(PROCDIR, "/proc");
foreach my $f (readdir(PROCDIR)) {
if ($f eq int($f)) {
local $line = &read_file_contents("/proc/$f/cmdline");
if ($line =~ /$_[0]/) {
push(@pids, $f);
}
}
}
closedir(PROCDIR);
return @pids;
}
if (&foreign_check("proc")) {
# Call the proc module
&foreign_require("proc", "proc-lib.pl");