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>
39 static bool kill_in_progress=
false;
40 void signal_hand(
void);
44 extern int cleanup_done;
45 extern bool volatile abort_loop;
46 extern bool volatile shutdown_in_progress;
48 extern void close_connections(
void);
51 using namespace drizzled;
67 static 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 if ((drizzled::getDebug().test(drizzled::debug::ALLOW_SIGINT)))
106 (void) sigemptyset(&set);
107 (void) sigaddset(&set,SIGINT);
108 (void) pthread_sigmask(SIG_UNBLOCK, &set, NULL);
110 (void) sigemptyset(&set);
111 #ifndef IGNORE_SIGHUP_SIGQUIT
112 if (sigaddset(&set,SIGQUIT))
114 std::cerr <<
"failed setting sigaddset() with SIGQUIT\n";
117 if (sigaddset(&set,SIGHUP))
119 std::cerr <<
"failed setting sigaddset() with SIGHUP\n";
123 if (sigaddset(&set,SIGTERM))
125 std::cerr <<
"failed setting sigaddset() with SIGTERM\n";
128 if (sigaddset(&set,SIGTSTP))
130 std::cerr <<
"failed setting sigaddset() with SIGTSTP\n";
145 session::Cache::mutex().lock();
146 session::Cache::mutex().unlock();
147 COND_thread_count.notify_all();
149 if (pthread_sigmask(SIG_BLOCK, &set, NULL))
151 std::cerr <<
"Failed to set pthread_sigmask() in signal handler\n";
156 if (shutdown_in_progress and abort_loop ==
false)
162 while (sigwait(&set, &sig) == EINTR)
168 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 strerror_r(error, buffer,
sizeof(buffer));
236 std::cerr <<
"pthread_kill() error on shutdown of signal thread (" << buffer <<
")\n";
241 boost::posix_time::milliseconds duration(100);
242 completed= thread.timed_join(duration);
256 DRIZZLE_DECLARE_PLUGIN
262 N_(
"Signal handler"),
268 DRIZZLE_DECLARE_PLUGIN_END;