From 433d137fe0c98416d2bfec56fd72ae60703c3145 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sat, 6 Oct 2007 21:26:32 +0000 Subject: [PATCH] Sped up find_byname --- CHANGELOG | 1 + web-lib-funcs.pl | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 8bce0af18..17f862b70 100644 --- 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. diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index c4984c8fa..3cfe3146d 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -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");