Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Oct 2012 03:43:02 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r241859 - head/sys/kern
Message-ID:  <201210220343.q9M3h2Ic024439@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Mon Oct 22 03:43:02 2012
New Revision: 241859
URL: http://svn.freebsd.org/changeset/base/241859

Log:
  Correct the killpg(2) return values:
  
  Return EPERM if processes were found but they
  were unable to be signaled.
  
  Return the first error from p_cansignal if no signal was successful.
  
  Reviewed by:	jilles
  Approved by:	cperciva
  MFC after:	1 week

Modified:
  head/sys/kern/kern_sig.c

Modified: head/sys/kern/kern_sig.c
==============================================================================
--- head/sys/kern/kern_sig.c	Mon Oct 22 03:41:24 2012	(r241858)
+++ head/sys/kern/kern_sig.c	Mon Oct 22 03:43:02 2012	(r241859)
@@ -1599,8 +1599,10 @@ killpg1(struct thread *td, int sig, int 
 {
 	struct proc *p;
 	struct pgrp *pgrp;
-	int nfound = 0;
+	int err;
+	int ret;
 
+	ret = ESRCH;
 	if (all) {
 		/*
 		 * broadcast
@@ -1613,11 +1615,14 @@ killpg1(struct thread *td, int sig, int 
 				PROC_UNLOCK(p);
 				continue;
 			}
-			if (p_cansignal(td, p, sig) == 0) {
-				nfound++;
+			err = p_cansignal(td, p, sig);
+			if (err == 0) {
 				if (sig)
 					pksignal(p, sig, ksi);
+				ret = err;
 			}
+			else if (ret == ESRCH)
+				ret = err;
 			PROC_UNLOCK(p);
 		}
 		sx_sunlock(&allproc_lock);
@@ -1644,16 +1649,19 @@ killpg1(struct thread *td, int sig, int 
 				PROC_UNLOCK(p);
 				continue;
 			}
-			if (p_cansignal(td, p, sig) == 0) {
-				nfound++;
+			err = p_cansignal(td, p, sig);
+			if (err == 0) {
 				if (sig)
 					pksignal(p, sig, ksi);
+				ret = err;
 			}
+			else if (ret == ESRCH)
+				ret = err;
 			PROC_UNLOCK(p);
 		}
 		PGRP_UNLOCK(pgrp);
 	}
-	return (nfound ? 0 : ESRCH);
+	return (ret);
 }
 
 #ifndef _SYS_SYSPROTO_H_



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210220343.q9M3h2Ic024439>