DORMANTno replies

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

From: John Kacur <jkacur@redhat.com>
Date: 2012-03-21 22:18:52
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help