24#include <sys/resource.h>
33#include <boost/filesystem.hpp>
35#include <drizzled/vc_version.h>
36#include <drizzled/abort_exception.h>
37#include <drizzled/catalog/local.h>
38#include <drizzled/configmake.h>
39#include <drizzled/data_home.h>
40#include <drizzled/debug.h>
41#include <drizzled/drizzled.h>
42#include <drizzled/errmsg_print.h>
43#include <drizzled/gettext.h>
44#include <drizzled/internal/my_sys.h>
45#include <drizzled/plugin.h>
46#include <drizzled/plugin/client.h>
47#include <drizzled/plugin/listen.h>
48#include <drizzled/plugin/monitored_in_transaction.h>
49#include <drizzled/pthread_globals.h>
50#include <drizzled/replication_services.h>
51#include <drizzled/session.h>
52#include <drizzled/session/cache.h>
53#include <drizzled/signal_handler.h>
54#include <drizzled/transaction_services.h>
55#include <drizzled/drizzled_abort.h>
56#include <drizzled/util/backtrace.h>
57#include <drizzled/current_session.h>
58#include <drizzled/diagnostics_area.h>
59#include <drizzled/sql_base.h>
60#include <drizzled/sql_lex.h>
61#include <drizzled/system_variables.h>
66static pthread_t select_thread;
67static uint32_t thr_kill_signal;
73static void my_message_sql(drizzled::error_t error,
const char *str, myf MyFlags)
75 Session* session= current_session;
82 if (MyFlags & ME_FATALERROR)
84 session->is_fatal_error= 1;
99 if (! (session->lex().current_select &&
100 session->lex().current_select->no_error && !session->is_fatal_error))
102 if (! session->main_da().is_error())
105 error= ER_UNKNOWN_ERROR;
110 session->main_da().set_error_status(error, str);
114 if (!session->no_warnings_for_error && !session->is_fatal_error)
120 session->no_warnings_for_error=
true;
121 push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
122 session->no_warnings_for_error=
false;
126 if (not session || MyFlags & ME_NOREFRESH)
128 errmsg_printf(error::ERROR,
"%s: %s",internal::my_progname,str);
132static void init_signals(
void)
137 if (not (getDebug().test(debug::NO_STACKTRACE) ||
138 getDebug().test(debug::CORE_ON_SIGNAL)))
140 sa.sa_flags = SA_RESETHAND | SA_NODEFER;
141 sigemptyset(&sa.sa_mask);
142 sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
144 sa.sa_handler= drizzled_handle_segfault;
145 sigaction(SIGSEGV, &sa, NULL);
146 sigaction(SIGABRT, &sa, NULL);
148 sigaction(SIGBUS, &sa, NULL);
150 sigaction(SIGILL, &sa, NULL);
151 sigaction(SIGFPE, &sa, NULL);
154 if (getDebug().test(debug::CORE_ON_SIGNAL))
158 rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
159 if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
160 errmsg_printf(error::WARN,
161 _(
"setrlimit could not change the size of core files "
162 "to 'infinity'; We may not be able to generate a "
163 "core file on signals"));
165 (void) sigemptyset(&set);
166 ignore_signal(SIGPIPE);
167 sigaddset(&set,SIGPIPE);
168#ifndef IGNORE_SIGHUP_SIGQUIT
169 sigaddset(&set,SIGQUIT);
170 sigaddset(&set,SIGHUP);
172 sigaddset(&set,SIGTERM);
173 sigaddset(&set,SIGINT);
176 sigemptyset(&sa.sa_mask);
178 sa.sa_handler = drizzled_print_signal_warning;
179 sigaction(SIGTERM, &sa, NULL);
181 sa.sa_handler = drizzled_print_signal_warning;
182 sigaction(SIGHUP, &sa, NULL);
184 sigaddset(&set,SIGTSTP);
186 if (getDebug().test(debug::ALLOW_SIGINT) && thr_kill_signal != SIGINT)
189 sa.sa_handler= drizzled_end_thread_signal;
190 sigaction(thr_kill_signal, &sa, NULL);
192 sigdelset(&set, thr_kill_signal);
194 sigprocmask(SIG_SETMASK,&set,NULL);
195 pthread_sigmask(SIG_SETMASK,&set,NULL);
197 (void) sigemptyset(&set);
198 sigaddset(&set,SIGTSTP);
199 sigprocmask(SIG_UNBLOCK,&set,NULL);
200 pthread_sigmask(SIG_UNBLOCK,&set,NULL);
207static void GoogleProtoErrorThrower(google::protobuf::LogLevel level,
213 case google::protobuf::LOGLEVEL_INFO:
215 case google::protobuf::LOGLEVEL_WARNING:
216 case google::protobuf::LOGLEVEL_ERROR:
217 case google::protobuf::LOGLEVEL_FATAL:
219 throw(
"error in google protocol buffer parsing");
223int main(
int argc,
char **argv)
225#if defined(ENABLE_NLS)
226 setlocale(LC_ALL,
"");
227 bindtextdomain(
"drizzle", LOCALEDIR);
228 textdomain(
"drizzle");
233 drizzled::internal::my_progname= argv[0];
234 drizzled::internal::my_init();
239 thr_kill_signal= SIGINT;
241 google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
244 error_handler_hook= my_message_sql;
247 if (init_variables_before_daemonizing(argc, argv) ==
false)
249 drizzled_abort <<
"init_variables_before_daemonizing() failed";
252 if (init_variables_after_daemonizing(modules) ==
false)
254 drizzled_abort <<
"init_variables_after_daemonizing() failed";
264 select_thread= pthread_self();
265 select_thread_in_use=1;
267 if (was_help_requested() ==
false)
269 if (chdir(getDataHome().
string().c_str()))
271 drizzled_abort <<
"Data directory " << getDataHome().string() <<
" does not exist";
274 ifstream old_uuid_file (
"server.uuid");
275 if (old_uuid_file.is_open())
277 getline(old_uuid_file, server_uuid);
278 old_uuid_file.close();
283 char uuid_string[37];
284 uuid_generate_random(uu);
285 uuid_unparse(uu, uuid_string);
286 ofstream new_uuid_file (
"server.uuid");
287 new_uuid_file << uuid_string;
288 new_uuid_file.close();
289 server_uuid= string(uuid_string);
292 if (mkdir(
"local", 0700) == -1)
302 drizzled_abort <<
"Could not create local catalog, permission denied in directory:" << getcwd(cwd,
sizeof(cwd));
309 drizzled_abort <<
"Could not create local catalog, in directory:" << getcwd(cwd,
sizeof(cwd)) <<
" system error was:" << strerror(errno);
314 setFullDataHome(boost::filesystem::system_complete(getDataHome()));
315 errmsg_printf(error::INFO,
"Data Home directory is : %s", getFullDataHome().native().c_str());
325 init_server_components(modules);
330 cout << _(
"Drizzle has receieved an abort event.") << endl;
331 cout << _(
"In Function: ") << *::boost::get_error_info<boost::throw_function>(ex) << endl;
332 cout << _(
"In File: ") << *::boost::get_error_info<boost::throw_file>(ex) << endl;
333 cout << _(
"On Line: ") << *::boost::get_error_info<boost::throw_line>(ex) << endl;
335 drizzled_abort <<
"init_server_components() failed";
354 drizzled_abort <<
"Failed plugin::Listen::setup()";
357 assert(plugin::num_trx_monitored_objects > 0);
358 drizzle_rm_tmp_tables();
359 errmsg_printf(error::INFO, _(ER(ER_STARTUP)), internal::my_progname, DRIZZLE_RELEASE_VERSION, COMPILATION_COMMENT);
364 setCurrentSession(session.get());
366 plugin_startup_window(modules, *session.get());
369 errmsg_printf(error::INFO,
"Drizzle startup complete, listening for connections will now begin.");
378 Session::shared_ptr session= Session::make_shared(client, client->catalog());
381 if (Session::schedule(session))
383 Session::unlink(session);
390 setCurrentSession(session.get());
395 boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
396 select_thread_in_use=
false;
398 COND_thread_count.notify_all();
401 session::Cache::shutdownSecond();
406 errmsg_printf(error::INFO,
"Drizzle is now shutting down");
static bool evaluateRegisteredPlugins()
static bool sendShutdownEvent(Session &)
static bool sendStartupEvent(Session &)
static plugin::Client * serveConnections()
static plugin::Client * getNullClient()
TODO: Rename this file - func.h is stupid.