* tailing reliable realtime streaming feeder for inn
* filemon.c - file monitoring (inotify, kqueue, poll, etc.)
*
- * Copyright (C) 2010 Ian Jackson <ijackson@chiark.greenend.org.uk>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * (I believe that when you compile and link this as part of the inn2
- * build, with the Makefile runes I have provided, all the libraries
- * and files which end up included in innduct are licence-compatible
- * with GPLv3. If not then please let me know. -Ian Jackson.)
+ * Copyright Ian Jackson <ijackson@chiark.greenend.org.uk>
+ * and contributors; see LICENCE.txt.
+ * SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "innduct.h"
if (pf->wd < 0) sysdie("filemon inotify: inotify_add_watch %s", ipf->path);
LIST_ADDHEAD(filemon_inotify_watches, pf);
- dbg("filemon inotify: startfile %p wd=%d pf=%p", ipf, wd, pf);
+ dbg("filemon inotify: startfile %p wd=%d pf=%p", ipf, pf->wd, pf);
}
static void filemon_method_stopfile(InputFile *ipf, Filemon_Perfile *pf) {
static void *filemon_inotify_readable(oop_source *lp, int fd,
oop_event e, void *u) {
struct inotify_event iev;
+ InputFile *ipf;
for (;;) {
int r= read(filemon_inotify_fd, &iev, sizeof(iev));
if (r==-1) {
Filemon_Perfile *pf;
FOR_LIST_NODE(pf, filemon_inotify_watches)
if (pf->wd == iev.wd) goto found;
- crash("inotify read event on unknown wd=%p", iev.wd);
+ /* Linux seems to remember events and can produce them even after
+ * you've removed the watch. This means that we can't spot bugs
+ * where we lose track of our watches and have to just regard
+ * unexpected random watch events as normal. It's not a
+ * correctness problem as the watch is just a prod to read a file,
+ * which is harmless if it does not need to be read. */
+ dbg("filemon inotify: read event with unknown wd=%d", iev.wd);
+ continue;
+
found:
- InputFile *ipf= pf->ipf;
+ ipf= pf->ipf;
/*dbg("filemon inotify readable read %p wd=%d", ipf, iev.wd);*/
tailing_make_readable(ipf);
}
LIST_INIT(filemon_inotify_watches);
filemon_inotify_fd= inotify_init();
if (filemon_inotify_fd<0) {
- syswarn("filemon/inotify: inotify_init failed");
+ syswarn("filemon inotify: inotify_init failed");
return 0;
}
xsetnonblock(filemon_inotify_fd, 1);
loop->on_fd(loop, filemon_inotify_fd, OOP_READ, filemon_inotify_readable, 0);
- dbg("filemon inotify init filemon_inotify_fd=%d", filemon_inotify_fd);
+ dbg("filemon inotify: init filemon_inotify_fd=%d", filemon_inotify_fd);
return 1;
}
void filemon_method_dump_info(FILE *f) {
- int i;
fprintf(f,"inotify");
DUMPV("%d",,filemon_inotify_fd);
DUMPV("%d",filemon_inotify_watches.,count);
struct Filemon_Perfile { int dummy; };
int filemon_method_init(void) {
- warn("filemon/dummy: no filemon method compiled in");
+ warn("filemon dummy: no filemon method compiled in");
return 0;
}
static void filemon_method_startfile(InputFile *ipf, Filemon_Perfile *pf) { }