public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* directory notifications lost after fork?
@ 2002-03-10 21:08 Oskar Liljeblad
  2002-03-11  7:41 ` Alex Riesen
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Oskar Liljeblad @ 2002-03-10 21:08 UTC (permalink / raw)
  To: linux-kernel

The code snipper demonstrates what I consider a bug in the
dnotify facilities in the kernel. After a fork, all registered
notifications are lost in the process where they originally
where registered (the parent process). "lost" here means that
the signal specified with F_SETSIG fcntl no longer is delivered
when notified.

How to reproduce (tested with 2.4.17):
  gcc -o dnoticebug dnoticebug.c
  dnoticebug &				# run in background
  cat dnoticebug.c >/dev/null		# "notified" should now be printed
  cat dnoticebug.c >/dev/null		# nothing is printed this time
  
If you comment out the line with fork below, "notified" *will* be
printed every time you cat dnoticebug.c.

I'm not subscribed to the list so I'd appreciate if you CCed me.
(Otherwise I'd have to use the archives :) Thanks.

Oskar Liljeblad (oskar@osk.mine.nu)

===

#define _GNU_SOURCE
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

static void handler(int sig, siginfo_t *si, void *data)
{
	printf("notified\n");
}

int main(void)
{
	struct sigaction act;
	int fd;

	act.sa_sigaction = handler;
	sigemptyset(&act.sa_mask);
	act.sa_flags = SA_SIGINFO;
	sigaction(SIGRTMIN, &act, NULL);

	fd = open(".", O_RDONLY);
	fcntl(fd, F_SETSIG, SIGRTMIN);
	fcntl(fd, F_NOTIFY, DN_ACCESS|DN_MULTISHOT);

	while (1) {
		pause();
		if (fork() <= 0) exit(0);
		wait(NULL);
	}
}

^ permalink raw reply	[flat|nested] 15+ messages in thread
[parent not found: <20020311122701.A9718@riesen-pc.gr05.synopsys.com>]
* Re: directory notifications lost after fork?
@ 2002-03-12  1:47 Malte Starostik
  2002-03-12 12:55 ` Jamie Lokier
  0 siblings, 1 reply; 15+ messages in thread
From: Malte Starostik @ 2002-03-12  1:47 UTC (permalink / raw)
  To: linux-kernel

(Manually quoted from the archive)

> Just a "me too".
> I have tried also to use the default (SIGIO) by setting owner pid (just
> in case). It is all the same.
> Does someone use the notifications, btw?
> The whole thing seems somewhat untested.
> -alex
We used to use them in the KDE libraries. However, we decided to disable it 
for now due to this problem since it's not theoretical, it hits quite often 
in konqueror and especially kdesktop as both spawn child processes.
On a side note, dnotify is pretty weak compared to FAM with imon 
(http://oss.sgi.com/projects/fam/) IMHO:
Imagine a file manager that has a view on a large directory like /usr/bin. Now 
a file in that directory is added / removed / changed. With dnotify, the 
filemanager will have to rescan the whole directory as a reaction to the 
signal, to find out which file has changed. OTOH, with FAM, it gets a precise 
event that tells "file `somebinary' has been added" or similar.
I don't have much of a clue about the kernel, so please excuse my ignorance, 
but the imon patch seems pretty unintrusive to me and enables more 
fine-grained file change notifications than dnotify. Also, FAM can monitor 
NFS-mounted directories with almost no network overhead when it's also 
running on the server.

> On Sun, Mar 10, 2002 at 10:08:02PM +0100, Oskar Liljeblad wrote:
> > The code snipper demonstrates what I consider a bug in the
> > dnotify facilities in the kernel. After a fork, all registered
> > notifications are lost in the process where they originally
> > where registered (the parent process). "lost" here means that
> > the signal specified with F_SETSIG fcntl no longer is delivered
> > when notified.

Regards,
-Malte

PS: I'm not subscribed, please CC me on answers; I'll also watch the archive.
-- 
Malte Starostik
PGP: 1024D/D2F3C787 [C138 2121 FAF3 410A 1C2A  27CD 5431 7745 D2F3 C787]


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2002-03-12 17:23 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-10 21:08 directory notifications lost after fork? Oskar Liljeblad
2002-03-11  7:41 ` Alex Riesen
2002-03-12 12:19   ` Jamie Lokier
2002-03-11  8:50 ` Oskar Liljeblad
2002-03-11 10:20   ` Alex Riesen
2002-03-11 10:26 ` Andrea Arcangeli
2002-03-12  1:04   ` Stephen Rothwell
2002-03-12  1:20     ` Andrea Arcangeli
2002-03-12  2:59       ` Stephen Rothwell
2002-03-12  4:01         ` Andrea Arcangeli
     [not found] <20020311122701.A9718@riesen-pc.gr05.synopsys.com>
2002-03-11 19:34 ` Alex Riesen
  -- strict thread matches above, loose matches on Subject: below --
2002-03-12  1:47 Malte Starostik
2002-03-12 12:55 ` Jamie Lokier
2002-03-12 16:37   ` Daniel Phillips
2002-03-12 17:21     ` Jamie Lokier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox