diff --git a/src/plugins/task/affinity/affinity.c b/src/plugins/task/affinity/affinity.c
index 2efcd9440f0f7be1d395e275ba48e7de4d625f80..513f558f9568a3c807be47a010077677ede50529 100644
--- a/src/plugins/task/affinity/affinity.c
+++ b/src/plugins/task/affinity/affinity.c
@@ -165,7 +165,7 @@ int slurm_setaffinity(pid_t pid, size_t size, const cpu_set_t *mask)
 	int rval;
 	char mstr[1 + CPU_SETSIZE / 4];
 
-#ifdef HAVE_SCHED_SETAFFINITY
+#ifdef SCHED_GETAFFINITY_THREE_ARGS
 	rval = sched_setaffinity(pid, size, mask);
 #else
 	rval = sched_setaffinity(pid, mask);
diff --git a/src/plugins/task/affinity/affinity.h b/src/plugins/task/affinity/affinity.h
index bef29c42616dc1a13621c1a914cd961260be9213..efa28bded5908443907cf1995260239f6d126744 100644
--- a/src/plugins/task/affinity/affinity.h
+++ b/src/plugins/task/affinity/affinity.h
@@ -44,9 +44,9 @@
 #include <string.h>
 #include <sys/utsname.h>
 
+#define _GNU_SOURCE
 #define __USE_GNU
 #include <sched.h> /* SMB */
-#undef __USE_GNU
 
 #if HAVE_STDLIB_H
 #  include <stdlib.h>
diff --git a/testsuite/expect/Makefile.am b/testsuite/expect/Makefile.am
index 7801039549ec2e09341a6fde9a5e8884cd9a3a3d..9652334dfedfe6af7e88dbd1edad8190d8678823 100644
--- a/testsuite/expect/Makefile.am
+++ b/testsuite/expect/Makefile.am
@@ -79,6 +79,8 @@ EXTRA_DIST = \
 	test1.87			\
 	test1.88			\
 	test1.88.prog.c			\
+	test1.89			\
+	test1.89.prog.c			\
 	test2.1				\
 	test2.2				\
 	test2.3				\
diff --git a/testsuite/expect/test1.89.prog.c b/testsuite/expect/test1.89.prog.c
index 20e4fac18c67721e020715892f0480ee76280dda..563a6ec5c3644e776eabd1a69ea314ddab361645 100644
--- a/testsuite/expect/test1.89.prog.c
+++ b/testsuite/expect/test1.89.prog.c
@@ -1,4 +1,5 @@
 #define _GNU_SOURCE
+#define __USE_GNU
 #include <errno.h>
 #include <sched.h>
 #include <stdio.h>