|
a/src/common/rclinit.cpp |
|
b/src/common/rclinit.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.8 2006-11-08 15:34:20 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.9 2007-05-21 13:30:21 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
19 |
*/
|
19 |
*/
|
20 |
|
20 |
|
21 |
#include <stdio.h>
|
21 |
#include <stdio.h>
|
22 |
#include <signal.h>
|
22 |
#include <signal.h>
|
23 |
#include <locale.h>
|
23 |
#include <locale.h>
|
|
|
24 |
#include <pthread.h>
|
24 |
|
25 |
|
25 |
#include "debuglog.h"
|
26 |
#include "debuglog.h"
|
26 |
#include "rclconfig.h"
|
27 |
#include "rclconfig.h"
|
27 |
#include "rclinit.h"
|
28 |
#include "rclinit.h"
|
28 |
#include "pathut.h"
|
29 |
#include "pathut.h"
|
|
... |
|
... |
33 |
void (*cleanup)(void), void (*sigcleanup)(int),
|
34 |
void (*cleanup)(void), void (*sigcleanup)(int),
|
34 |
string &reason, const string *argcnf)
|
35 |
string &reason, const string *argcnf)
|
35 |
{
|
36 |
{
|
36 |
if (cleanup)
|
37 |
if (cleanup)
|
37 |
atexit(cleanup);
|
38 |
atexit(cleanup);
|
|
|
39 |
|
|
|
40 |
// We ignore SIGPIPE always. All pieces of code which can write to a pipe
|
|
|
41 |
// must check write() return values.
|
|
|
42 |
signal(SIGPIPE, SIG_IGN);
|
|
|
43 |
|
|
|
44 |
// We block SIGCLD globally. We intend to properly wait for our children
|
|
|
45 |
sigset_t sset;
|
|
|
46 |
sigemptyset(&sset);
|
|
|
47 |
sigaddset(&sset, SIGCHLD);
|
|
|
48 |
pthread_sigmask(SIG_BLOCK, &sset, 0);
|
38 |
|
49 |
|
39 |
if (sigcleanup) {
|
50 |
if (sigcleanup) {
|
40 |
for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++)
|
51 |
for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++)
|
41 |
if (signal(catchedSigs[i], SIG_IGN) != SIG_IGN)
|
52 |
if (signal(catchedSigs[i], SIG_IGN) != SIG_IGN)
|
42 |
signal(catchedSigs[i], sigcleanup);
|
53 |
signal(catchedSigs[i], sigcleanup);
|
|
... |
|
... |
84 |
// to utf8 for indexation.
|
95 |
// to utf8 for indexation.
|
85 |
setlocale(LC_CTYPE, "");
|
96 |
setlocale(LC_CTYPE, "");
|
86 |
|
97 |
|
87 |
return config;
|
98 |
return config;
|
88 |
}
|
99 |
}
|
|
|
100 |
|
|
|
101 |
// Signals are handled by the main thread. All others should call this routine
|
|
|
102 |
// to block possible signals
|
|
|
103 |
void recoll_threadinit()
|
|
|
104 |
{
|
|
|
105 |
sigset_t sset;
|
|
|
106 |
sigemptyset(&sset);
|
|
|
107 |
|
|
|
108 |
for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++)
|
|
|
109 |
sigaddset(&sset, catchedSigs[i]);
|
|
|
110 |
pthread_sigmask(SIG_BLOCK, &sset, 0);
|
|
|
111 |
}
|