Sped up find_byname
authorJamie Cameron <jcameron@webmin.com>
Sat, 6 Oct 2007 21:26:32 +0000 (21:26 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sat, 6 Oct 2007 21:26:32 +0000 (21:26 +0000)
CHANGELOG
web-lib-funcs.pl

index 8bce0af..17f862b 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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.
index c4984c8..3cfe314 100755 (executable)
@@ -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");