* rebased llvm/hotfix-sparcv9-not-64.diff
[t2sde.git] / package / filesystem / fam / fam-2.7.0-dnotify-1.patch
blob5620f4a7b9ce02a0b3d2ec94f4f7024c55ada350
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../fam/fam-2.7.0-dnotify-1.patch
5 # Copyright (C) 2008 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 Submitted By: Jim Gifford (jim at linuxfromscratch dot org)
18 Date: 2004-03-15
19 Initial Package Version: Jim Gifford
20 Origin: Debian Maintainer of FAM
21 Description: Dnotify Patch for FAM 2.7.0
23 diff -Naur fam-2.7.0.orig/config.h.in fam-2.7.0/config.h.in
24 --- fam-2.7.0.orig/config.h.in 2003-01-20 00:40:15.000000000 +0000
25 +++ fam-2.7.0/config.h.in 2004-03-15 21:31:34.553059530 +0000
26 @@ -180,3 +180,6 @@
28 /* Define to `int' if <sys/types.h> doesn't define. */
29 #undef uid_t
31 +/* Define to 1 if you have F_NOTIFY fcntl */
32 +#undef USE_DNOTIFY
33 diff -Naur fam-2.7.0.orig/configure.ac fam-2.7.0/configure.ac
34 --- fam-2.7.0.orig/configure.ac 2003-11-26 19:47:59.000000000 +0000
35 +++ fam-2.7.0/configure.ac 2004-03-15 21:31:34.556058981 +0000
36 @@ -33,7 +33,26 @@
37 AC_HEADER_DIRENT
38 AC_CHECK_HEADERS([fcntl.h limits.h linux/imon.h netinet/in.h rpc/rpc.h rpcsvc/mount.h stddef.h stdlib.h string.h syslog.h sys/imon.h sys/param.h sys/select.h sys/statvfs.h sys/syssgi.h sys/time.h sys/types.h sys/un.h unistd.h])
40 -if test "$have_sys_imon_h"; then
41 +# Test for the linux dnotify fcntl
42 +AC_MSG_CHECKING([for dnotify fcntl support])
43 +AC_TRY_COMPILE([
44 +#define _GNU_SOURCE
45 +#include <fcntl.h>
46 +#include <unistd.h>
47 +],
48 +[ int fd = 1;
49 + fcntl (fd, F_NOTIFY, (DN_MODIFY|DN_CREATE|DN_DELETE|DN_RENAME|DN_ATTRIB)
50 + |DN_MULTISHOT);
51 +], have_dnotify=yes, have_dnotify=no)
53 +use_dnotify=false
54 +AC_MSG_RESULT($have_dnotify)
56 +if test "$have_dnotify"; then
57 + MONITOR_FUNCS=IMonNone
58 + AC_DEFINE([USE_DNOTIFY], [], [Use dnotify])
59 + use_dnotify=true
60 +elif test "$have_sys_imon_h"; then
61 MONITOR_FUNCS=IMonIRIX
62 elif test "$have_linux_imon_h"; then
63 MONITOR_FUNCS=IMonLinux
64 @@ -41,6 +60,7 @@
65 MONITOR_FUNCS=IMonNone
67 AC_SUBST(MONITOR_FUNCS)
68 +AM_CONDITIONAL(USE_DNOTIFY, $use_dnotify)
70 # Checks for typedefs, structures, and compiler characteristics.
71 AC_HEADER_STDBOOL
72 diff -Naur fam-2.7.0.orig/src/DNotify.c++ fam-2.7.0/src/DNotify.c++
73 --- fam-2.7.0.orig/src/DNotify.c++ 1970-01-01 00:00:00.000000000 +0000
74 +++ fam-2.7.0/src/DNotify.c++ 2004-03-15 21:31:34.542061543 +0000
75 @@ -0,0 +1,582 @@
76 +// Copyright (C) 2001 Red Hat, Inc. All Rights Reserved.
77 +// Copyright (C) 1999 Silicon Graphics, Inc. All Rights Reserved.
78 +//
79 +// This program is free software; you can redistribute it and/or modify it
80 +// under the terms of version 2 of the GNU General Public License as
81 +// published by the Free Software Foundation.
82 +//
83 +// This program is distributed in the hope that it would be useful, but
84 +// WITHOUT ANY WARRANTY; without even the implied warranty of
85 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, any
86 +// license provided herein, whether implied or otherwise, is limited to
87 +// this program in accordance with the express provisions of the GNU
88 +// General Public License. Patent licenses, if any, provided herein do not
89 +// apply to combinations of this program with other product or programs, or
90 +// any other product whatsoever. This program is distributed without any
91 +// warranty that the program is delivered free of the rightful claim of any
92 +// third person by way of infringement or the like. See the GNU General
93 +// Public License for more details.
94 +//
95 +// You should have received a copy of the GNU General Public License along
96 +// with this program; if not, write the Free Software Foundation, Inc., 59
97 +// Temple Place - Suite 330, Boston MA 02111-1307, USA.
99 +#define _GNU_SOURCE
100 +#include <fcntl.h>
102 +#include <string.h>
103 +#include <signal.h>
104 +#include <stdio.h>
105 +#include <unistd.h>
106 +#include <sys/types.h>
107 +#include <sys/stat.h>
108 +#include <libgen.h>
110 +#include "DNotify.h"
112 +#include "Interest.h"
113 +#include "Log.h"
114 +#include "Scheduler.h"
115 +#include <memory>
118 +int DNotify::pipe_write_fd = -2;
119 +int DNotify::pipe_read_fd = -2;
120 +volatile sig_atomic_t DNotify::queue_overflowed = 0;
121 +volatile sig_atomic_t DNotify::queue_changed = 0;
122 +int DNotify::change_queue[QUEUESIZE];
123 +volatile int DNotify::queue_head = 0; // Only modified by read handler
124 +volatile int DNotify::queue_tail = 0; // Only modified by signal handler
125 +DNotify::EventHandler DNotify::ehandler;
127 +DNotify::DirWatch *DNotify::dir_hash[DIR_HASHSIZE];
128 +DNotify::FileWatch *DNotify::file_hash[FILE_HASHSIZE];
130 +struct DNotify::FileWatch
132 + DirWatch *dir_watch;
133 + dev_t file_dev;
134 + ino_t file_ino;
135 + FileWatch *next; // The DirWatch.watches list
136 + FileWatch *hash_link;
139 +struct DNotify::DirWatch
141 + int fd;
142 + dev_t dir_dev;
143 + ino_t dir_ino;
145 + DirWatch *hash_link;
146 + FileWatch *watches;
149 +struct DNotify::ChangeEventData
151 + dev_t file_dev;
152 + ino_t file_ino;
153 +};
155 +DNotify::DNotify(EventHandler h)
157 + assert(ehandler == NULL);
158 + ehandler = h;
161 +DNotify::~DNotify()
163 + if (pipe_read_fd >= 0)
165 + // Tell the scheduler.
167 + (void) Scheduler::remove_read_handler(pipe_read_fd);
169 + // Close the pipe.
171 + if (close(pipe_read_fd) < 0)
172 + Log::perror("can't pipe read end");
173 + else
174 + Log::debug("closed pipe read end");
176 + if (close(pipe_write_fd) < 0)
177 + Log::perror("can't pipe write end");
178 + else
179 + Log::debug("closed pipe write end");
180 + pipe_read_fd = -1;
182 + ehandler = NULL;
185 +void
186 +DNotify::overflow_signal_handler(int sig, siginfo_t *si, void *data)
188 + char c = 'x';
191 + char *str = "*************** overflow sigqueue ***********************\n";
192 + write (STDERR_FILENO, str, strlen(str));
195 + if (!queue_overflowed)
197 + queue_overflowed = 1;
198 + // Trigger the read handler
199 + write(pipe_write_fd, &c, 1);
203 +void
204 +DNotify::signal_handler(int sig, siginfo_t *si, void *data)
206 + int left;
207 + char c = 'x';
209 + if (queue_head <= queue_tail)
210 + left = (QUEUESIZE + queue_head) - queue_tail;
211 + else
212 + left = queue_head - queue_tail;
214 + // Must leave at least one item unused to see difference
215 + // Betweeen empty and full
216 + if (left <= 1)
218 + queue_overflowed = 1;
220 + char *str = "*************** overflow famqueue ****************\n";
221 + write (STDERR_FILENO, str, strlen(str));
224 + else
226 + change_queue[queue_tail] = si->si_fd;
227 + queue_tail = (queue_tail + 1) % QUEUESIZE;
230 + if (!queue_changed)
232 + queue_changed = 1;
233 + // Trigger the read handler
234 + write(pipe_write_fd, &c, 1);
238 +bool
239 +DNotify::is_active()
241 + if (pipe_read_fd == -2)
243 + int filedes[2];
244 + int res;
246 + res = pipe (filedes);
247 + if (res >= 0)
248 + { Log::debug("opened pipe");
249 + pipe_read_fd = filedes[0];
250 + pipe_write_fd = filedes[1];
252 + // Setup signal handler:
253 + struct sigaction act;
255 + act.sa_sigaction = signal_handler;
256 + sigemptyset(&act.sa_mask);
257 + act.sa_flags = SA_SIGINFO;
258 + sigaction(SIGRTMIN, &act, NULL);
260 + // When the RT queue overflows we get a SIGIO
261 + act.sa_sigaction = overflow_signal_handler;
262 + sigemptyset(&act.sa_mask);
263 + sigaction(SIGIO, &act, NULL);
265 + (void) Scheduler::install_read_handler(pipe_read_fd, read_handler, NULL);
268 + return pipe_read_fd >= 0;
271 +DNotify::DirWatch *
272 +DNotify::lookup_dirwatch (int fd)
274 + DirWatch **p;
275 + DirWatch *w;
277 + p = dir_hashchain (fd);
279 + while (*p)
281 + w = *p;
283 + if (w->fd == fd)
284 + return w;
286 + p = &w->hash_link;
289 + return *p;
292 +// This colud be made faster by using another hash table.
293 +// But it's not that bad, since it is only used by express/revoke
294 +DNotify::DirWatch *
295 +DNotify::lookup_dirwatch (dev_t dir_dev, ino_t dir_ino)
297 + DirWatch *p;
298 + int i;
300 + for (i=0;i<DIR_HASHSIZE;i++)
302 + p = dir_hash[i];
304 + while (p)
306 + if (p->dir_dev == dir_dev && p->dir_ino == dir_ino)
307 + return p;
309 + p = p->hash_link;
313 + return NULL;
316 +DNotify::FileWatch *
317 +DNotify::lookup_filewatch (dev_t dev, ino_t ino)
319 + FileWatch **p;
320 + FileWatch *w;
322 + p = file_hashchain (dev, ino);
324 + while (*p)
326 + w = *p;
328 + if (w->file_dev == dev && w->file_ino == ino)
329 + return w;
331 + p = &w->hash_link;
334 + return *p;
337 +// Make sure w is not already in the hash table before calling
338 +// this function.
339 +void
340 +DNotify::hash_dirwatch(DirWatch *w)
342 + DirWatch **p;
343 + p = dir_hashchain (w->fd);
344 + w->hash_link = *p;
345 + *p = w;
348 +// Make sure w is not already in the hash table before calling
349 +// this function.
350 +void
351 +DNotify::hash_filewatch(FileWatch *w)
353 + FileWatch **p;
354 + p = file_hashchain (w->file_dev, w->file_ino);
355 + w->hash_link = *p;
356 + *p = w;
359 +void
360 +DNotify::unhash_dirwatch(DirWatch *w)
362 + DirWatch **p;
364 + p = dir_hashchain (w->fd);
366 + while (*p)
368 + if (*p == w)
370 + *p = w->hash_link;
371 + break;
373 + p = &(*p)->hash_link;
375 + w->hash_link = NULL;
378 +void
379 +DNotify::unhash_filewatch(FileWatch *w)
381 + FileWatch **p;
383 + p = file_hashchain (w->file_dev, w->file_ino);
385 + while (*p)
387 + if (*p == w)
389 + *p = w->hash_link;
390 + break;
392 + p = &(*p)->hash_link;
394 + w->hash_link = NULL;
397 +DNotify::Status
398 +DNotify::watch_dir(const char *notify_dir, dev_t file_dev, ino_t file_ino)
400 + struct stat stat;
401 + dev_t dir_dev;
402 + ino_t dir_ino;
403 + DirWatch *dwatch;
404 + FileWatch *fw;
406 + if (lstat (notify_dir, &stat) == -1)
407 + return BAD;
409 + dwatch = lookup_dirwatch(stat.st_dev, stat.st_ino);
410 + if (!dwatch)
412 + Log::debug ("New DirWatch for %s (%x %x)\n",
413 + notify_dir, (int)stat.st_dev, (int)stat.st_ino);
414 + dwatch = new DirWatch;
415 + dwatch->watches = NULL;
416 + dwatch->hash_link = NULL;
417 + dwatch->dir_dev = stat.st_dev;
418 + dwatch->dir_ino = stat.st_ino;
420 + dwatch->fd = open(notify_dir, O_RDONLY);
421 + fcntl (dwatch->fd, F_SETSIG, SIGRTMIN);
422 + if (fcntl (dwatch->fd, F_NOTIFY,
423 + (DN_MODIFY|DN_CREATE|DN_DELETE|DN_RENAME|DN_ATTRIB)
424 + | DN_MULTISHOT) == -1) {
425 + return BAD;
427 + hash_dirwatch (dwatch);
430 + fw = lookup_filewatch (file_dev, file_ino);
431 + if (fw && fw->dir_watch == dwatch)
432 + return OK;
434 + // No old FileWatch, need to add one:
435 + Log::debug("New FileWatch for %x %x\n", (int)file_dev, (int)file_ino);
436 + fw = new FileWatch;
437 + fw->next = dwatch->watches;
438 + dwatch->watches = fw;
439 + fw->file_dev = file_dev;
440 + fw->file_ino = file_ino;
441 + fw->dir_watch = dwatch;
442 + hash_filewatch(fw);
443 + return OK;
446 +char *
447 +dirname_dup (const char *name)
449 + char *copy = strdup(name);
450 + char *res = dirname(copy);
451 + res = strdup(res);
452 + free (copy);
453 + return res;
456 +DNotify::Status
457 +DNotify::express(const char *name, struct stat *status)
459 + struct stat stat;
460 + char *notify_dir;
461 + int res;
462 + Status s;
463 + dev_t dev;
464 + ino_t ino;
466 + Log::debug("express() name: %s\n", name);
468 + if (!is_active())
469 + return BAD;
471 + if (::lstat (name, &stat) == -1)
472 + return BAD;
474 + dev = stat.st_dev;
475 + ino = stat.st_ino;
477 + if ((stat.st_mode & S_IFMT) != S_IFDIR)
478 + notify_dir = dirname_dup (name);
479 + else
480 + notify_dir = (char *)name;
482 + s = watch_dir (notify_dir, dev, ino);
483 + if (notify_dir != name)
484 + free (notify_dir);
485 + if (s)
486 + return s;
488 + // Check for a race condition; if someone removed or changed the
489 + // file at the same time that we are expressing interest in it,
490 + // revoke the interest so we don't get notifications about changes
491 + // to a recycled inode that we don't otherwise care about.
492 + //
493 + struct stat st;
494 + if (status == NULL) {
495 + status = &st;
497 + if (::lstat(name, status) == -1) {
498 + Log::perror("stat on \"%s\" failed", name);
499 + revoke(name, stat.st_dev, stat.st_ino);
500 + return BAD;
502 + if (status->st_dev != stat.st_dev
503 + || status->st_ino != stat.st_ino) {
504 + Log::error("File \"%s\" changed between express and stat",
505 + name);
506 + revoke(name, stat.st_dev, stat.st_ino);
507 + return BAD;
508 + }
510 + Log::debug("told dnotify to monitor \"%s\" = dev %d/%d, ino %d", name,
511 + major(status->st_dev), minor(status->st_dev),
512 + status->st_ino);
513 + return OK;
516 +DNotify::Status
517 +DNotify::revoke(const char *name, dev_t dev, ino_t ino)
519 + FileWatch *fwatch;
520 + DirWatch *dwatch;
522 + Log::debug("revoke() name: %s, dev: %x, ino: %x\n", name, dev, ino);
524 + if (!is_active())
525 + return BAD;
527 + // Lookup FileWatch by dev:ino, and its DirWatch.
528 + fwatch = lookup_filewatch (dev, ino);
529 + if (fwatch == NULL)
530 + return BAD;
532 + dwatch = fwatch->dir_watch;
534 + // delete FileWatch, if last FileWatch: close fd, delete DirWatch
535 + Log::debug ("Destroying FileWatch for (%x %x)\n",
536 + (int)fwatch->file_dev, (int)fwatch->file_ino);
537 + FileWatch **p;
538 + for (p=&dwatch->watches; *p; p=&(*p)->next)
540 + if (*p == fwatch)
542 + *p = (*p)->next;
543 + break;
546 + unhash_filewatch(fwatch);
547 + delete fwatch;
548 + if (dwatch->watches == NULL)
550 + Log::debug ("Destroying DirWatch for (%x %x)\n",
551 + (int)dwatch->dir_dev, (int)dwatch->dir_ino);
552 + close(dwatch->fd);
553 + unhash_dirwatch(dwatch);
554 + delete dwatch;
557 + return OK;
561 +void
562 +DNotify::all_watches_changed(void)
564 + int i;
565 + FileWatch *fw;
567 + for (i=0; i<FILE_HASHSIZE; i++)
569 + fw = file_hash[i];
570 + while (fw)
572 + (*ehandler)(fw->file_dev, fw->file_ino, CHANGE);
574 + fw = fw->hash_link;
580 +void
581 +DNotify::read_handler(int fd, void *)
583 + static char readbuf[5000];
584 + DirWatch *dw;
585 + FileWatch *fw;
586 + int snap_queue_tail;
587 + int last_fd;
589 + int rc = read(fd, readbuf, sizeof readbuf);
590 + queue_changed = 0;
591 + if (rc < 0)
592 + Log::perror("pipe read");
593 + else if (queue_overflowed)
595 + // There is a *slight* race condition here. Between reading
596 + // the queue_overflow flag and resetting it. But it doesn't
597 + // matter, since I'm gonna handle the overflow after reseting
598 + // anyway.
599 + queue_overflowed = false;
601 + // We're soon gonna check all watches anyway, so
602 + // get rid of the current queue
603 + queue_head = queue_tail;
605 + all_watches_changed ();
607 + else
609 + // Don't read events that happen later than
610 + // the initial read. (Otherwise skipping fd's
611 + // might miss some changes).
612 + snap_queue_tail = queue_tail;
613 + last_fd = -1;
614 + while (queue_head != snap_queue_tail)
616 + fd = change_queue[queue_head];
617 + queue_head = (queue_head + 1) % QUEUESIZE;
619 + // Skip multiple changes to the same fd
620 + if (fd != last_fd)
622 + dw = lookup_dirwatch (fd);
623 + if (dw)
625 + int n_watches, i;
626 + ChangeEventData *data;
628 + Log::debug("dnotify said dev %d/%d, ino %ld changed",
629 + major(dw->dir_dev), minor(dw->dir_dev), dw->dir_ino);
631 + n_watches = 0;
632 + for (fw=dw->watches; fw; fw=fw->next)
633 + n_watches++;
635 + data = new ChangeEventData[n_watches];
637 + i = 0;
638 + for (fw=dw->watches; fw; fw=fw->next)
640 + data[i].file_dev = fw->file_dev;
641 + data[i].file_ino = fw->file_ino;
642 + i++;
645 + for (i = 0; i < n_watches; i++)
647 + (*ehandler)(data[i].file_dev, data[i].file_ino, CHANGE);
650 + delete[] data;
653 + last_fd = fd;
658 diff -Naur fam-2.7.0.orig/src/DNotify.h fam-2.7.0/src/DNotify.h
659 --- fam-2.7.0.orig/src/DNotify.h 1970-01-01 00:00:00.000000000 +0000
660 +++ fam-2.7.0/src/DNotify.h 2004-03-15 21:31:34.546060811 +0000
661 @@ -0,0 +1,98 @@
662 +// Copyright (C) 2001 Red Hat, Inc. All Rights Reserved.
663 +// Copyright (C) 1999 Silicon Graphics, Inc. All Rights Reserved.
665 +// This program is free software; you can redistribute it and/or modify it
666 +// under the terms of version 2 of the GNU General Public License as
667 +// published by the Free Software Foundation.
669 +// This program is distributed in the hope that it would be useful, but
670 +// WITHOUT ANY WARRANTY; without even the implied warranty of
671 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, any
672 +// license provided herein, whether implied or otherwise, is limited to
673 +// this program in accordance with the express provisions of the GNU
674 +// General Public License. Patent licenses, if any, provided herein do not
675 +// apply to combinations of this program with other product or programs, or
676 +// any other product whatsoever. This program is distributed without any
677 +// warranty that the program is delivered free of the rightful claim of any
678 +// third person by way of infringement or the like. See the GNU General
679 +// Public License for more details.
681 +// You should have received a copy of the GNU General Public License along
682 +// with this program; if not, write the Free Software Foundation, Inc., 59
683 +// Temple Place - Suite 330, Boston MA 02111-1307, USA.
685 +#ifndef DNotify_included
686 +#define DNotify_included
688 +#include "config.h"
689 +#include "Monitor.h"
690 +#include <signal.h>
692 +// DNotify is an object encapsulating the dnotify linux fcntl.
693 +// It "emulates" the IMon interface.
694 +// There can only be one instantiation of the DNotify object.
696 +// The user of this object uses express() and revoke() to
697 +// express/revoke interest in a file. There is also
698 +// a callback, the EventHandler. When an dnotify event comes in,
699 +// the EventHandler is called.
701 +// The user of the DNotify object is the Interest class.
703 +class DNotify : public Monitor {
704 +public:
705 + DNotify(EventHandler h);
706 + ~DNotify();
708 + static bool is_active();
710 + virtual Status express(const char *name, struct stat *stat_return);
711 + virtual Status revoke(const char *name, dev_t dev, ino_t ino);
713 +private:
714 + struct FileWatch;
715 + struct DirWatch;
716 + struct ChangeEventData;
718 + // Class Variables
719 + enum { QUEUESIZE = 1024 };
720 + static int pipe_write_fd;
721 + static int pipe_read_fd;
722 + static int change_queue[QUEUESIZE];
723 + static volatile sig_atomic_t DNotify::queue_overflowed;
724 + static volatile sig_atomic_t DNotify::queue_changed;
725 + static volatile int queue_head; // Only modified by read handler
726 + static volatile int queue_tail; // Only modified by signal handler
727 + static EventHandler ehandler;
728 + static void overflow_signal_handler(int sig, siginfo_t *si, void *data);
729 + static void signal_handler(int sig, siginfo_t *si, void *data);
730 + static void read_handler(int fd, void *closure);
732 + enum { DIR_HASHSIZE = 367 };
733 + static DirWatch *dir_hash[DIR_HASHSIZE];
734 + enum { FILE_HASHSIZE = 823 };
735 + static FileWatch *file_hash[FILE_HASHSIZE];
737 + static DirWatch **dir_hashchain(int fd)
738 + { return &dir_hash[(unsigned) (fd) % DIR_HASHSIZE]; }
739 + static FileWatch **file_hashchain(dev_t d, ino_t i)
740 + { return &file_hash[(unsigned) (d+i) % FILE_HASHSIZE]; }
742 + static DirWatch *lookup_dirwatch (int fd);
743 + static DirWatch *lookup_dirwatch (dev_t dir_dev, ino_t dir_ino);
744 + static FileWatch *lookup_filewatch (dev_t file_dev, ino_t file_ino);
745 + static void hash_dirwatch(DirWatch *w);
746 + static void hash_filewatch(FileWatch *w);
747 + static void unhash_dirwatch(DirWatch *w);
748 + static void unhash_filewatch(FileWatch *w);
749 + static Status watch_dir(const char *notify_dir, dev_t file_dev, ino_t file_ino);
751 + static void all_watches_changed(void);
753 + DNotify(const DNotify&); // Do not copy
754 + DNotify & operator = (const DNotify&); // or assign.
757 +#endif /* !IMon_included */
760 diff -Naur fam-2.7.0.orig/src/IMon.h fam-2.7.0/src/IMon.h
761 --- fam-2.7.0.orig/src/IMon.h 2003-01-18 14:18:12.000000000 +0000
762 +++ fam-2.7.0/src/IMon.h 2004-03-15 21:31:34.558058615 +0000
763 @@ -24,10 +24,7 @@
764 #define IMon_included
766 #include "config.h"
767 -#include <sys/stat.h>
768 -#include <sys/types.h>
770 -#include "Boolean.h"
771 +#include "Monitor.h"
773 struct stat;
775 @@ -41,25 +38,18 @@
777 // The user of the IMon object is the Interest class.
779 -class IMon {
780 +class IMon : public Monitor {
782 public:
784 - enum Status { OK = 0, BAD = -1 };
785 - enum Event { EXEC, EXIT, CHANGE };
787 - typedef void (*EventHandler)(dev_t, ino_t, int event);
789 IMon(EventHandler h);
790 ~IMon();
792 static bool is_active();
794 - Status express(const char *name, struct stat *stat_return);
795 - Status revoke(const char *name, dev_t dev, ino_t ino);
796 + virtual Status express(const char *name, struct stat *stat_return);
797 + virtual Status revoke(const char *name, dev_t dev, ino_t ino);
799 private:
801 // Class Variables
803 static int imonfd;
804 diff -Naur fam-2.7.0.orig/src/Interest.c++ fam-2.7.0/src/Interest.c++
805 --- fam-2.7.0.orig/src/Interest.c++ 2003-01-18 14:18:12.000000000 +0000
806 +++ fam-2.7.0/src/Interest.c++ 2004-03-15 21:31:34.550060079 +0000
807 @@ -42,12 +42,21 @@
808 #include "Event.h"
809 #include "FileSystem.h"
810 #include "IMon.h"
811 +#include "DNotify.h"
812 #include "Log.h"
813 #include "Pollster.h"
814 #include "timeval.h"
816 Interest *Interest::hashtable[];
817 -IMon Interest::imon(imon_handler);
819 +#ifdef USE_DNOTIFY
820 +static DNotify dnotify(Interest::monitor_handler);
821 +Monitor * Interest::monitor = &dnotify;
822 +#else
823 +static IMon imon(Interest::monitor_handler);
824 +Monitor * Interest::monitor = &imon;
825 +#endif
827 bool Interest::xtab_verification = true;
829 Interest::Interest(const char *name, FileSystem *fs, in_addr host, ExportVerification ev)
830 @@ -60,10 +69,10 @@
831 mypath_exported_to_host(ev == NO_VERIFY_EXPORTED)
833 memset(&old_stat, 0, sizeof(old_stat));
834 - IMon::Status s = IMon::BAD;
836 - s = imon.express(name, &old_stat);
837 - if (s != IMon::OK)
838 + Monitor::Status s = Monitor::BAD;
839 + s = monitor->express(name, &old_stat);
840 + if (s != Monitor::OK)
841 { int rc = lstat(name, &old_stat);
842 if (rc < 0)
843 { Log::info("can't lstat %s", name);
844 @@ -100,7 +109,7 @@
846 #endif
848 - if (exported_to_host()) fs->ll_monitor(this, s == IMon::OK);
849 + if (exported_to_host()) fs->ll_monitor(this, s == Monitor::OK);
852 Interest::~Interest()
853 @@ -128,7 +137,7 @@
854 pp = &p->hashlink; // move to next element
856 if (!found_same)
857 - (void) imon.revoke(name(), dev, ino);
858 + (void) monitor->revoke(name(), dev, ino);
862 @@ -147,7 +156,7 @@
864 // Express interest.
865 IMon::Status s = IMon::BAD;
866 - s = imon.express(name(), NULL);
867 + s = monitor->express(name(), NULL);
868 if (s != IMon::OK) {
869 return true;
871 @@ -248,23 +257,23 @@
874 void
875 -Interest::imon_handler(dev_t device, ino_t inumber, int event)
876 +Interest::monitor_handler(dev_t device, ino_t inumber, int event)
878 assert(device || inumber);
880 for (Interest *p = *hashchain(device, inumber), *next = p; p; p = next)
881 { next = p->hashlink;
882 if (p->ino == inumber && p->dev == device)
883 - { if (event == IMon::EXEC)
884 + { if (event == Monitor::EXEC)
885 { p->cur_exec_state = EXECUTING;
886 (void) p->report_exec_state();
888 - else if (event == IMon::EXIT)
889 + else if (event == Monitor::EXIT)
890 { p->cur_exec_state = NOT_EXECUTING;
891 (void) p->report_exec_state();
893 else
894 - { assert(event == IMon::CHANGE);
895 + { assert(event == Monitor::CHANGE);
896 p->scan();
899 diff -Naur fam-2.7.0.orig/src/Interest.h fam-2.7.0/src/Interest.h
900 --- fam-2.7.0.orig/src/Interest.h 2003-01-18 14:18:12.000000000 +0000
901 +++ fam-2.7.0/src/Interest.h 2004-03-15 21:31:34.560058249 +0000
902 @@ -32,7 +32,7 @@
904 class Event;
905 class FileSystem;
906 -class IMon;
907 +class Monitor;
908 struct stat;
910 // Interest -- abstract base class for filesystem entities of interest.
911 @@ -74,7 +74,7 @@
913 // Public Class Method
915 - static void imon_handler(dev_t, ino_t, int event);
916 + static void monitor_handler(dev_t, ino_t, int event);
918 static void enable_xtab_verification(bool enable);
920 @@ -121,7 +121,7 @@
922 // Class Variables
924 - static IMon imon;
925 + static Monitor *monitor;
926 static Interest *hashtable[HASHSIZE];
927 static bool xtab_verification;
929 diff -Naur fam-2.7.0.orig/src/Makefile.am fam-2.7.0/src/Makefile.am
930 --- fam-2.7.0.orig/src/Makefile.am 2003-01-19 12:00:17.000000000 +0000
931 +++ fam-2.7.0/src/Makefile.am 2004-03-15 21:31:34.562057882 +0000
932 @@ -71,7 +71,11 @@
933 main.c++ \
934 timeval.c++ \
935 timeval.h \
936 - @MONITOR_FUNCS@.c++
937 + Monitor.h \
938 + DNotify.h \
939 + DNotify.c++ \
940 + @MONITOR_FUNCS@.c++
942 -EXTRA_famd_SOURCES = IMonIrix.c++ IMonLinux.c++ IMonNone.c++
943 +EXTRA_famd_SOURCES = IMonIrix.c++ IMonLinux.c++ IMonNone.c++ DNotify.c++ \
944 + DNotify.h Monitor.h
946 diff -Naur fam-2.7.0.orig/src/Monitor.h fam-2.7.0/src/Monitor.h
947 --- fam-2.7.0.orig/src/Monitor.h 1970-01-01 00:00:00.000000000 +0000
948 +++ fam-2.7.0/src/Monitor.h 2004-03-15 21:31:34.564057516 +0000
949 @@ -0,0 +1,57 @@
950 +// Copyright (C) 2001 Red Hat, Inc. All Rights Reserved.
951 +// Copyright (C) 1999 Silicon Graphics, Inc. All Rights Reserved.
952 +//
953 +// This program is free software; you can redistribute it and/or modify it
954 +// under the terms of version 2 of the GNU General Public License as
955 +// published by the Free Software Foundation.
957 +// This program is distributed in the hope that it would be useful, but
958 +// WITHOUT ANY WARRANTY; without even the implied warranty of
959 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, any
960 +// license provided herein, whether implied or otherwise, is limited to
961 +// this program in accordance with the express provisions of the GNU
962 +// General Public License. Patent licenses, if any, provided herein do not
963 +// apply to combinations of this program with other product or programs, or
964 +// any other product whatsoever. This program is distributed without any
965 +// warranty that the program is delivered free of the rightful claim of any
966 +// third person by way of infringement or the like. See the GNU General
967 +// Public License for more details.
969 +// You should have received a copy of the GNU General Public License along
970 +// with this program; if not, write the Free Software Foundation, Inc., 59
971 +// Temple Place - Suite 330, Boston MA 02111-1307, USA.
973 +#ifndef Monitor_included
974 +#define Monitor_included
976 +#include "config.h"
977 +#include <sys/stat.h>
978 +#include <sys/types.h>
980 +struct stat;
982 +// Monitor is an abstract baseclass for differend file monitoring
983 +// systems. The original system used was IMon, and the Montor API
984 +// is heavily influenced by that.
985 +// There can only be one instantiation of the Monitor object.
987 +// The user of this object uses express() and revoke() to
988 +// express/revoke interest in a file to imon. There is also
989 +// a callback, the EventHandler. When an event comes in,
990 +// the EventHandler is called.
992 +// The main implementers of the Monitor class is IMon and DNotify
994 +class Monitor {
995 +public:
997 + enum Status { OK = 0, BAD = -1 };
998 + enum Event { EXEC, EXIT, CHANGE };
1000 + typedef void (*EventHandler)(dev_t, ino_t, int event);
1002 + virtual Status express(const char *name, struct stat *stat_return) = 0;
1003 + virtual Status revoke(const char *name, dev_t dev, ino_t ino) = 0;
1006 +#endif /* !Monitor_included */