45
45
#include <boost/filesystem.hpp>
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"
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>
71
#include <drizzled/diagnostics_area.h>
72
#include <drizzled/sql_base.h>
73
#include <drizzled/sql_lex.h>
74
#include <drizzled/system_variables.h>
68
76
using namespace drizzled;
69
77
using namespace std;
70
namespace fs=boost::filesystem;
72
79
static pthread_t select_thread;
73
80
static uint32_t thr_kill_signal;
82
extern bool opt_daemon;
77
86
All global error messages are sent here where the first one is stored
90
99
session->is_fatal_error= 1;
93
TODO: There are two exceptions mechanism (Session and sp_rcontext),
102
@TODO There are two exceptions mechanism (Session and sp_rcontext),
94
103
this could be improved by having a common stack of handlers.
96
if (session->handle_error(error, str,
97
DRIZZLE_ERROR::WARN_LEVEL_ERROR))
105
if (session->handle_error(error, str, DRIZZLE_ERROR::WARN_LEVEL_ERROR))
101
session->lex->current_select == 0 if lex structure is not inited
109
session->lex().current_select == 0 if lex structure is not inited
102
110
(not query command (COM_QUERY))
104
if (! (session->lex->current_select &&
105
session->lex->current_select->no_error && !session->is_fatal_error))
112
if (! (session->lex().current_select &&
113
session->lex().current_select->no_error && !session->is_fatal_error))
107
if (! session->main_da.is_error()) // Return only first message
115
if (! session->main_da().is_error()) // Return only first message
109
117
if (error == EE_OK)
110
118
error= ER_UNKNOWN_ERROR;
125
133
session->no_warnings_for_error= true;
126
134
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
127
135
session->no_warnings_for_error= false;
130
if (!session || MyFlags & ME_NOREFRESH)
131
errmsg_printf(ERRMSG_LVL_ERROR, "%s: %s",internal::my_progname,str);
139
if (not session || MyFlags & ME_NOREFRESH)
141
errmsg_printf(error::ERROR, "%s: %s",internal::my_progname,str);
134
145
static void init_signals(void)
153
164
sigaction(SIGFPE, &sa, NULL);
156
if (test_flags.test(TEST_CORE_ON_SIGNAL))
167
if (getDebug().test(debug::CORE_ON_SIGNAL))
158
169
/* Change limits so that we will get a core file */
159
170
struct rlimit rl;
160
171
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
161
172
if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
162
errmsg_printf(ERRMSG_LVL_WARN,
173
errmsg_printf(error::WARN,
163
174
_("setrlimit could not change the size of core files "
164
175
"to 'infinity'; We may not be able to generate a "
165
176
"core file on signals"));
241
252
/* Function generates error messages before abort */
242
253
error_handler_hook= my_message_sql;
243
255
/* init_common_variables must get basic settings such as data_home_dir
244
256
and plugin_load_list. */
245
if (init_common_variables(argc, argv, modules))
257
if (init_basic_variables(argc, argv))
258
unireg_abort(1); // Will do exit
262
if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
264
perror("Failed to ignore SIGHUP");
268
fprintf(stderr, "failed to daemon() in order to daemonize\n");
273
if (init_remaining_variables(modules))
246
274
unireg_abort(1); // Will do exit
271
299
if (chdir("local"))
273
errmsg_printf(ERRMSG_LVL_ERROR,
301
errmsg_printf(error::ERROR,
274
302
_("Local catalog %s/local does not exist\n"),
275
303
getDataHome().file_string().c_str());
279
full_data_home= fs::system_complete(getDataHome());
280
getDataHomeCatalog()= "./";
281
getDataHome()= "../";
307
boost::filesystem::path &full_data_home= getFullDataHome();
308
full_data_home= boost::filesystem::system_complete(getDataHome());
309
errmsg_printf(error::INFO, "Data Home directory is : %s", full_data_home.native_file_string().c_str());
291
if (init_server_components(modules))
321
if (init_server_components(modules))
324
catch (abort_exception& ex)
327
cout << _("Drizzle has receieved an abort event.") << endl;
328
cout << _("In Function: ") << *::boost::get_error_info<boost::throw_function>(ex) << endl;
329
cout << _("In File: ") << *::boost::get_error_info<boost::throw_file>(ex) << endl;
330
cout << _("On Line: ") << *::boost::get_error_info<boost::throw_line>(ex) << endl;
295
337
* This check must be done after init_server_components for now
320
360
(void) unlink(pid_file.file_string().c_str()); // Not needed anymore
325
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_STARTUP)), internal::my_progname,
365
errmsg_printf(error::INFO, _(ER(ER_STARTUP)), internal::my_progname,
326
366
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
337
377
currentSession().release();
338
378
currentSession().reset(session.get());
339
transaction_services.sendStartupEvent(session.get());
381
transaction_services.sendStartupEvent(*session);
383
plugin_startup_window(modules, *(session.get()));
345
391
Listen for new connections and start new session for each connection
346
392
accepted. The listen.getClient() method will return NULL when the server
347
393
should be shutdown.