Bug 473287 - killproc doesn't kill all processes found in pidfile
Summary: killproc doesn't kill all processes found in pidfile
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: initscripts
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-11-27 14:25 UTC by Ruben Kerkhof
Modified: 2014-03-17 03:16 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-12-01 19:04:06 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
patch, avoiding bugzilla pasting fun (616 bytes, text/plain)
2008-12-01 17:13 UTC, Bill Nottingham
no flags Details

Description Ruben Kerkhof 2008-11-27 14:25:56 UTC
Description of problem:

Some programs (HAProxy for example when running with nprocs=2) write multiple pids to the same pidfile, each on its own line. Killproc only reads the first line of a pid file, so it will only kill the first process found.

Comment 1 Bill Nottingham 2008-12-01 17:07:10 UTC
Hm, this would be a behavior change - this may have unintended consequences.

diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
index acef332..bb58048 100644
--- a/rc.d/init.d/functions
+++ b/rc.d/init.d/functions
@@ -152,10 +152,15 @@ __pids_var_run() {
 	pid=
 	if [ -f "$pid_file" ] ; then
 	        local line p
-		read line < "$pid_file"
-		for p in $line ; do
-			[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
-		done
+
+		while : ; do
+			read line
+			[ -z "$line" ] && break
+			for p in $line ; do
+				[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
+			done
+		done < "$pid_file"
+
 	        if [ -n "$pid" ]; then
 	                return 0
 	        fi

Does this fix it for you?

Comment 2 Bill Nottingham 2008-12-01 17:13:54 UTC
Created attachment 325267 [details]
patch, avoiding bugzilla pasting fun

Comment 3 Ruben Kerkhof 2008-12-01 18:48:36 UTC
This fixes it for me, thanks. I'm not sure what other programs will break though...

Comment 4 Bill Nottingham 2008-12-01 19:04:06 UTC
http://git.fedorahosted.org/git/?p=initscripts.git;a=commitdiff;h=d8d067e3e2c6492fa16d6290e7b5fbb9a9e0b745

Will be in rawhide with the next build. Due to the behavior change, it's very unlikely to be backported to a release.


Note You need to log in before you can comment on or make changes to this bug.