Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Jun 2014 14:36:08 +0000 (UTC)
From:      Christian Weisgerber <naddy@mips.inka.de>
To:        freebsd-ports@freebsd.org
Subject:   Re: [net/openntpd] pidfile support
Message-ID:  <slrnlop2uo.2m90.naddy@lorvorc.mips.inka.de>
References:  <CAN3T69vFEGXmwWjwp69oJEOPx3cLKaDyxR379xGvnzaZ-_ExtA@mail.gmail.com> <slrnlon6qq.20b9.naddy@lorvorc.mips.inka.de> <CAN3T69v0dkAQBXOZwgQjracPykT_xtMG6w6U%2B%2B_D1_twDtndjw@mail.gmail.com> <CAN3T69vgA53ofNGpRkWR7oPuyfgyhX8G1%2BHtvGhLCeEjSRuJTQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2014-06-02, Tomek WaƂaszek <tmwalaszek@gmail.com> wrote:

>> Yes, the fix will work but it will be not a generic solution.
>> Maybe for those types of programs we should have a generic solution? For
>> example add a variable leader="YES", and if this variable will be set then
>> the rc script will kill only the 'master' process?
>> I wrote a simple patch for the rc.subr, I dont know whether this solution
>> is good but anyway it works for me :P
>> Patch is in the attachment :)

(Here's Tomek's patch that didn't make it to the mailing list.)

----------
diff --git a/rc.subr b/rc.subr
index 850bc03..668ea14 100644
--- a/rc.subr
+++ b/rc.subr
@@ -252,7 +252,7 @@ check_pidfile()
 		debug "pid file ($_pidfile): no pid in file."
 		return
 	fi
-	_find_processes $_procname $_interpreter '-p '"$_pid" ${_leader:-"NO"}
+	_find_processes $_procname ${_interpreter:-.} '-p '"$_pid"
 }
 
 #
@@ -265,12 +265,10 @@ check_process()
 {
 	_procname=$1
 	_interpreter=$2
-	_leader=$3
-
 	if [ -z "$_procname" ]; then
-		err 3 'USAGE: check_process procname [interpreter leader]'
+		err 3 'USAGE: check_process procname [interpreter]'
 	fi
-	_find_processes $_procname $_interpreter '-ax' $_leader
+	_find_processes $_procname ${_interpreter:-.} '-ax'
 }
 
 #
@@ -295,13 +293,12 @@ check_process()
 #
 _find_processes()
 {
-	if [ $# -ne 4 ]; then
+	if [ $# -ne 3 ]; then
 		err 3 'USAGE: _find_processes procname interpreter psargs'
 	fi
 	_procname=$1
 	_interpreter=$2
 	_psargs=$3
-	_leader=$4
 
 	_pref=
 	if [ $_interpreter != "." ]; then	# an interpreted script
@@ -341,22 +338,14 @@ _find_processes()
 		_fp_match='case "$_arg0" in
 		    $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})"|"[${_procnamebn}]")'
 	fi
-	
+
 	_proccheck="\
-		$PS 2>/dev/null -o pid= -o pgid= -o jid= -o command= $_psargs"' |
-		while read _npid _pgid _jid '"$_fp_args"'; do
+		$PS 2>/dev/null -o pid= -o jid= -o command= $_psargs"' |
+		while read _npid _jid '"$_fp_args"'; do
 			'"$_fp_match"'
-				if checkyesno _leader;
-				then 
-					if [ "$JID" -eq "$_jid" -a "$_npid" -eq "$_pgid"  ]; then
-						echo -n "$_pref$_npid";
-						_pref=" ";
-					fi
-				else
-					if [ "$JID" -eq "$_jid" ]; then
-						echo -n "$_pref$_npid";
-						_pref=" ";
-					fi
+				if [ "$JID" -eq "$_jid" ];
+				then echo -n "$_pref$_npid";
+				_pref=" ";
 				fi
 				;;
 			esac
@@ -670,15 +659,13 @@ run_rc_command()
 	rc_pid=
 	_pidcmd=
 	_procname=${procname:-${command}}
-	command_interpreter=${command_interpreter:-.}
-	_leader=${leader:-"NO"}
 
 					# setup pid check command
 	if [ -n "$_procname" ]; then
 		if [ -n "$pidfile" ]; then
 			_pidcmd='rc_pid=$(check_pidfile '"$pidfile $_procname $command_interpreter"')'
 		else
-			_pidcmd='rc_pid=$(check_process '"$_procname $command_interpreter $_leader"')'
+			_pidcmd='rc_pid=$(check_process '"$_procname $command_interpreter"')'
 		fi
 		if [ -n "$_pidcmd" ]; then
 			_keywords="${_keywords} status poll"

-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?slrnlop2uo.2m90.naddy>