All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] Refactor pidns16 test using new LTP API
Date: Mon, 15 Aug 2022 16:00:41 +0200	[thread overview]
Message-ID: <YvpRidqm9QPS6DfR@yuki> (raw)
In-Reply-To: <YvZyAt0QGnRZMirP@pevik>

Hi!
> > +static int counter;
> Shouldn't this be volatile? And maybe also sig_atomic_t instead of int (even
> it's the same)?

As long as we only modify the counter from within the signal handler
it's not required.

The probelm that sig_atomic_t fixes is to make sure that the load/store
is single CPU instruction so that we are sure that we don not jump into
the handler in the middle of a sequence of load/store instruction.

And the volatile "turns off" caching of the value, so again anything
that is accessed from both the handler and the rest of the code should
be volatile.

> static volatile sig_atomic_t counter;
> 
> > -char *TCID = "pidns16";
> > -int TST_TOTAL = 3;
> > -
> > -void child_signal_handler(int sig, siginfo_t * si, void *unused)
> > +static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LTP_ATTRIBUTE_UNUSED void *unused)
> >  {
> > -	static int c = 1;
> > -	pid_t expected_pid;
> > -
> > -	/* Verifying from which process the signal handler is signalled */
> > +	pid_t exp_pid;
> 
> > -	switch (c) {
> > -	case 1:
> > -		expected_pid = PARENT_PID;
> > +	switch (counter) {
> > +	case 0:
> > +		exp_pid = 0;
> >  		break;
> > -	case 2:
> > -		expected_pid = CHILD_PID;
> > +	case 1:
> > +		exp_pid = 1;
> >  		break;
> >  	default:
> > -		tst_resm(TBROK, "child should NOT be signalled 3+ times");
> > +		tst_brk(TBROK, "Child should NOT be signalled 3+ times");
> >  		return;
> >  	}
> 
> very nit: I'd use if (counter 
> if (counter > 1) {
> 	tst_brk(TBROK, "Child should NOT be signalled 3+ times");
> 	return;
> }
> exp_pid = counter;

The bigger problem though is that we call tst_brk() and tst_res() in the
handler, which is not safe at all. The are couple things that can go
wrong here, mostly glibc locks can get deadlocked for the underlying
FILE* and if the underlying fprintf() calls malloc() the malloc data
structures may end up corrupted. It's quite rare for this to happen, but
there have been a few tests that were failing with small probability due
to these mistakes.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08 12:50 [LTP] [PATCH v1] Refactor pidns16 test using new LTP API Andrea Cervesato via ltp
2022-08-12 15:30 ` Petr Vorel
2022-08-15 14:00   ` 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=YvpRidqm9QPS6DfR@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    /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.