This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] Remove signal handling for nanosleep (bug 16364)



On 10-11-2015 11:16, Andreas Schwab wrote:
> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> 
>> +/* Fork and terminate the child in 0.25s while parent waits on a nanosleep
>> +   for 0.5s.  */
>> +static int
>> +check_nanosleep_base (void)
>> +{
>> +  int ret = 0;
>> +  pid_t f = fork ();
>> +  if (f == 0)
>> +    {
>> +      // child
>> +      struct timespec tv = { .tv_sec = 0, .tv_nsec = 250000000UL };
>> +      nanosleep (&tv, &tv);
>> +      _exit (EXIT_SUCCESS);
>> +    }
>> +  else if (f > 0)
>> +    {
>> +      // parent
>> +      struct timespec tv = { .tv_sec = 0, .tv_nsec = 500000000UL };
>> +      ret = nanosleep (&tv, &tv);
>> +    }
>> +  else if (f == -1)
>> +    {
>> +      puts ("error: fork failed");
>> +      _exit (EXIT_FAILURE);
>> +    }
>> +  return ret;
>> +}
> 
> You should wait for the child before returning.
> How do you avoid the race between the parent and the child?
> 

That's the hole points of the previous discussion in v1 patch while
Florian also pointed this racy.  He neither I could devise a race-free
testcase to check for this issue so my questioning was if someone have
a way to remove the race or if we really should push for this test. 

> Andreas.
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]