Skip to content

Commit

Permalink
posix/conformance/interfaces/sem_timedwait/2-1: Remove MAP_ANONYMOUS
Browse files Browse the repository at this point in the history
MAP_ANONYMOUS is not part of POSIX, so remove it from open posix testsuit.
And use open_shm to get the file descriptor.

Signed-off-by: Ma Xinjian <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
  • Loading branch information
MaXinjian authored and metan-ucw committed Sep 27, 2024
1 parent c3f507a commit 3d77539
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,33 @@
#include "posixtest.h"

#define TEST "2-1"
#define SHM_NAME "/posixtest_2-1"
#define FUNCTION "sem_timedwait"
#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "

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(ERROR_PREFIX "shm_open()");
return PTS_UNRESOLVED;
}

if (ftruncate(fd, sizeof(*mysemp)) == -1) {
perror(ERROR_PREFIX "ftruncate()");
return PTS_UNRESOLVED;
}

if (shm_unlink(SHM_NAME) != 0) {
perror(ERROR_PREFIX "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;
Expand Down Expand Up @@ -82,5 +100,7 @@ int main(void)
}
return PTS_PASS;
}

close(fd);
return PTS_UNRESOLVED;
}

0 comments on commit 3d77539

Please sign in to comment.