allow daemon-specific log parameters
This commit is contained in:
parent
1205b11f60
commit
70f45f8746
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.6 2006-09-08 09:02:47 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.7 2006-11-08 07:22:14 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -25,22 +25,23 @@ static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.6 2006-09-08 09:02:47 dockes Exp
|
|||||||
#include "debuglog.h"
|
#include "debuglog.h"
|
||||||
#include "rclconfig.h"
|
#include "rclconfig.h"
|
||||||
#include "rclinit.h"
|
#include "rclinit.h"
|
||||||
|
#include "pathut.h"
|
||||||
|
|
||||||
RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
|
static const int catchedSigs[] = {SIGHUP, SIGINT, SIGQUIT, SIGTERM};
|
||||||
|
|
||||||
|
RclConfig *recollinit(RclInitFlags flags,
|
||||||
|
void (*cleanup)(void), void (*sigcleanup)(int),
|
||||||
string &reason, const string *argcnf)
|
string &reason, const string *argcnf)
|
||||||
{
|
{
|
||||||
if (cleanup)
|
if (cleanup)
|
||||||
atexit(cleanup);
|
atexit(cleanup);
|
||||||
|
|
||||||
if (sigcleanup) {
|
if (sigcleanup) {
|
||||||
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
|
for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++)
|
||||||
signal(SIGHUP, sigcleanup);
|
if (signal(catchedSigs[i], SIG_IGN) != SIG_IGN)
|
||||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
signal(catchedSigs[i], sigcleanup);
|
||||||
signal(SIGINT, sigcleanup);
|
|
||||||
if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
|
|
||||||
signal(SIGQUIT, sigcleanup);
|
|
||||||
if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
|
|
||||||
signal(SIGTERM, sigcleanup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLog::getdbl()->setloglevel(DEBDEB1);
|
DebugLog::getdbl()->setloglevel(DEBDEB1);
|
||||||
DebugLog::setfilename("stderr");
|
DebugLog::setfilename("stderr");
|
||||||
RclConfig *config = new RclConfig(argcnf);
|
RclConfig *config = new RclConfig(argcnf);
|
||||||
@ -53,10 +54,27 @@ RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve the log file name and level
|
||||||
string logfilename, loglevel;
|
string logfilename, loglevel;
|
||||||
if (config->getConfParam(string("logfilename"), logfilename))
|
if (flags & RCLINIT_DAEMON) {
|
||||||
|
config->getConfParam(string("daemlogfilename"), logfilename);
|
||||||
|
config->getConfParam(string("daemloglevel"), loglevel);
|
||||||
|
}
|
||||||
|
if (logfilename.empty())
|
||||||
|
config->getConfParam(string("logfilename"), logfilename);
|
||||||
|
if (loglevel.empty())
|
||||||
|
config->getConfParam(string("loglevel"), loglevel);
|
||||||
|
|
||||||
|
// Initialize logging
|
||||||
|
if (!logfilename.empty()) {
|
||||||
|
logfilename = path_tildexpand(logfilename);
|
||||||
|
// If not an absolute path, compute relative to config dir
|
||||||
|
if (logfilename.at(0) != '/') {
|
||||||
|
logfilename = path_cat(config->getConfDir(), logfilename);
|
||||||
|
}
|
||||||
DebugLog::setfilename(logfilename.c_str());
|
DebugLog::setfilename(logfilename.c_str());
|
||||||
if (config->getConfParam(string("loglevel"), loglevel)) {
|
}
|
||||||
|
if (!loglevel.empty()) {
|
||||||
int lev = atoi(loglevel.c_str());
|
int lev = atoi(loglevel.c_str());
|
||||||
DebugLog::getdbl()->setloglevel(lev);
|
DebugLog::getdbl()->setloglevel(lev);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,14 +16,35 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _RCLINIT_H_INCLUDED_
|
#ifndef _RCLINIT_H_INCLUDED_
|
||||||
#define _RCLINIT_H_INCLUDED_
|
#define _RCLINIT_H_INCLUDED_
|
||||||
/* @(#$Id: rclinit.h,v 1.4 2006-09-08 09:02:47 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: rclinit.h,v 1.5 2006-11-08 07:22:14 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#ifndef NO_NAMESPACES
|
||||||
|
using std::string;
|
||||||
|
#endif
|
||||||
|
|
||||||
class RclConfig;
|
class RclConfig;
|
||||||
|
/**
|
||||||
extern RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
|
* Initialize by reading configuration, opening log file, etc.
|
||||||
std::string &reason,
|
*
|
||||||
const std::string *argcnf = 0);
|
* @param flags misc modifiers
|
||||||
|
* @param cleanup function to call before exiting (atexit)
|
||||||
|
* @param sigcleanup function to call on terminal signal (INT/HUP...) This
|
||||||
|
* should typically set a flag which tells the program (recoll,
|
||||||
|
* recollindex etc.. to exit as soon as possible (after closing the db,
|
||||||
|
* etc.). cleanup will then be called by exit().
|
||||||
|
* @param reason in case of error: output string explaining things
|
||||||
|
* @param argcnf Configuration directory name from the command line (overriding
|
||||||
|
* default and environment
|
||||||
|
* @return the parsed configuration.
|
||||||
|
*/
|
||||||
|
enum RclInitFlags {RCLINIT_NONE=0, RCLINIT_DAEMON=1};
|
||||||
|
extern RclConfig *recollinit(RclInitFlags flags,
|
||||||
|
void (*cleanup)(void), void (*sigcleanup)(int),
|
||||||
|
string &reason, const string *argcnf = 0);
|
||||||
|
inline RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
|
||||||
|
string &reason, const string *argcnf = 0) {
|
||||||
|
return recollinit(RCLINIT_NONE, cleanup, sigcleanup, reason, argcnf);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _RCLINIT_H_INCLUDED_ */
|
#endif /* _RCLINIT_H_INCLUDED_ */
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.26 2006-10-24 14:28:38 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.27 2006-11-08 07:22:14 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -285,7 +285,10 @@ int main(int argc, const char **argv)
|
|||||||
Usage();
|
Usage();
|
||||||
|
|
||||||
string reason;
|
string reason;
|
||||||
RclConfig *config = recollinit(cleanup, sigcleanup, reason, &a_config);
|
RclInitFlags flags = (op_flags & OPT_m) && !(op_flags&OPT_D) ?
|
||||||
|
RCLINIT_DAEMON : RCLINIT_NONE;
|
||||||
|
RclConfig *config =
|
||||||
|
recollinit(flags, cleanup, sigcleanup, reason, &a_config);
|
||||||
if (config == 0 || !config->ok()) {
|
if (config == 0 || !config->ok()) {
|
||||||
cerr << "Configuration problem: " << reason << endl;
|
cerr << "Configuration problem: " << reason << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user