|
a/src/common/rclinit.cpp |
|
b/src/common/rclinit.cpp |
|
... |
|
... |
31 |
#include "pathut.h"
|
31 |
#include "pathut.h"
|
32 |
#include "unac.h"
|
32 |
#include "unac.h"
|
33 |
#include "smallut.h"
|
33 |
#include "smallut.h"
|
34 |
#include "execmd.h"
|
34 |
#include "execmd.h"
|
35 |
|
35 |
|
36 |
static const int catchedSigs[] = {SIGHUP, SIGINT, SIGQUIT, SIGTERM,
|
36 |
static const int catchedSigs[] = {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2};
|
37 |
SIGUSR1, SIGUSR2};
|
37 |
|
|
|
38 |
static pthread_t mainthread_id;
|
|
|
39 |
|
|
|
40 |
static void siglogreopen(int)
|
|
|
41 |
{
|
|
|
42 |
if (recoll_ismainthread())
|
|
|
43 |
DebugLog::reopen();
|
|
|
44 |
}
|
38 |
|
45 |
|
39 |
RclConfig *recollinit(RclInitFlags flags,
|
46 |
RclConfig *recollinit(RclInitFlags flags,
|
40 |
void (*cleanup)(void), void (*sigcleanup)(int),
|
47 |
void (*cleanup)(void), void (*sigcleanup)(int),
|
41 |
string &reason, const string *argcnf)
|
48 |
string &reason, const string *argcnf)
|
42 |
{
|
49 |
{
|
|
... |
|
... |
52 |
setlocale(LC_CTYPE, "");
|
59 |
setlocale(LC_CTYPE, "");
|
53 |
|
60 |
|
54 |
// We would like to block SIGCHLD globally, but we can't because
|
61 |
// We would like to block SIGCHLD globally, but we can't because
|
55 |
// QT uses it. Have to block it inside execmd.cpp
|
62 |
// QT uses it. Have to block it inside execmd.cpp
|
56 |
|
63 |
|
57 |
// Install signal handler
|
64 |
// Install app signal handler
|
58 |
if (sigcleanup) {
|
65 |
if (sigcleanup) {
|
59 |
struct sigaction action;
|
66 |
struct sigaction action;
|
60 |
action.sa_handler = sigcleanup;
|
67 |
action.sa_handler = sigcleanup;
|
61 |
action.sa_flags = 0;
|
68 |
action.sa_flags = 0;
|
62 |
sigemptyset(&action.sa_mask);
|
69 |
sigemptyset(&action.sa_mask);
|
|
... |
|
... |
103 |
}
|
110 |
}
|
104 |
if (!loglevel.empty()) {
|
111 |
if (!loglevel.empty()) {
|
105 |
int lev = atoi(loglevel.c_str());
|
112 |
int lev = atoi(loglevel.c_str());
|
106 |
DebugLog::getdbl()->setloglevel(lev);
|
113 |
DebugLog::getdbl()->setloglevel(lev);
|
107 |
}
|
114 |
}
|
|
|
115 |
// Install log rotate sig handler
|
|
|
116 |
{
|
|
|
117 |
struct sigaction action;
|
|
|
118 |
action.sa_handler = siglogreopen;
|
|
|
119 |
action.sa_flags = 0;
|
|
|
120 |
sigemptyset(&action.sa_mask);
|
|
|
121 |
if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
|
|
|
122 |
if (sigaction(SIGHUP, &action, 0) < 0) {
|
|
|
123 |
perror("Sigaction failed");
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
108 |
|
128 |
|
109 |
// Make sure the locale charset is initialized (so that multiple
|
129 |
// Make sure the locale charset is initialized (so that multiple
|
110 |
// threads don't try to do it at once).
|
130 |
// threads don't try to do it at once).
|
111 |
config->getDefCharset();
|
131 |
config->getDefCharset();
|
|
|
132 |
|
|
|
133 |
mainthread_id = pthread_self();
|
112 |
|
134 |
|
113 |
// Init unac locking
|
135 |
// Init unac locking
|
114 |
unac_init_mt();
|
136 |
unac_init_mt();
|
115 |
// Init smallut and pathut static values
|
137 |
// Init smallut and pathut static values
|
116 |
pathut_init_mt();
|
138 |
pathut_init_mt();
|
|
... |
|
... |
158 |
sigset_t sset;
|
180 |
sigset_t sset;
|
159 |
sigemptyset(&sset);
|
181 |
sigemptyset(&sset);
|
160 |
|
182 |
|
161 |
for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++)
|
183 |
for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++)
|
162 |
sigaddset(&sset, catchedSigs[i]);
|
184 |
sigaddset(&sset, catchedSigs[i]);
|
|
|
185 |
sigaddset(&sset, SIGHUP);
|
163 |
pthread_sigmask(SIG_BLOCK, &sset, 0);
|
186 |
pthread_sigmask(SIG_BLOCK, &sset, 0);
|
164 |
}
|
187 |
}
|
|
|
188 |
|
|
|
189 |
bool recoll_ismainthread()
|
|
|
190 |
{
|
|
|
191 |
return pthread_equal(pthread_self(), mainthread_id);
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|