[LTP] openposix: timers/twoevtimers: Wait for both timer signals

Jan Stancek jstancek@redhat.com
Sat Oct 10 11:42:08 CEST 2026


On Sat, Oct 10, 2026, 11:07 Li Wang <li.wang@linux.dev> wrote:

> Hi Jan,
>
> linuxtestproject.agent@gmail.com wrote:
>
> > Hi Jan,
> >
> > On Fri, 9 Oct 2026, Jan Stancek via ltp wrote:
> > > openposix: timers/twoevtimers: Wait for both timer signals
> >
> > > +   PTS_WRITE_MSG("Caught abort signal\n");
> > > +   PTS_WRITE_MSG("Caught alarm signal\n");
> > > +           if (errno != EINTR) {
> > > +                   perror("nanosleep() did not return success\n");
> > > +                   return PTS_UNRESOLVED;
> > > +           }
> >
> > Medium: PTS_WRITE_MSG() calls write() without preserving errno. If the
> > second signal arrives after nanosleep() sets EINTR but before the new
> > errno check, a failed handler write (e.g. EAGAIN on a full nonblocking
> > stdout pipe) causes a spurious unresolved result even when both timers
> > fired. Save errno on entry and restore it before returning in both
> > handlers.
>
> The race condition pointed out by the AI seems plausible. Would it make
> sense to save and restore errno in the signal handlers, like this:
>

It seems very unlikely. I was thinking to move the print outside of signal
handler if we want to address it.


> static void handler_abrt(int signo PTS_ATTRIBUTE_UNUSED)
>  {
> +       int saved_errno = errno;
> +
>         PTS_WRITE_MSG("Caught abort signal\n");
>         caughtabort++;
> +
> +       errno = saved_errno;
> +
>  }
>
>  static void handler_alrm(int signo PTS_ATTRIBUTE_UNUSED)
>  {
> +       int saved_errno = errno;
> +
>         PTS_WRITE_MSG("Caught alarm signal\n");
>         caughtalarm++;
> +
> +       errno = saved_errno;
>  }
>
> The rest part looks good to me.
>
> --
> Regards,
> Li Wang
>
>


More information about the ltp mailing list