diff --git a/ChangeLog b/ChangeLog index 05574ca77..5b5a5cf0a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -40,6 +40,7 @@ Features + New '_get' is a DOM accessor helper command. + New virtual tags (WEEK, MONTH, YEAR, PARENT). + Added the 'remaining' format for all date columns. + + Protects against interrupt during critical DB commit and sync operations. Bugs + #1195 Random seed not random enough - removed all random number code (thanks diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 8419bb295..34bbb3e50 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -610,6 +611,15 @@ void TDB2::modify (Task& task, bool add_to_backlog /* = true */) //////////////////////////////////////////////////////////////////////////////// void TDB2::commit () { + // Ignore harmful signals. + signal (SIGHUP, SIG_IGN); + signal (SIGINT, SIG_IGN); + signal (SIGKILL, SIG_IGN); + signal (SIGPIPE, SIG_IGN); + signal (SIGTERM, SIG_IGN); + signal (SIGUSR1, SIG_IGN); + signal (SIGUSR2, SIG_IGN); + dump (); context.timer_commit.start (); @@ -618,6 +628,15 @@ void TDB2::commit () undo.commit (); backlog.commit (); + // Restore signal handling. + signal (SIGHUP, SIG_DFL); + signal (SIGINT, SIG_DFL); + signal (SIGKILL, SIG_DFL); + signal (SIGPIPE, SIG_DFL); + signal (SIGTERM, SIG_DFL); + signal (SIGUSR1, SIG_DFL); + signal (SIGUSR2, SIG_DFL); + context.timer_commit.stop (); } diff --git a/src/commands/CmdSync.cpp b/src/commands/CmdSync.cpp index e6d462f10..5371bd9b6 100644 --- a/src/commands/CmdSync.cpp +++ b/src/commands/CmdSync.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -131,6 +132,15 @@ int CmdSync::execute (std::string& output) out << format (STRING_CMD_SYNC_PROGRESS, connection) << "\n"; + // Ignore harmful signals. + signal (SIGHUP, SIG_IGN); + signal (SIGINT, SIG_IGN); + signal (SIGKILL, SIG_IGN); + signal (SIGPIPE, SIG_IGN); + signal (SIGTERM, SIG_IGN); + signal (SIGUSR1, SIG_IGN); + signal (SIGUSR2, SIG_IGN); + Msg response; if (send (connection, certificate, request, response)) { @@ -270,6 +280,15 @@ int CmdSync::execute (std::string& output) out << "\n"; output = out.str (); + // Restore signal handling. + signal (SIGHUP, SIG_DFL); + signal (SIGINT, SIG_DFL); + signal (SIGKILL, SIG_DFL); + signal (SIGPIPE, SIG_DFL); + signal (SIGTERM, SIG_DFL); + signal (SIGUSR1, SIG_DFL); + signal (SIGUSR2, SIG_DFL); + #else // Without GnuTLS found at compile time, there is no working sync command. throw std::string (STRING_CMD_SYNC_NO_TLS);