Skip to contentSkip to conversation

selftests/memfd: Rename local union semun to avoid bionic clash

PATCH New Wake Liu 1 participant 1 message Nov 5

Subsystems (2)
lore
Share & tools
lore

Wake Liu

author
#0 lore raw

PATCH 1/1 selftests/memfd: Rename local union semun to avoid bionic clash

Commit b24335521de9 ("selftests/memfd: use IPC semaphore instead of SIGSTOP/SIGCONT") added a local definition of union semun, since glibc and musl expect the caller to define it before calling semctl(). Bionic, however, already defines union semun in <sys/sem.h>, so memfd_test no longer builds against it:

memfd_test.c:45:7: error: redefinition of 'semun'

Rename the local union to memfd_semun. Its layout is unchanged, so it can still be passed as the variadic semctl() argument with any C library.

Fixes b24335521de9 ("selftests/memfd: use IPC semaphore instead of SIGSTOP/SIGCONT")
---
 tools/testing/selftests/memfd/memfd_test.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/memfd/memfd_test.c +8 -2
index cdab3a837624..188cb7c32db1 100644
@@ -42,7 +42,13 @@
 		    F_SEAL_EXEC)
 
 #define MFD_NOEXEC_SEAL	0x0008U
-union semun {
+
+/*
+ * glibc and musl leave union semun for the caller to define, but bionic
+ * already provides it in <sys/sem.h>. Use a private name so the test
+ * builds against all of them.
+ */
+union memfd_semun {
 	int val;
 	struct semid_ds *buf;
 	unsigned short int *array;
@@ -1387,7 +1393,7 @@ static void test_sysctl_sysctl2_failset(void)
 static int sysctl_nested_child(void *arg)
 {
 	int pid, sem;
-	union semun semun;
+	union memfd_semun semun;
 	struct sembuf sembuf;
 
 	printf("%s nested sysctl 0\n", memfd_str);

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.56.0.398.g882cbad275-goog