45
45
#include <boost/filesystem.hpp>
47
#include <drizzled/abort_exception.h>
48
#include <drizzled/catalog/local.h>
49
#include <drizzled/configmake.h>
50
#include <drizzled/data_home.h>
51
#include <drizzled/debug.h>
52
#include <drizzled/drizzled.h>
53
#include <drizzled/errmsg_print.h>
54
#include <drizzled/gettext.h>
55
#include <drizzled/internal/my_sys.h>
56
#include <drizzled/plugin.h>
57
#include <drizzled/plugin/client.h>
58
#include <drizzled/plugin/listen.h>
59
#include <drizzled/plugin/monitored_in_transaction.h>
60
#include <drizzled/pthread_globals.h>
61
#include <drizzled/replication_services.h>
62
#include <drizzled/session.h>
63
#include <drizzled/session/cache.h>
64
#include <drizzled/signal_handler.h>
65
#include <drizzled/transaction_services.h>
66
#include <drizzled/tztime.h>
67
#include <drizzled/unireg.h>
68
#include <drizzled/util/backtrace.h>
69
#include <drizzled/current_session.h>
70
#include <drizzled/daemon.h>
47
#include "drizzled/plugin.h"
48
#include "drizzled/gettext.h"
49
#include "drizzled/configmake.h"
50
#include "drizzled/session.h"
51
#include "drizzled/session/cache.h"
52
#include "drizzled/internal/my_sys.h"
53
#include "drizzled/unireg.h"
54
#include "drizzled/drizzled.h"
55
#include "drizzled/errmsg_print.h"
56
#include "drizzled/data_home.h"
57
#include "drizzled/plugin/listen.h"
58
#include "drizzled/plugin/client.h"
59
#include "drizzled/pthread_globals.h"
60
#include "drizzled/tztime.h"
61
#include "drizzled/signal_handler.h"
62
#include "drizzled/replication_services.h"
63
#include "drizzled/transaction_services.h"
64
#include "drizzled/catalog/local.h"
66
#include "drizzled/util/backtrace.h"
72
68
using namespace drizzled;
73
69
using namespace std;
70
namespace fs=boost::filesystem;
75
72
static pthread_t select_thread;
76
73
static uint32_t thr_kill_signal;
78
extern bool opt_daemon;
82
77
All global error messages are sent here where the first one is stored
95
90
session->is_fatal_error= 1;
98
@TODO There are two exceptions mechanism (Session and sp_rcontext),
93
TODO: There are two exceptions mechanism (Session and sp_rcontext),
99
94
this could be improved by having a common stack of handlers.
101
if (session->handle_error(error, str, DRIZZLE_ERROR::WARN_LEVEL_ERROR))
96
if (session->handle_error(error, str,
97
DRIZZLE_ERROR::WARN_LEVEL_ERROR))
105
session->getLex()->current_select == 0 if lex structure is not inited
101
session->lex->current_select == 0 if lex structure is not inited
106
102
(not query command (COM_QUERY))
108
if (! (session->getLex()->current_select &&
109
session->getLex()->current_select->no_error && !session->is_fatal_error))
104
if (! (session->lex->current_select &&
105
session->lex->current_select->no_error && !session->is_fatal_error))
111
107
if (! session->main_da.is_error()) // Return only first message
129
125
session->no_warnings_for_error= true;
130
126
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
131
127
session->no_warnings_for_error= false;
135
if (not session || MyFlags & ME_NOREFRESH)
137
errmsg_printf(error::ERROR, "%s: %s",internal::my_progname,str);
130
if (!session || MyFlags & ME_NOREFRESH)
131
errmsg_printf(ERRMSG_LVL_ERROR, "%s: %s",internal::my_progname,str);
141
134
static void init_signals(void)
160
153
sigaction(SIGFPE, &sa, NULL);
163
if (getDebug().test(debug::CORE_ON_SIGNAL))
156
if (test_flags.test(TEST_CORE_ON_SIGNAL))
165
158
/* Change limits so that we will get a core file */
166
159
struct rlimit rl;
167
160
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
168
161
if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
169
errmsg_printf(error::WARN,
162
errmsg_printf(ERRMSG_LVL_WARN,
170
163
_("setrlimit could not change the size of core files "
171
164
"to 'infinity'; We may not be able to generate a "
172
165
"core file on signals"));
248
241
/* Function generates error messages before abort */
249
242
error_handler_hook= my_message_sql;
251
243
/* init_common_variables must get basic settings such as data_home_dir
252
244
and plugin_load_list. */
253
if (init_basic_variables(argc, argv))
254
unireg_abort(1); // Will do exit
258
if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
260
perror("Failed to ignore SIGHUP");
264
fprintf(stderr, "failed to daemon() in order to daemonize\n");
269
if (init_remaining_variables(modules))
245
if (init_common_variables(argc, argv, modules))
270
246
unireg_abort(1); // Will do exit
295
271
if (chdir("local"))
297
errmsg_printf(error::ERROR,
273
errmsg_printf(ERRMSG_LVL_ERROR,
298
274
_("Local catalog %s/local does not exist\n"),
299
275
getDataHome().file_string().c_str());
303
boost::filesystem::path &full_data_home= getFullDataHome();
304
full_data_home= boost::filesystem::system_complete(getDataHome());
305
errmsg_printf(error::INFO, "Data Home directory is : %s", full_data_home.native_file_string().c_str());
279
full_data_home= fs::system_complete(getDataHome());
317
if (init_server_components(modules))
320
catch (abort_exception& ex)
323
cout << _("Drizzle has receieved an abort event.") << endl;
324
cout << _("In Function: ") << *::boost::get_error_info<boost::throw_function>(ex) << endl;
325
cout << _("In File: ") << *::boost::get_error_info<boost::throw_file>(ex) << endl;
326
cout << _("On Line: ") << *::boost::get_error_info<boost::throw_line>(ex) << endl;
289
if (init_server_components(modules))
333
293
* This check must be done after init_server_components for now
356
318
(void) unlink(pid_file.file_string().c_str()); // Not needed anymore
361
errmsg_printf(error::INFO, _(ER(ER_STARTUP)), internal::my_progname,
323
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_STARTUP)), internal::my_progname,
362
324
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
373
335
currentSession().release();
374
336
currentSession().reset(session.get());
377
transaction_services.sendStartupEvent(*session);
379
plugin_startup_window(modules, *(session.get()));
337
transaction_services.sendStartupEvent(session.get());
387
343
Listen for new connections and start new session for each connection
424
380
COND_thread_count.notify_all();
426
382
/* Wait until cleanup is done */
427
session::Cache::singleton().shutdownSecond();
384
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
385
while (not ready_to_exit)
386
COND_server_end.wait(scopedLock);
430
390
module::Registry::shutdown();