19#include <drizzled/gettext.h>
20#include <drizzled/error.h>
21#include <drizzled/plugin/storage_engine.h>
22#include <drizzled/pthread_globals.h>
23#include <drizzled/internal/my_pthread.h>
24#include <drizzled/internal/my_sys.h>
25#include <drizzled/plugin/daemon.h>
26#include <drizzled/signal_handler.h>
27#include <drizzled/session.h>
28#include <drizzled/session/cache.h>
29#include <drizzled/debug.h>
30#include <drizzled/drizzled.h>
31#include <drizzled/open_tables_state.h>
33#include <boost/thread/thread.hpp>
34#include <boost/filesystem.hpp>
39static bool kill_in_progress=
false;
40void signal_hand(
void);
44extern int cleanup_done;
45extern bool volatile abort_loop;
46extern bool volatile shutdown_in_progress;
48extern void close_connections(
void);
67static void kill_server(
int sig)
75 kill_in_progress=
true;
82 if (sig == SIGTERM || sig == 0)
84 errmsg_printf(error::INFO, _(ER(ER_NORMAL_SHUTDOWN)),internal::my_progname);
88 errmsg_printf(error::ERROR, _(ER(ER_GOT_SIGNAL)),internal::my_progname,sig);
101 internal::my_thread_init();
102 signal_thread_in_use=
true;
104 (void) sigemptyset(&set);
105#ifndef IGNORE_SIGHUP_SIGQUIT
106 if (sigaddset(&set,SIGQUIT))
108 std::cerr <<
"failed setting sigaddset() with SIGQUIT\n";
111 if (sigaddset(&set,SIGHUP))
113 std::cerr <<
"failed setting sigaddset() with SIGHUP\n";
117 if (sigaddset(&set,SIGTERM))
119 std::cerr <<
"failed setting sigaddset() with SIGTERM\n";
122 if (sigaddset(&set,SIGINT))
124 std::cerr <<
"failed setting sigaddset() with SIGINT\n";
127 if (sigaddset(&set,SIGTSTP))
129 std::cerr <<
"failed setting sigaddset() with SIGTSTP\n";
144 session::Cache::mutex().lock();
145 session::Cache::mutex().unlock();
146 COND_thread_count.notify_all();
148 if (pthread_sigmask(SIG_BLOCK, &set, NULL))
150 std::cerr <<
"Failed to set pthread_sigmask() in signal handler\n";
155 if (shutdown_in_progress and abort_loop ==
false)
161 while (sigwait(&set, &sig) == EINTR)
167 signal_thread_in_use=
false;
178 if (abort_loop ==
false)
185 if (abort_loop ==
false)
188 drizzled::plugin::StorageEngine::flushLogs(NULL);
198 boost::thread thread;
205 boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
206 thread= boost::thread(signal_hand);
207 signal_thread= thread.native_handle();
208 COND_thread_count.wait(scopedLock);
221 bool completed=
false;
228 while (completed ==
false and count--)
230 int signal= count == 1 ? SIGTSTP : SIGTERM;
232 if (
int error= pthread_kill(thread.native_handle(), signal))
235 char* buffer_ptr= strerror_r(error, buffer,
sizeof(buffer));
236 std::cerr <<
"pthread_kill() error on shutdown of signal thread (" << buffer_ptr <<
")\n";
241 boost::posix_time::milliseconds duration(100);
242 completed= thread.timed_join(duration);
256DRIZZLE_DECLARE_PLUGIN
262 N_(
"Signal handler"),
268DRIZZLE_DECLARE_PLUGIN_END;
TODO: Rename this file - func.h is stupid.