Skip to contentSkip to conversation

posix/conformance/interfaces/sem_timedwait/2-1: Remove MAP_ANONYMOUS

PATCH In review Ma Xinjian via ltp 2 participants 2 messages Sep 19, 2024 – Sep 23, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 posix/conformance/interfaces/sem_timedwait/2-1: Remove MAP_ANONYMOUS

MAP_ANONYMOUS is not part of POSIX, so remove it from open posix testsuit. And use open_shm to get the file descriptor.

---
 .../interfaces/sem_timedwait/2-1.c            | 24 +++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c +22 -2
index 2eca8dff6..b1747f01d 100644
@@ -24,6 +24,7 @@
 #include "posixtest.h"
 
 #define TEST "2-1"
+#define SHM_NAME "posixtest_2-1"
 #define FUNCTION "sem_timedwait"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
@@ -31,8 +32,25 @@ int main(void)
 {
 	sem_t *mysemp;
 	struct timespec ts;
-	int pid;
-	mysemp = mmap(NULL, sizeof(*mysemp), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+	int fd, pid;
+
+	fd = shm_open(SHM_NAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+	if (fd == -1) {
+		perror("An error occurs when calling shm_open()");
+		return PTS_UNRESOLVED;
+	}
+
+	if (ftruncate(fd, sizeof(*mysemp)) == -1) {
+		perror("An error occurs when calling ftruncate()");
+		return PTS_UNRESOLVED;
+	}
+
+	if (shm_unlink(SHM_NAME) != 0) {
+		perror("An error occurs when calling shm_unlink()");
+		return PTS_UNRESOLVED;
+	}
+
+	mysemp = mmap(NULL, sizeof(*mysemp), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	if (mysemp == MAP_FAILED) {
 		perror(ERROR_PREFIX "mmap");
 		return PTS_UNRESOLVED;
@@ -82,5 +100,7 @@ int main(void)
 		}
 		return PTS_PASS;
 	}
+
+	close(fd);
 	return PTS_UNRESOLVED;
 }
Signature · 5 lines
2.42.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!
Pushed with two minor changes, thanks.

- POSIX requires that the SHM_NAME starts with /
- Made use of ERROR_PREFIX

Full diff:

testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c +4 -4
index b1747f01d..d9012cc5e 100644
@@ -24,7 +24,7 @@
 #include "posixtest.h"
 
 #define TEST "2-1"
-#define SHM_NAME "posixtest_2-1"
+#define SHM_NAME "/posixtest_2-1"
 #define FUNCTION "sem_timedwait"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
@@ -36,17 +36,17 @@ int main(void)
 
        fd = shm_open(SHM_NAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
        if (fd == -1) {
-               perror("An error occurs when calling shm_open()");
+               perror(ERROR_PREFIX "shm_open()");
                return PTS_UNRESOLVED;
        }
 
        if (ftruncate(fd, sizeof(*mysemp)) == -1) {
-               perror("An error occurs when calling ftruncate()");
+               perror(ERROR_PREFIX "ftruncate()");
                return PTS_UNRESOLVED;
        }
 
        if (shm_unlink(SHM_NAME) != 0) {
-               perror("An error occurs when calling shm_unlink()");
+               perror(ERROR_PREFIX "shm_unlink()");
                return PTS_UNRESOLVED;
        }
 
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp