[LTP] [PATCH v2] posix/conformance/interfaces/sem_timedwait/2-1: Fix test

Cyril Hrubis chrubis@suse.cz
Mon Jan 15 11:01:13 CET 2024


Hi!
> -	/* Semaphore started out locked */
> -	if (sem_init(&mysemp, 0, 0) == -1) {
> +	/* Map semaphore to shared memory */
> +	int shm_fd = shm_open("/myshm", O_CREAT | O_RDWR, 0666);
> +
> +	ftruncate(shm_fd, sizeof(sem_t));
> +	mysemp = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);

Again, this can be just anonymous memory, need need to back it up by the
file descriptor. Should be as easy as:

	mysemp = mmap(NULL, sizeof(*mysemp), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);

As well as the error conditions are still not checked.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list