bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test-fdutimensat racy?


From: Eric Blake
Subject: Re: test-fdutimensat racy?
Date: Tue, 21 May 2013 08:10:54 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130514 Thunderbird/17.0.6

On 05/21/2013 07:27 AM, Bernhard Voelker wrote:
> On 05/21/2013 03:08 PM, Eric Blake wrote:
>> On 05/21/2013 06:52 AM, Bernhard Voelker wrote:
>>> +  if (-1 == fd)
>>> +    {
>>> +      ASSERT ((fd = creat (BASE "naptmp", 0600)) != -1); /* Never closed.  
>>> */
>>> +      ASSERT (unlink (BASE "naptmp") == 0);
>>
>> unlink() of an open fd is not guaranteed to succeed, and indeed fails on
>> mingw; you can also provoke the failure in some NFS setups.  You'd need
>> to add some cleanup (maybe an atexit hook will work) that closes and
>> only then removes the witness file.
>>
> 
> Good catch, thanks.
> Here's a new version of the patch.
> 

> +
> +static void
> +clear_temp_file (void)
>  {

Needs a close here to work...

> +  unlink (TEMPFILE);
>  }
> 
>  /* Sleep long enough to notice a timestamp difference on the file
> -   system in the current directory.  Assumes that BASE is defined,
> -   and requires that the test module depends on nanosleep.  */
> +   system in the current directory.  Use an adaptive approach, trying
> +   to find the smallest delay which works on the current file system
> +   to make the timestamp difference appear.  Assert a maximum delay of
> +   2 seconds.  Assumes that BASE is defined, and requires that the test
> +   module depends on nanosleep.  */
>  static void
>  nap (void)
>  {
> -  static struct timespec delay;
> -  if (!delay.tv_sec && !delay.tv_nsec)
> +  static int fd = -1;
> +  struct stat old_st;
> +  static int delay = 1;
> +
> +  if (-1 == fd)
> +    {
> +      ASSERT ((fd = creat (TEMPFILE, 0600)) != -1); /* Never closed.  */

...at which point this comment is now wrong.  You need to save the fd
here, so that...

> +      atexit (clear_temp_file);

clear_temp_file knows which fd to close.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]