From 2ba0ea32543e674b2817a0c225cb66f46034aa79 Mon Sep 17 00:00:00 2001 From: dockes Date: Sun, 24 Dec 2006 07:40:26 +0000 Subject: [PATCH] option -x to disable x11 session monitoring --- src/configure | 13 ++++++++++++- src/configure.ac | 11 ++++++++++- src/doc/man/recollindex.1 | 13 +++++++++++-- src/doc/user/usermanual.sgml | 8 ++++---- src/index/rclmon.h | 7 +++++-- src/index/rclmonprc.cpp | 14 +++++++++++--- src/index/recollindex.cpp | 17 +++++++++++++---- 7 files changed, 66 insertions(+), 17 deletions(-) diff --git a/src/configure b/src/configure index 604ee420..4fbd5cd5 100755 --- a/src/configure +++ b/src/configure @@ -1454,6 +1454,12 @@ echo "$as_me: error: fam library not found" >&2;} fi fi +if test -f /usr/include/sys/inotify.h -a X$withFam = Xno ; then + inot_default=yes +else + inot_default=no +fi + # Real time monitoring with inotify # Check whether --with-inotify or --without-inotify was given. @@ -1461,10 +1467,12 @@ if test "${with_inotify+set}" = set; then withval="$with_inotify" withInotify=$withval else - withInotify=no + withInotify=$inot_default fi; if test X$withInotify != Xno ; then + { echo "$as_me:$LINENO: Enabled support for inotify monitoring" >&5 +echo "$as_me: Enabled support for inotify monitoring" >&6;} cat >>confdefs.h <<\_ACEOF #define RCL_MONITOR 1 @@ -1475,6 +1483,9 @@ cat >>confdefs.h <<\_ACEOF #define RCL_USE_INOTIFY 1 _ACEOF +else + { echo "$as_me:$LINENO: inotify monitoring disabled" >&5 +echo "$as_me: inotify monitoring disabled" >&6;} fi ##### Look for iconv. We first look for libiconv in /usr/local/lib:/usr/lib diff --git a/src/configure.ac b/src/configure.ac index d38516b8..1016d5a3 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -91,15 +91,24 @@ if test X$withFam != Xno ; then fi fi +if test -f /usr/include/sys/inotify.h -a X$withFam = Xno ; then + inot_default=yes +else + inot_default=no +fi + # Real time monitoring with inotify AC_ARG_WITH(inotify, AC_HELP_STRING([--with-inotify], [Use inotify for almost real time indexing of modified files.]), - withInotify=$withval, withInotify=no) + withInotify=$withval, withInotify=$inot_default) if test X$withInotify != Xno ; then + AC_MSG_NOTICE([enabled support for inotify monitoring]) AC_DEFINE(RCL_MONITOR, 1, [Real time monitoring option]) AC_DEFINE(RCL_USE_INOTIFY, 1, [Compile the inotify interface]) +else + AC_MSG_NOTICE([inotify monitoring disabled]) fi ##### Look for iconv. We first look for libiconv in /usr/local/lib:/usr/lib diff --git a/src/doc/man/recollindex.1 b/src/doc/man/recollindex.1 index 18b73a48..e21a8e57 100644 --- a/src/doc/man/recollindex.1 +++ b/src/doc/man/recollindex.1 @@ -1,4 +1,4 @@ -.\" $Id: recollindex.1,v 1.4 2006-12-22 11:01:28 dockes Exp $ (C) 2005 J.F.Dockes\$ +.\" $Id: recollindex.1,v 1.5 2006-12-24 07:40:26 dockes Exp $ (C) 2005 J.F.Dockes\$ .TH RECOLLINDEX 1 "8 January 2006" .SH NAME recollindex \- indexing command for the Recoll full text search system @@ -23,6 +23,9 @@ recollindex \- indexing command for the Recoll full text search system [ .B -D ] +[ +.B -x +] .br .B recollindex [ @@ -90,7 +93,13 @@ is given, it will stay in the foreground. Option .B -w can be used to specify that the program should sleep for the -specified time before indexing. The default value is 60. +specified time before indexing begins. The default value is 60. The daemon +normally monitors the X11 session and exits when it is reset. +Option +.B +-x +disables this X11 session monitoring (daemon will stay alive even if it +cannot connect to the X11 server). .PP The other modes are useful mainly for testing. diff --git a/src/doc/user/usermanual.sgml b/src/doc/user/usermanual.sgml index 3d4052e3..3cbe65af 100644 --- a/src/doc/user/usermanual.sgml +++ b/src/doc/user/usermanual.sgml @@ -24,7 +24,7 @@ Dockes - $Id: usermanual.sgml,v 1.32 2006-12-22 11:01:28 dockes Exp $ + $Id: usermanual.sgml,v 1.33 2006-12-24 07:40:26 dockes Exp $ This document introduces full text search notions @@ -423,7 +423,7 @@ recoll Real time monitoring/indexing is performed by starting the recollindex -m command. With this option, recollindex will detach from the terminal and - become a daemon, forever monitoring file changes and updating + become a daemon, permanently monitoring file changes and updating the index. The package must have been @@ -431,8 +431,8 @@ recoll with option --with-fam or --with-inotify for the monitoring code and option to be enabled in - recollindex. This is not currently the - default. + recollindex. The default is currently to + include inotify monitoring on systems that support it. The rclmon.sh script can be used to easily start and stop the daemon. It can be found in the diff --git a/src/index/rclmon.h b/src/index/rclmon.h index b9de4dbb..6f68f200 100644 --- a/src/index/rclmon.h +++ b/src/index/rclmon.h @@ -2,7 +2,7 @@ #define _RCLMON_H_INCLUDED_ #include "autoconfig.h" #ifdef RCL_MONITOR -/* @(#$Id: rclmon.h,v 1.7 2006-11-07 16:51:45 dockes Exp $ (C) 2006 J.F.Dockes */ +/* @(#$Id: rclmon.h,v 1.8 2006-12-24 07:40:26 dockes Exp $ (C) 2006 J.F.Dockes */ /** * Definitions for the real-time monitoring recoll. * We're interested in file modifications, deletions and renaming. @@ -37,6 +37,8 @@ class RclMonEvent { RclMonEvent() : m_etyp(RCLEVT_NONE) {} }; +enum RclMonitorOption {RCLMON_NONE=0, RCLMON_NOFORK=1, RCLMON_NOX11=2}; + /** * Monitoring event queue. This is the shared object between the main thread * (which does the actual indexing work), and the monitoring thread which @@ -60,6 +62,7 @@ class RclMonEventQueue { bool ok(); bool empty(); RclMonEvent pop(); + void setopts(int opts); // Convenience function for initially communicating config to mon thr void setConfig(RclConfig *conf); @@ -70,7 +73,7 @@ class RclMonEventQueue { }; /** Start monitoring on the topdirs described in conf */ -extern bool startMonitor(RclConfig *conf, bool nofork); +extern bool startMonitor(RclConfig *conf, int flags); /** Main routine for the event receiving thread */ extern void *rclMonRcvRun(void *); diff --git a/src/index/rclmonprc.cpp b/src/index/rclmonprc.cpp index a1b72ad2..9c69725a 100644 --- a/src/index/rclmonprc.cpp +++ b/src/index/rclmonprc.cpp @@ -2,7 +2,7 @@ #ifdef RCL_MONITOR #ifndef lint -static char rcsid[] = "@(#$Id: rclmonprc.cpp,v 1.9 2006-12-23 13:07:21 dockes Exp $ (C) 2006 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclmonprc.cpp,v 1.10 2006-12-24 07:40:26 dockes Exp $ (C) 2006 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -47,6 +47,7 @@ typedef map queue_type; */ class RclEQData { public: + int m_opts; queue_type m_queue; RclConfig *m_config; bool m_ok; @@ -77,6 +78,12 @@ bool RclMonEventQueue::empty() return m_data == 0 ? true : m_data->m_queue.empty(); } +void RclMonEventQueue::setopts(int opts) +{ + if (m_data) + m_data->m_opts = opts; +} + // Must be called with the queue locked RclMonEvent RclMonEventQueue::pop() { @@ -166,7 +173,7 @@ bool RclMonEventQueue::ok() LOGDEB(("RclMonEventQueue: not ok: bad state\n")); return false; } - if (!x11IsAlive()) { + if (!(m_data->m_opts & RCLMON_NOX11) && !x11IsAlive()) { LOGDEB(("RclMonEventQueue: not ok: x11\n")); return false; } @@ -268,7 +275,7 @@ static void processunlock() pthread_t rcv_thrid; -bool startMonitor(RclConfig *conf, bool nofork) +bool startMonitor(RclConfig *conf, int opts) { if (!processlock(conf->getConfDir())) { LOGERR(("startMonitor: lock error. Other process running ?\n")); @@ -277,6 +284,7 @@ bool startMonitor(RclConfig *conf, bool nofork) atexit(processunlock); rclEQ.setConfig(conf); + rclEQ.setopts(opts); if (pthread_create(&rcv_thrid, 0, &rclMonRcvRun, &rclEQ) != 0) { LOGERR(("startMonitor: cant create event-receiving thread\n")); return false; diff --git a/src/index/recollindex.cpp b/src/index/recollindex.cpp index b6f6a0f1..e65ccdbb 100644 --- a/src/index/recollindex.cpp +++ b/src/index/recollindex.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.29 2006-12-21 09:22:31 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.30 2006-12-24 07:40:26 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -217,6 +217,7 @@ static int op_flags; #define OPT_D 0x100 #define OPT_e 0x200 #define OPT_w 0x400 +#define OPT_x 0x800 static const char usage [] = "\n" @@ -226,8 +227,10 @@ static const char usage [] = " Index everything according to configuration file\n" " -z : reset database before starting indexation\n" #ifdef RCL_MONITOR -"recollindex -m [-D]\n" -" Perform real time indexation. Don't become a daemon if -D is set\n" +"recollindex -m [-w ] -x [-D]\n" +" Perform real time indexation. Don't become a daemon if -D is set.\n" +" -w sets number of seconds to wait before starting.\n" +" -x disables exit on end of x11 session\n" #endif "recollindex -e \n" " Purge data for individual files. No stem database updates\n" @@ -288,6 +291,7 @@ int main(int argc, const char **argv) Usage(); argc--; goto b1; #endif + case 'x': op_flags |= OPT_x; break; case 'z': op_flags |= OPT_z; break; default: Usage(); break; } @@ -352,7 +356,12 @@ int main(int argc, const char **argv) confindexer = new ConfIndexer(config, &updater); confindexer->index(rezero); delete confindexer; - if (startMonitor(config, (op_flags&OPT_D)!=0)) + int opts = RCLMON_NONE; + if (op_flags & OPT_D) + opts |= RCLMON_NOFORK; + if (op_flags & OPT_x) + opts |= RCLMON_NOX11; + if (startMonitor(config, opts)) exit(0); exit(1); #endif // MONITOR