From f49e484e015c94a92b5f30a4ea3b11060a09797d Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 20 Nov 2008 15:33:32 +0000 Subject: Modified processinfo to fix problem with detecting pid file. It now also checks for matching proc directory. git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1604 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lib/processinfo.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/processinfo.lua b/lib/processinfo.lua index 2a7392e..f071ed0 100644 --- a/lib/processinfo.lua +++ b/lib/processinfo.lua @@ -184,7 +184,19 @@ local function has_pidfile(name) local file = f:read("*a") f:close() if file and string.find(file, "%w") then - pid = fs.read_file(string.match(file, "^%s*(.*%S)")) + -- check to see if there's a matching proc directory and that it was created slightly after the pid file + -- this allows us to find init scripts with differing process names and avoids the problem with + -- proc numbers wrapping + file = string.match(file, "^%s*(.*%S)") + local tmp = string.match(fs.read_file(file), "%d+") + if tmp then + local dir = "/proc/" .. tmp + filetime = posix.stat(file, "ctime") + dirtime = posix.stat(dir, "ctime") + if dirtime and (tonumber(dirtime) - tonumber(filetime) < 100) then + pid = tmp + end + end end return pid end -- cgit v1.2.3