dnotify: ignore FS_EVENT_ON_CHILD
commit2e776c1424b3c276c8cf6775f7e0b2f1ef42e624
authorAndreas Gruenbacher <agruen@suse.de>
Wed, 14 Oct 2009 22:13:23 +0000 (15 00:13 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 1 Apr 2010 22:55:49 +0000 (1 15:55 -0700)
treec84853a3adbb66dfe2bd8c201dbacbe6cf7c93b8
parent0a550150a43ec8dfe49171e9e736e6d7b8b7fa8b
dnotify: ignore FS_EVENT_ON_CHILD

commit 945526846a84c00adac1efd1c6befdaa77039623 upstream.

Mask off FS_EVENT_ON_CHILD in dnotify_handle_event().  Otherwise, when there
is more than one watch on a directory and dnotify_should_send_event()
succeeds, events with FS_EVENT_ON_CHILD set will trigger all watches and cause
spurious events.

This case was overlooked in commit e42e2773.

#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

static void create_event(int s, siginfo_t* si, void* p)
{
printf("create\n");
}

static void delete_event(int s, siginfo_t* si, void* p)
{
printf("delete\n");
}

int main (void) {
struct sigaction action;
char *tmpdir, *file;
int fd1, fd2;

sigemptyset (&action.sa_mask);
action.sa_flags = SA_SIGINFO;

action.sa_sigaction = create_event;
sigaction (SIGRTMIN + 0, &action, NULL);

action.sa_sigaction = delete_event;
sigaction (SIGRTMIN + 1, &action, NULL);

# define TMPDIR "/tmp/test.XXXXXX"
tmpdir = malloc(strlen(TMPDIR) + 1);
strcpy(tmpdir, TMPDIR);
mkdtemp(tmpdir);

# define TMPFILE "/file"
file = malloc(strlen(tmpdir) + strlen(TMPFILE) + 1);
sprintf(file, "%s/%s", tmpdir, TMPFILE);

fd1 = open (tmpdir, O_RDONLY);
fcntl(fd1, F_SETSIG, SIGRTMIN);
fcntl(fd1, F_NOTIFY, DN_MULTISHOT | DN_CREATE);

fd2 = open (tmpdir, O_RDONLY);
fcntl(fd2, F_SETSIG, SIGRTMIN + 1);
fcntl(fd2, F_NOTIFY, DN_MULTISHOT | DN_DELETE);

if (fork()) {
/* This triggers a create event */
creat(file, 0600);
/* This triggers a create and delete event (!) */
unlink(file);
} else {
sleep(1);
rmdir(tmpdir);
}

return 0;
}

Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
Signed-off-by: Eric Paris <eparis@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/notify/dnotify/dnotify.c