public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: chenguanxi11234@163.com
Cc: yang.guang5@zte.com.cn, ltp@lists.linux.it,
	Chen Haonan <chen.haonan2@zte.com.cn>
Subject: Re: [LTP] [PATCH v2] posix/conformance/interfaces/sem_timedwait/2-1: Fix test
Date: Mon, 15 Jan 2024 11:01:13 +0100	[thread overview]
Message-ID: <ZaUCaXEcdEquP_r7@yuki> (raw)
In-Reply-To: <977c827a45313499dd372cfda1c5156c2729595d.1704804430.git.chen.haonan2@zte.com.cn>

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

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

      reply	other threads:[~2024-01-15 10:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-14  6:38 [LTP] [PATCH v2] posix/conformance/interfaces/sem_timedwait/2-1: Fix test chenguanxi11234
2024-01-15 10:01 ` Cyril Hrubis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZaUCaXEcdEquP_r7@yuki \
    --to=chrubis@suse.cz \
    --cc=chen.haonan2@zte.com.cn \
    --cc=chenguanxi11234@163.com \
    --cc=ltp@lists.linux.it \
    --cc=yang.guang5@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox