[PATCH rt-tests] pi_stress: Check the status of sched_getaffinity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Check the status of sched_getaffinity and exit upon error.

CPU_ISSET only checks whether a cpu is in a mask, and not whether the
mask is valid. Checking the status ensures we aren't working with garbage
values.

This also removes the warning from gcc about the status variable being unused
as reported by Darren Hart.

Reported-by: Darren Hart <dvhart@xxxxxxxxxxxxxxx>
Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>
---
 src/pi_tests/pi_stress.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c
index 0940567..e273d62 100644
--- a/src/pi_tests/pi_stress.c
+++ b/src/pi_tests/pi_stress.c
@@ -597,9 +597,17 @@ void *reporter(void *arg)
 int verify_cpu(int cpu)
 {
 	int status;
+	int err;
 	cpu_set_t mask;
 
+	CPU_ZERO(&mask);
+
 	status = sched_getaffinity(0, sizeof(cpu_set_t), &mask);
+	if (status == -1) {
+		err = errno;
+		fprintf(stderr, "sched_getaffinity %s\n", strerror(err));
+		exit(-1);
+	}
 
 	if (CPU_ISSET(cpu, &mask))
 		return SUCCESS;
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux