Patchwork [U-Boot,v2] MAKEALL: fix kill_children for BSD hosts

login
register
mail settings
Submitter Andreas Bießmann
Date Feb. 8, 2013, 8:35 a.m.
Message ID <1360312557-25604-1-git-send-email-andreas.devel@googlemail.com>
Download mbox | patch
Permalink /patch/219067/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Andreas Bießmann - Feb. 8, 2013, 8:35 a.m.
ps on BSD hosts (like OS X) do not provide the --no-headers switch nor
understand the AIX format descriptions. Unfortunately there seems no solution to
get the PIDs of children in a platfrom independent manner.
Therefore detect the OS and decide upon that which way to go.

This patch makes the MAKEALL script cleanly stoppable on bare OS X when using
the parallel builds of targets.

Additionally this patch removes double call to grep by a single call to sed for
GNU style child PID detection.

Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
---
 MAKEALL |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
Joe Hershberger - Feb. 8, 2013, 8:52 p.m.
On Fri, Feb 8, 2013 at 2:35 AM, Andreas Bießmann
<andreas.devel@googlemail.com> wrote:
> ps on BSD hosts (like OS X) do not provide the --no-headers switch nor
> understand the AIX format descriptions. Unfortunately there seems no solution to
> get the PIDs of children in a platfrom independent manner.
> Therefore detect the OS and decide upon that which way to go.
>
> This patch makes the MAKEALL script cleanly stoppable on bare OS X when using
> the parallel builds of targets.
>
> Additionally this patch removes double call to grep by a single call to sed for
> GNU style child PID detection.
>
> Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> ---

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

Patch

diff --git a/MAKEALL b/MAKEALL
index 5b06c54..1dffa1a 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -784,8 +784,20 @@  build_targets() {
 #-----------------------------------------------------------------------
 
 kill_children() {
-	local pgid=`ps -p $$ --no-headers -o "%r" | tr -d ' '`
-	local children=`pgrep -g $pgid | grep -v $$ | grep -v $pgid`
+	local OS=$(uname -s)
+	local children=""
+	case "${OS}" in
+		"Darwin")
+			# Mac OS X is known to have BSD style ps
+			local pgid=$(ps -p $$ -o pgid | sed -e "/PGID/d")
+			children=$(ps -g $pgid -o pid | sed -e "/PID\|$$\|$pgid/d")
+			;;
+		*)
+			# everything else tries the GNU style
+			local pgid=$(ps -p $$ --no-headers -o "%r" | tr -d ' ')
+			children=$(pgrep -g $pgid | sed -e "/$$\|$pgid/d")
+			;;
+	esac
 
 	kill $children 2> /dev/null
 	wait $children 2> /dev/null