summaryrefslogtreecommitdiff
path: root/db/db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'db/db.cpp')
-rw-r--r--db/db.cpp101
1 files changed, 55 insertions, 46 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 619e9a43069..ca43813fd6f 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -42,6 +42,7 @@ extern OpLog _oplog;
extern int ctr;
extern int callDepth;
+void setupSignals();
void closeAllSockets();
void startReplication();
void pairWith(const char *remoteEnd, const char *arb);
@@ -239,52 +240,6 @@ void msg(const char *m, int extras = 0) {
msg(m, "127.0.0.1", DBPort, extras);
}
-#if !defined(_WIN32)
-
-#include <signal.h>
-
-void pipeSigHandler( int signal ) {
- psignal( signal, "Signal Received : ");
-}
-
-int segvs = 0;
-void segvhandler(int x) {
- if ( ++segvs > 1 ) {
- signal(x, SIG_DFL);
- if ( segvs == 2 ) {
- cout << "\n\n\n got 2nd SIGSEGV" << endl;
- sayDbContext();
- }
- return;
- }
- problem() << "got SIGSEGV " << x << ", terminating :-(" << endl;
- sayDbContext();
-// closeAllSockets();
-// MemoryMappedFile::closeAllFiles();
-// flushOpLog();
- dbexit(14);
-}
-
-void mysighandler(int x) {
- signal(x, SIG_IGN);
- log() << "got kill or ctrl c signal " << x << ", will terminate after current cmd ends" << endl;
- {
- dblock lk;
- problem() << " now exiting" << endl;
- exit(12);
- }
-}
-
-void setupSignals() {
- assert( signal(SIGINT, mysighandler) != SIG_ERR );
- assert( signal(SIGTERM, mysighandler) != SIG_ERR );
-}
-
-#else
-void setupSignals() {}
-#endif
-
-
void repairDatabases() {
dblock lk;
vector< string > dbNames;
@@ -317,6 +272,7 @@ void clearTmpFiles() {
}
}
+void segvhandler(int x);
void initAndListen(int listenPort, const char *appserverLoc = null) {
clearTmpFiles();
@@ -355,6 +311,7 @@ void initAndListen(int listenPort, const char *appserverLoc = null) {
//ofstream problems("dbproblems.log", ios_base::app | ios_base::out);
int test2();
void testClient();
+void pipeSigHandler( int signal );
int main(int argc, char* argv[], char *envp[] )
{
@@ -537,3 +494,55 @@ usage:
return 0;
}
+
+/* we do not use log() below as it uses a mutex and that could cause deadlocks.
+*/
+
+string getDbContext();
+
+#undef cout
+
+#if !defined(_WIN32)
+
+#include <signal.h>
+
+void pipeSigHandler( int signal ) {
+ psignal( signal, "Signal Received : ");
+}
+
+int segvs = 0;
+void segvhandler(int x) {
+ if ( ++segvs > 1 ) {
+ signal(x, SIG_DFL);
+ if ( segvs == 2 ) {
+ cout << "\n\n\n got 2nd SIGSEGV" << endl;
+ sayDbContext();
+ }
+ return;
+ }
+ cout << "got SIGSEGV " << x << ", terminating :-(" << endl;
+ sayDbContext();
+// closeAllSockets();
+// MemoryMappedFile::closeAllFiles();
+// flushOpLog();
+ dbexit(14);
+}
+
+void mysighandler(int x) {
+ signal(x, SIG_IGN);
+ cout << "got kill or ctrl c signal " << x << ", will terminate after current cmd ends" << endl;
+ {
+ dblock lk;
+ problem() << " now exiting" << endl;
+ exit(12);
+ }
+}
+
+void setupSignals() {
+ assert( signal(SIGINT, mysighandler) != SIG_ERR );
+ assert( signal(SIGTERM, mysighandler) != SIG_ERR );
+}
+
+#else
+void setupSignals() {}
+#endif