Re: [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback

Thomas Weißschuh (Schneider Electric) <[email protected]> Tue, 7 Apr 2026 10:50:07 +0200
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <20260407104610-a319819e-8194-473b-982f-9afbb27b3b0b@linutronix.de>
On Tue, Apr 07, 2026 at 10:16:08AM +0200, Florian Bezdeka wrote:
> On Tue, 2026-04-07 at 08:48 +0200, Thomas Weißschuh (Schneider Electric)
> wrote:
> > clock_nanosleep() is expected to return errors as a positive number,
> > without relying on errno.
> > 
> > Signed-off-by: Thomas Weißschuh (Schneider Electric) <[email protected]>
> > ---
> >  src/cyclictest/cyclictest.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> > index 0c30e767e685..dacf0b7a718e 100644
> > --- a/src/cyclictest/cyclictest.c
> > +++ b/src/cyclictest/cyclictest.c
> > @@ -62,12 +62,18 @@
> >  static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req,
> >  			   struct timespec *rem)
> >  {
> > +	int retval;
> > +
> >  	if (clock_id == CLOCK_THREAD_CPUTIME_ID)
> >  		return -EINVAL;
> >  	if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
> >  		clock_id = MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED);
> >  
> > -	return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
> > +	retval = syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
> > +	if (retval == 0)
> > +		return 0;
> > +
> > +	return errno;
> 
> That doesn't match with the commit message above, does it? syscall() to
> my knowledge will not set/touch errno. syscall() will return whatever
> came back from the kernel.

syscall() *does* indeed touch errno. From syscall(2):
"A -1 return value indicates an error, and an error number is stored in errno."

Unfortunately there is no standard variant of syscall() which does not
touch errno.

> The value of errno is "undefined" (in terms of "contains the last error
> code, wherever this is coming from") here.
> 
> Looking at patch 4: Looks like this patch can be dropped.

No, this patch (patch 3) is only for the fallback definition of uclibc.
Patch 4 is necessary for all libcs. For some (to me unknown) reason
clock_nanosleep() works different from all the other libc functions.

> >  }
> >  
> >  int sched_setaffinity(__pid_t __pid, size_t __cpusetsize,
> > 
> > -- 
> > 2.53.0