From: ludo@gnu.org (Ludovic Courtès)
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: 21460@debbugs.gnu.org, bug-guix@gnu.org
Subject: bug#21460: Race condition in tests/tail-2/assert.sh
Date: Fri, 11 Sep 2015 22:55:01 +0200 [thread overview]
Message-ID: <87a8ssad7e.fsf@gnu.org> (raw)
In-Reply-To: <55F30CEC.7060102@cs.ucla.edu> (Paul Eggert's message of "Fri, 11 Sep 2015 10:18:36 -0700")
[-- Attachment #1: Type: text/plain, Size: 1135 bytes --]
Paul Eggert <eggert@cs.ucla.edu> skribis:
> Ludovic Courtès wrote:
>> I think the problem happens when ‘tail’ opens ‘foo’ right in between of
>> the two notifications: ‘foo’ is still there, and so ‘tail’ doesn’t
>> report anything.
>>
>> Does that make sense?
>
> Yes, though if the link count is indeed zero, I'm surprised that
> 'tail' can open the file -- that sounds like a bug in the kernel.
Attached is a reproducer; just run it in a loop for a couple of seconds:
--8<---------------cut here---------------start------------->8---
$ while ./a.out ; do : ; done
funny, errno = Success, nlink = 0
Aborted (core dumped)
--8<---------------cut here---------------end--------------->8---
I’m not sure if that’s a kernel bug. Strictly speaking, inotify works
as expected: we get a notification for nlink--, which doesn’t mean the
file has vanished.
The conclusion for ‘tail’ would be to wait for the IN_DELETE_SELF event
before considering the file to be gone. WDYT?
(That ‘inotify_rm_watch’ returns EINVAL *is* a bug IMO, but not
worrisome.)
Thanks,
Ludo’.
[-- Attachment #2: the inotify race --]
[-- Type: text/plain, Size: 1257 bytes --]
#define _GNU_SOURCE 1
#include <stdlib.h>
#include <unistd.h>
#include <sys/inotify.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <assert.h>
int
main ()
{
int file = creat ("foo", S_IRUSR | S_IWUSR);
assert_perror (errno);
close (file);
int notifications = inotify_init ();
assert_perror (errno);
int watch = inotify_add_watch (notifications, "foo",
IN_MODIFY | IN_ATTRIB
| IN_DELETE_SELF | IN_MOVE_SELF);
assert_perror (errno);
if (fork () == 0)
{
unlink ("foo");
assert_perror (errno);
exit (EXIT_SUCCESS);
}
struct inotify_event event;
ssize_t count = read (notifications, &event, sizeof event);
assert (count == sizeof event);
assert (event.mask == IN_ATTRIB);
struct stat st;
stat ("foo", &st);
if (errno != ENOENT)
{
printf ("funny, errno = %m, nlink = %li\n",
st.st_nlink);
abort ();
}
count = read (notifications, &event, sizeof event);
assert (count == sizeof event);
assert (event.mask == IN_DELETE_SELF);
/* Bug #2: this returns EINVAL for no good reason. */
/* inotify_rm_watch (notifications, watch); */
/* assert_perror (errno); */
return EXIT_SUCCESS;
}
next prev parent reply other threads:[~2015-09-11 20:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-11 16:23 bug#21459: Race condition in tests/tail-2/assert.sh Ludovic Courtès
2015-09-11 17:18 ` bug#21460: " Paul Eggert
2015-09-11 20:55 ` Ludovic Courtès [this message]
2015-09-11 22:49 ` Pádraig Brady
2015-09-11 23:48 ` Pádraig Brady
2015-09-12 1:09 ` Paul Eggert
2015-09-12 2:22 ` Pádraig Brady
2015-10-02 15:50 ` Pádraig Brady
2015-09-11 20:34 ` bug#21459: " Pádraig Brady
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=87a8ssad7e.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=21460@debbugs.gnu.org \
--cc=bug-guix@gnu.org \
--cc=eggert@cs.ucla.edu \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
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.