diff --git a/src/index/rclmon.h b/src/index/rclmon.h index 649eddb9..4cf5091c 100644 --- a/src/index/rclmon.h +++ b/src/index/rclmon.h @@ -103,6 +103,9 @@ extern bool startMonitor(RclConfig *conf, int flags); /** Main routine for the event receiving thread */ extern void *rclMonRcvRun(void *); +/** Utility routine to try and set ionice */ +extern void rclMonIonice(RclConfig *conf); + // Specific debug macro for monitor synchronization events #define MONDEB LOGDEB2 diff --git a/src/index/rclmonprc.cpp b/src/index/rclmonprc.cpp index aa05c540..8b174e85 100644 --- a/src/index/rclmonprc.cpp +++ b/src/index/rclmonprc.cpp @@ -42,6 +42,7 @@ #include "recollindex.h" #include "pathut.h" #include "x11mon.h" +#include "rclionice.h" typedef unsigned long mttcast; @@ -545,4 +546,15 @@ bool startMonitor(RclConfig *conf, int opts) LOGDEB(("Monitor: returning\n")); return true; } + + +void rclMonIonice(RclConfig *config) +{ + string clss, classdata; + if (!config->getConfParam("monioniceclass", clss) || clss.empty()) + clss = "3"; + config->getConfParam("monioniceclassdata", classdata); + rclionice(clss, classdata); +} + #endif // RCL_MONITOR diff --git a/src/index/recollindex.cpp b/src/index/recollindex.cpp index c6cc9b6c..1c3e552c 100644 --- a/src/index/recollindex.cpp +++ b/src/index/recollindex.cpp @@ -294,6 +294,8 @@ int main(int argc, const char **argv) if (setpriority(PRIO_PROCESS, 0, 20) != 0) { LOGINFO(("recollindex: can't setpriority(), errno %d\n", errno)); } + // Try to ionice. This does not work on all platforms + rclMonIonice(config); if (op_flags & (OPT_i|OPT_e)) { lockorexit(&pidfile); @@ -350,12 +352,16 @@ int main(int argc, const char **argv) exit(1); } } + pidfile.write_pid(); + // Not too sure if I have to redo the nice thing after daemon(), // can't hurt anyway (easier than testing on all platforms...) if (setpriority(PRIO_PROCESS, 0, 20) != 0) { LOGINFO(("recollindex: can't setpriority(), errno %d\n", errno)); } - pidfile.write_pid(); + // Try to ionice. This does not work on all platforms + rclMonIonice(config); + if (sleepsecs > 0) { LOGDEB(("recollindex: sleeping %d\n", sleepsecs)); for (int i = 0; i < sleepsecs; i++) { diff --git a/src/lib/Makefile b/src/lib/Makefile index 21b940f5..b727333e 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -6,8 +6,8 @@ LIBS = librcl.a all: $(LIBS) -OBJS = rclaspell.o beaglequeuecache.o rclconfig.o rclinit.o textsplit.o unacpp.o beaglequeue.o csguess.o fsindexer.o indexer.o mimetype.o htmlparse.o myhtmlparse.o mimehandler.o internfile.o mh_exec.o mh_execm.o mh_html.o mh_mail.o mh_mbox.o mh_text.o docseq.o docseqdb.o docseqhist.o filtseq.o dynconf.o plaintorich.o recollq.o reslistpager.o sortseq.o wasastringtoquery.o wasatorcl.o rcldb.o rcldoc.o rclquery.o searchdata.o stemdb.o stoplist.o base64.o circache.o closefrom.o conftree.o copyfile.o debuglog.o execmd.o fstreewalk.o idfile.o fileudi.o md5.o mimeparse.o netcon.o pathut.o pxattr.o readfile.o smallut.o transcode.o wipedir.o x11mon.o mime-getpart.o mime-parsefull.o mime-parseonlyheader.o mime-printbody.o mime-printdoc.o mime-printheader.o mime.o convert.o iodevice.o iofactory.o -DEPS = rclaspell.dep.stamp beaglequeuecache.dep.stamp rclconfig.dep.stamp rclinit.dep.stamp textsplit.dep.stamp unacpp.dep.stamp beaglequeue.dep.stamp csguess.dep.stamp fsindexer.dep.stamp indexer.dep.stamp mimetype.dep.stamp htmlparse.dep.stamp myhtmlparse.dep.stamp mimehandler.dep.stamp internfile.dep.stamp mh_exec.dep.stamp mh_execm.dep.stamp mh_html.dep.stamp mh_mail.dep.stamp mh_mbox.dep.stamp mh_text.dep.stamp docseq.dep.stamp docseqdb.dep.stamp docseqhist.dep.stamp filtseq.dep.stamp dynconf.dep.stamp plaintorich.dep.stamp recollq.dep.stamp reslistpager.dep.stamp sortseq.dep.stamp wasastringtoquery.dep.stamp wasatorcl.dep.stamp rcldb.dep.stamp rcldoc.dep.stamp rclquery.dep.stamp searchdata.dep.stamp stemdb.dep.stamp stoplist.dep.stamp base64.dep.stamp circache.dep.stamp closefrom.dep.stamp conftree.dep.stamp copyfile.dep.stamp debuglog.dep.stamp execmd.dep.stamp fstreewalk.dep.stamp idfile.dep.stamp fileudi.dep.stamp md5.dep.stamp mimeparse.dep.stamp netcon.dep.stamp pathut.dep.stamp pxattr.dep.stamp readfile.dep.stamp smallut.dep.stamp transcode.dep.stamp wipedir.dep.stamp x11mon.dep.stamp mime-getpart.dep.stamp mime-parsefull.dep.stamp mime-parseonlyheader.dep.stamp mime-printbody.dep.stamp mime-printdoc.dep.stamp mime-printheader.dep.stamp mime.dep.stamp convert.dep.stamp iodevice.dep.stamp iofactory.dep.stamp +OBJS = rclaspell.o beaglequeuecache.o rclconfig.o rclinit.o textsplit.o unacpp.o beaglequeue.o csguess.o fsindexer.o indexer.o mimetype.o htmlparse.o myhtmlparse.o mimehandler.o internfile.o mh_exec.o mh_execm.o mh_html.o mh_mail.o mh_mbox.o mh_text.o docseq.o docseqdb.o docseqhist.o filtseq.o dynconf.o plaintorich.o recollq.o reslistpager.o sortseq.o wasastringtoquery.o wasatorcl.o rcldb.o rcldoc.o rclquery.o searchdata.o stemdb.o stoplist.o base64.o circache.o closefrom.o conftree.o copyfile.o debuglog.o execmd.o fstreewalk.o idfile.o fileudi.o md5.o mimeparse.o netcon.o pathut.o pxattr.o rclionice.o readfile.o smallut.o transcode.o wipedir.o x11mon.o mime-getpart.o mime-parsefull.o mime-parseonlyheader.o mime-printbody.o mime-printdoc.o mime-printheader.o mime.o convert.o iodevice.o iofactory.o +DEPS = rclaspell.dep.stamp beaglequeuecache.dep.stamp rclconfig.dep.stamp rclinit.dep.stamp textsplit.dep.stamp unacpp.dep.stamp beaglequeue.dep.stamp csguess.dep.stamp fsindexer.dep.stamp indexer.dep.stamp mimetype.dep.stamp htmlparse.dep.stamp myhtmlparse.dep.stamp mimehandler.dep.stamp internfile.dep.stamp mh_exec.dep.stamp mh_execm.dep.stamp mh_html.dep.stamp mh_mail.dep.stamp mh_mbox.dep.stamp mh_text.dep.stamp docseq.dep.stamp docseqdb.dep.stamp docseqhist.dep.stamp filtseq.dep.stamp dynconf.dep.stamp plaintorich.dep.stamp recollq.dep.stamp reslistpager.dep.stamp sortseq.dep.stamp wasastringtoquery.dep.stamp wasatorcl.dep.stamp rcldb.dep.stamp rcldoc.dep.stamp rclquery.dep.stamp searchdata.dep.stamp stemdb.dep.stamp stoplist.dep.stamp base64.dep.stamp circache.dep.stamp closefrom.dep.stamp conftree.dep.stamp copyfile.dep.stamp debuglog.dep.stamp execmd.dep.stamp fstreewalk.dep.stamp idfile.dep.stamp fileudi.dep.stamp md5.dep.stamp mimeparse.dep.stamp netcon.dep.stamp pathut.dep.stamp pxattr.dep.stamp rclionice.dep.stamp readfile.dep.stamp smallut.dep.stamp transcode.dep.stamp wipedir.dep.stamp x11mon.dep.stamp mime-getpart.dep.stamp mime-parsefull.dep.stamp mime-parseonlyheader.dep.stamp mime-printbody.dep.stamp mime-printdoc.dep.stamp mime-printheader.dep.stamp mime.dep.stamp convert.dep.stamp iodevice.dep.stamp iofactory.dep.stamp librcl.a : $(DEPS) $(OBJS) unac.o ar ru librcl.a $(OBJS) unac.o @@ -121,6 +121,8 @@ pathut.o : ../utils/pathut.cpp $(depth)/mk/localdefs $(CXX) $(ALL_CXXFLAGS) -c ../utils/pathut.cpp pxattr.o : ../utils/pxattr.cpp $(depth)/mk/localdefs $(CXX) $(ALL_CXXFLAGS) -c ../utils/pxattr.cpp +rclionice.o : ../utils/rclionice.cpp $(depth)/mk/localdefs + $(CXX) $(ALL_CXXFLAGS) -c ../utils/rclionice.cpp readfile.o : ../utils/readfile.cpp $(depth)/mk/localdefs $(CXX) $(ALL_CXXFLAGS) -c ../utils/readfile.cpp smallut.o : ../utils/smallut.cpp $(depth)/mk/localdefs @@ -316,6 +318,9 @@ pathut.dep.stamp : ../utils/pathut.cpp $(depth)/mk/localdefs pxattr.dep.stamp : ../utils/pxattr.cpp $(depth)/mk/localdefs $(CXX) -M $(ALL_CXXFLAGS) ../utils/pxattr.cpp > pxattr.dep touch pxattr.dep.stamp +rclionice.dep.stamp : ../utils/rclionice.cpp $(depth)/mk/localdefs + $(CXX) -M $(ALL_CXXFLAGS) ../utils/rclionice.cpp > rclionice.dep + touch rclionice.dep.stamp readfile.dep.stamp : ../utils/readfile.cpp $(depth)/mk/localdefs $(CXX) -M $(ALL_CXXFLAGS) ../utils/readfile.cpp > readfile.dep touch readfile.dep.stamp @@ -384,6 +389,7 @@ include mimeparse.dep include netcon.dep include pathut.dep include pxattr.dep +include rclionice.dep include readfile.dep include smallut.dep include transcode.dep diff --git a/src/lib/mkMake b/src/lib/mkMake index 1ea6d460..25140828 100755 --- a/src/lib/mkMake +++ b/src/lib/mkMake @@ -57,6 +57,7 @@ ${depth}/utils/mimeparse.cpp \ ${depth}/utils/netcon.cpp \ ${depth}/utils/pathut.cpp \ ${depth}/utils/pxattr.cpp \ +${depth}/utils/rclionice.cpp \ ${depth}/utils/readfile.cpp \ ${depth}/utils/smallut.cpp \ ${depth}/utils/transcode.cpp \ diff --git a/src/sampleconf/recoll.conf.in b/src/sampleconf/recoll.conf.in index 1876fa30..a80188f9 100644 --- a/src/sampleconf/recoll.conf.in +++ b/src/sampleconf/recoll.conf.in @@ -159,6 +159,11 @@ filtermaxseconds = 1200 # example: # mondelaypatterns = *.log:20 "*with spaces.*:30" +# ionice class for monitor (on platforms where this is supported) +# monioniceclass = 3 +# ionice class param for monitor (on platforms where this is supported) +# monioniceclassdata = + # If this is set, process the directory where Beagle Web browser plugins # copy visited pages for indexing. Of course, Beagle MUST NOT be running, # else things will behave strangely. diff --git a/src/utils/rclionice.cpp b/src/utils/rclionice.cpp new file mode 100644 index 00000000..37ab17ab --- /dev/null +++ b/src/utils/rclionice.cpp @@ -0,0 +1,53 @@ +/* Copyright (C) 2004 J.F.Dockes + * 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 2 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, write to the + * Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#include + +#include "rclionice.h" +#include "execmd.h" +#include "debuglog.h" + +bool rclionice(const string& clss, const string& cdata) +{ + string ionicexe; + if (!ExecCmd::which("ionice", ionicexe)) { + // ionice not found, bail out + LOGDEB(("rclionice: ionice not found\n")); + return false; + } + list args; + args.push_back("-c"); + args.push_back(clss); + + if (!cdata.empty()) { + args.push_back("-n"); + args.push_back(cdata); + } + + char cpid[100]; + sprintf(cpid, "%d", getpid()); + args.push_back("-p"); + args.push_back(cpid); + + ExecCmd cmd; + int status = cmd.doexec(ionicexe, args); + + if (status) { + LOGERR(("rclionice: failed, status 0x%x\n", status)); + return false; + } + return true; +} diff --git a/src/utils/rclionice.h b/src/utils/rclionice.h new file mode 100644 index 00000000..004eacdc --- /dev/null +++ b/src/utils/rclionice.h @@ -0,0 +1,25 @@ +/* Copyright (C) 2011 J.F.Dockes + * 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 2 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, write to the + * Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#ifndef _RCLIONICE_H_INCLUDED_ +#define _RCLIONICE_H_INCLUDED_ + +#include +using std::string; + +extern bool rclionice(const string& clss, const string& classdata); + +#endif /* _RCLIONICE_H_INCLUDED_ */