All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] Refactor pidns30 test using new LTP API
Date: Mon, 15 Aug 2022 17:07:41 +0200	[thread overview]
Message-ID: <YvphPfNzlDY6MM9r@yuki> (raw)
In-Reply-To: <20220812075005.16920-1-andrea.cervesato@suse.com>

Hi!
> +static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LTP_ATTRIBUTE_UNUSED void *unused)
>  {
> -	char buf[256];
> -	struct mq_attr attr;
> -
> -	if (si->si_signo != SIGUSR1) {
> -		printf("received signal = %d unexpectedly\n", si->si_signo);
> +	if (si->si_signo != SIGUSR1 || si->si_code != SI_MESGQ || si->si_pid != 0)
>  		return;
> -	}
>  
> -	if (si->si_code != SI_MESGQ) {
> -		printf("expected signal code SI_MESGQ; got %d instead\n",
> -		       si->si_code);
> -		return;
> -	}
> -
> -	if (si->si_pid) {
> -		printf("expected signal originator PID = 0; got %d instead\n",
> -		       si->si_pid);
> -		return;
> -	} else {
> -		printf("signal originator PID = 0\n");
> -		result = TPASS;
> -	}
> -
> -	/*
> -	 * Now read the message - Be silent on errors since this is not the
> -	 * test purpose.
> -	 */
> -	rc = mq_getattr(si->si_int, &attr);
> -	if (rc != -1)
> -		mq_receive(si->si_int, buf, attr.mq_msgsize, NULL);
> +	received++;

I do not like that much that we lost most of the information about the
failure here. Can we store at least the si_signo and si_pid so that they
can be printed in the case of the failure?

> -int main(void)
> +static void run(void)
>  {
> -	int status;
> -	char buf[5];
> -	pid_t cpid;
> -
> -	setup();
> -
> -	if (pipe(child_to_father) == -1 || pipe(father_to_child) == -1) {
> -		tst_brkm(TBROK | TERRNO, cleanup, "pipe failed");
> -	}
> +	int ret;
>  
> -	tst_syscall(__NR_mq_unlink, mqname);
> +	remove_mqueue(mqd);
>  
> -	/* container creation on PID namespace */
> -	cpid = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_fn, NULL);
> -	if (cpid == -1)
> -		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
> +	ret = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, NULL);
> +	if (ret < 0)
> +		tst_brk(TBROK | TERRNO, "clone failed");
>  
> -	mqd =
> -	    tst_syscall(__NR_mq_open, mqname, O_RDWR | O_CREAT | O_EXCL, 0777,
> -		    NULL);
> +	mqd = mq_open(MQNAME, O_RDWR | O_CREAT | O_EXCL, 0777, 0);
>  	if (mqd == -1)
> -		tst_brkm(TBROK | TERRNO, cleanup, "mq_open failed");
> -	else
> -		tst_resm(TINFO, "successfully created posix mqueue");
> +		tst_brk(TBROK | TERRNO, "mq_open failed");

We allready have SAFE_MQ_OPEN() I guess that we may add the rest of the
SAFE_MQ_* calls as well and use them here.

-- 
Cyril Hrubis
chrubis@suse.cz

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

      reply	other threads:[~2022-08-15 15:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12  7:50 [LTP] [PATCH v2] Refactor pidns30 test using new LTP API Andrea Cervesato via ltp
2022-08-15 15:07 ` 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=YvphPfNzlDY6MM9r@yuki \
    --to=chrubis@suse.cz \
    --cc=andrea.cervesato@suse.com \
    --cc=ltp@lists.linux.it \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.