~drizzle-trunk/drizzle/development

1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
21
22
#include <pthread.h>
23
#include <signal.h>
24
#include <sys/resource.h>
25
#include <unistd.h>
1786.3.1 by Monty Taylor
Initial working local catalog.
26
#include <sys/stat.h>
27
#include <sys/types.h>
28
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
29
30
#if TIME_WITH_SYS_TIME
31
# include <sys/time.h>
32
# include <time.h>
33
#else
34
# if HAVE_SYS_TIME_H
35
#  include <sys/time.h>
36
# else
37
#  include <time.h>
38
# endif
39
#endif
40
1300.5.7 by Monty Taylor
Fixed Sun Studio issues.
41
#if defined(HAVE_LOCALE_H)
42
# include <locale.h>
43
#endif
44
1791.3.5 by mordred
Now lets get the proper values into these bad boys.
45
#include <boost/filesystem.hpp>
1300.5.7 by Monty Taylor
Fixed Sun Studio issues.
46
2148.7.12 by Brian Aker
Merge in header fixes.
47
#include <drizzled/abort_exception.h>
48
#include <drizzled/catalog/local.h>
49
#include <drizzled/configmake.h>
50
#include <drizzled/data_home.h>
2104.3.3 by Brian Aker
Cleanup test flags for debug options on server startup
51
#include <drizzled/debug.h>
2148.7.12 by Brian Aker
Merge in header fixes.
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/unireg.h>
67
#include <drizzled/util/backtrace.h>
2154.2.24 by Brian Aker
Merge in all changes for current_session, etc.
68
#include <drizzled/current_session.h>
2167.2.1 by Monty Taylor
C++-ize daemon.c. Our codebase is c++.
69
#include <drizzled/daemon.h>
2239.1.5 by Olaf van der Spek
Refactor includes
70
#include <drizzled/diagnostics_area.h>
2227.4.3 by Olaf van der Spek
Remove unnecessary statement.h include
71
#include <drizzled/sql_base.h>
2234.1.3 by Olaf van der Spek
Refactor includes
72
#include <drizzled/sql_lex.h>
2241.3.2 by Olaf van der Spek
Refactor Session::variables
73
#include <drizzled/system_variables.h>
2131.10.1 by Stewart Smith
add a very simple --daemon or -d option to drizzled using the exact same code as memcached to start as a daemon.
74
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
75
using namespace drizzled;
76
using namespace std;
77
78
static pthread_t select_thread;
79
static uint32_t thr_kill_signal;
80
2131.10.1 by Stewart Smith
add a very simple --daemon or -d option to drizzled using the exact same code as memcached to start as a daemon.
81
extern bool opt_daemon;
82
1791.3.4 by mordred
Well, so handing pointers returned by std::string::c_str() is a bad idea anyway - but you certainly shouldn't do it in static initializers before you do all of your changes to the string. Sigh.
83
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
84
/**
85
  All global error messages are sent here where the first one is stored
86
  for the client.
87
*/
2087.3.1 by Brian Aker
Entire convert over to time_t.
88
static void my_message_sql(drizzled::error_t error, const char *str, myf MyFlags)
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
89
{
2281.4.2 by Olaf van der Spek
Prune
90
  Session* session= current_session;
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
91
  /*
92
    Put here following assertion when situation with EE_* error codes
93
    will be fixed
94
  */
2281.4.2 by Olaf van der Spek
Prune
95
  if (session)
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
96
  {
97
    if (MyFlags & ME_FATALERROR)
2440.4.1 by Brian Aker
Enable syslog and format sql_select
98
    {
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
99
      session->is_fatal_error= 1;
2440.4.1 by Brian Aker
Enable syslog and format sql_select
100
    }
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
101
102
    /*
2137.1.13 by Brian Aker
Fix bad error in warnings/errors.
103
      @TODO There are two exceptions mechanism (Session and sp_rcontext),
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
104
      this could be improved by having a common stack of handlers.
2281.4.2 by Olaf van der Spek
Prune
105
2137.1.13 by Brian Aker
Fix bad error in warnings/errors.
106
    if (session->handle_error(error, str, DRIZZLE_ERROR::WARN_LEVEL_ERROR))
107
      return;
2281.4.2 by Olaf van der Spek
Prune
108
    */
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
109
110
    /*
2227.4.8 by Olaf van der Spek
Session::lex()
111
      session->lex().current_select == 0 if lex structure is not inited
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
112
      (not query command (COM_QUERY))
113
    */
2227.4.8 by Olaf van der Spek
Session::lex()
114
    if (! (session->lex().current_select &&
115
           session->lex().current_select->no_error && !session->is_fatal_error))
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
116
    {
2239.1.4 by Olaf van der Spek
Refactor includes
117
      if (! session->main_da().is_error())            // Return only first message
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
118
      {
2087.3.1 by Brian Aker
Entire convert over to time_t.
119
        if (error == EE_OK)
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
120
          error= ER_UNKNOWN_ERROR;
2087.3.1 by Brian Aker
Entire convert over to time_t.
121
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
122
        if (str == NULL)
123
          str= ER(error);
2087.3.1 by Brian Aker
Entire convert over to time_t.
124
2239.1.4 by Olaf van der Spek
Refactor includes
125
        session->main_da().set_error_status(error, str);
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
126
      }
127
    }
128
129
    if (!session->no_warnings_for_error && !session->is_fatal_error)
130
    {
131
      /*
132
        Suppress infinite recursion if there a memory allocation error
133
        inside push_warning.
134
      */
135
      session->no_warnings_for_error= true;
136
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
137
      session->no_warnings_for_error= false;
138
    }
2137.1.13 by Brian Aker
Fix bad error in warnings/errors.
139
  }
2104.3.3 by Brian Aker
Cleanup test flags for debug options on server startup
140
2137.1.13 by Brian Aker
Fix bad error in warnings/errors.
141
  if (not session || MyFlags & ME_NOREFRESH)
142
  {
143
    errmsg_printf(error::ERROR, "%s: %s",internal::my_progname,str);
144
  }
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
145
}
146
147
static void init_signals(void)
148
{
149
  sigset_t set;
150
  struct sigaction sa;
151
2227.4.3 by Olaf van der Spek
Remove unnecessary statement.h include
152
  if (not (getDebug().test(debug::NO_STACKTRACE) ||
2104.3.3 by Brian Aker
Cleanup test flags for debug options on server startup
153
        getDebug().test(debug::CORE_ON_SIGNAL)))
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
154
  {
155
    sa.sa_flags = SA_RESETHAND | SA_NODEFER;
156
    sigemptyset(&sa.sa_mask);
157
    sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
158
159
    sa.sa_handler= drizzled_handle_segfault;
160
    sigaction(SIGSEGV, &sa, NULL);
161
    sigaction(SIGABRT, &sa, NULL);
162
#ifdef SIGBUS
163
    sigaction(SIGBUS, &sa, NULL);
164
#endif
165
    sigaction(SIGILL, &sa, NULL);
166
    sigaction(SIGFPE, &sa, NULL);
167
  }
168
2104.3.3 by Brian Aker
Cleanup test flags for debug options on server startup
169
  if (getDebug().test(debug::CORE_ON_SIGNAL))
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
170
  {
171
    /* Change limits so that we will get a core file */
172
    struct rlimit rl;
173
    rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
174
    if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
175
        errmsg_printf(error::WARN,
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
176
                      _("setrlimit could not change the size of core files "
177
                        "to 'infinity';  We may not be able to generate a "
178
                        "core file on signals"));
179
  }
180
  (void) sigemptyset(&set);
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
181
  ignore_signal(SIGPIPE);
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
182
  sigaddset(&set,SIGPIPE);
183
#ifndef IGNORE_SIGHUP_SIGQUIT
184
  sigaddset(&set,SIGQUIT);
185
  sigaddset(&set,SIGHUP);
186
#endif
187
  sigaddset(&set,SIGTERM);
188
189
  /* Fix signals if blocked by parents (can happen on Mac OS X) */
190
  sigemptyset(&sa.sa_mask);
191
  sa.sa_flags = 0;
192
  sa.sa_handler = drizzled_print_signal_warning;
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
193
  sigaction(SIGTERM, &sa, NULL);
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
194
  sa.sa_flags = 0;
195
  sa.sa_handler = drizzled_print_signal_warning;
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
196
  sigaction(SIGHUP, &sa, NULL);
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
197
#ifdef SIGTSTP
198
  sigaddset(&set,SIGTSTP);
199
#endif
2104.3.3 by Brian Aker
Cleanup test flags for debug options on server startup
200
  if (getDebug().test(debug::ALLOW_SIGINT))
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
201
  {
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
202
    sa.sa_flags= 0;
203
    sa.sa_handler= drizzled_end_thread_signal;
204
    sigaction(thr_kill_signal, &sa, NULL);
205
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
206
    // May be SIGINT
207
    sigdelset(&set, thr_kill_signal);
208
  }
209
  else
1608.1.2 by Brian Aker
Merge enum test
210
  {
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
211
    sigaddset(&set,SIGINT);
1608.1.2 by Brian Aker
Merge enum test
212
  }
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
213
  sigprocmask(SIG_SETMASK,&set,NULL);
214
  pthread_sigmask(SIG_SETMASK,&set,NULL);
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
215
  return;
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
216
}
217
2017.2.1 by Brian Aker
Cleanup error messages around bad table definitions.
218
static void GoogleProtoErrorThrower(google::protobuf::LogLevel level,
219
                                    const char* ,
220
                                    int, const string& ) throw(const char *)
1608.1.2 by Brian Aker
Merge enum test
221
{
222
  switch(level)
223
  {
224
  case google::protobuf::LOGLEVEL_INFO:
225
    break;
226
  case google::protobuf::LOGLEVEL_WARNING:
227
  case google::protobuf::LOGLEVEL_ERROR:
228
  case google::protobuf::LOGLEVEL_FATAL:
229
  default:
230
    throw("error in google protocol buffer parsing");
231
  }
232
}
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
233
234
int main(int argc, char **argv)
235
{
236
#if defined(ENABLE_NLS)
237
# if defined(HAVE_LOCALE_H)
238
  setlocale(LC_ALL, "");
239
# endif
2068.4.1 by Andrew Hutchings
Fix intl domain
240
  bindtextdomain("drizzle7", LOCALEDIR);
241
  textdomain("drizzle7");
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
242
#endif
243
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
244
  module::Registry &modules= module::Registry::singleton();
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
245
2385.3.9 by Olaf van der Spek
Move flush() into iocache
246
  drizzled::internal::my_progname= argv[0]; 
247
  drizzled::internal::my_init();
248
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
249
  /* nothing should come before this line ^^^ */
250
251
  /* Set signal used to kill Drizzle */
252
  thr_kill_signal= SIGINT;
253
1608.1.2 by Brian Aker
Merge enum test
254
  google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
255
1743.4.1 by LinuxJedi
Make sure unireg_abort shows the reason for the fail.
256
  /* Function generates error messages before abort */
1794.3.5 by Monty Taylor
Fixed temporoary dir sequencing.
257
  error_handler_hook= my_message_sql;
2131.10.7 by Stewart Smith
partition the initialisation of variables and command line options into two phases: the first being the simple one (that we can get out the --daemon option for) and the second being loading plugins, pidfile setup etc. This makes --daemon do the pidfile correctly.
258
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
259
  /* init_common_variables must get basic settings such as data_home_dir and plugin_load_list. */
260
  if (not init_variables_before_daemonizing(argc, argv))
261
  {
262
    unireg_abort << "init_variables_before_daemonizing() failed";				// Will do exit
263
  }
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
264
2392.1.1 by Brian Aker
Fixes for --help work.
265
  if (opt_daemon and was_help_requested() == false)
2131.10.1 by Stewart Smith
add a very simple --daemon or -d option to drizzled using the exact same code as memcached to start as a daemon.
266
  {
2131.10.8 by Stewart Smith
using signal() instead of sigignore() as it's compatible with FreeBSD < 8.1
267
    if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
2131.10.5 by Stewart Smith
small style fix
268
    {
2131.10.1 by Stewart Smith
add a very simple --daemon or -d option to drizzled using the exact same code as memcached to start as a daemon.
269
      perror("Failed to ignore SIGHUP");
270
    }
2168.1.6 by Monty Taylor
Fixed an ICC warning.
271
    if (daemonize())
2131.10.5 by Stewart Smith
small style fix
272
    {
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
273
      unireg_abort << "--daemon failed";
2131.10.1 by Stewart Smith
add a very simple --daemon or -d option to drizzled using the exact same code as memcached to start as a daemon.
274
    }
275
  }
276
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
277
  if (not init_variables_after_daemonizing(modules))
278
  {
279
    unireg_abort << "init_variables_after_daemonizing() failed";				// Will do exit
280
  }
281
2131.10.7 by Stewart Smith
partition the initialisation of variables and command line options into two phases: the first being the simple one (that we can get out the --daemon option for) and the second being loading plugins, pidfile setup etc. This makes --daemon do the pidfile correctly.
282
1794.3.5 by Monty Taylor
Fixed temporoary dir sequencing.
283
  /*
284
    init signals & alarm
285
    After this we can't quit by a simple unireg_abort
286
  */
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
287
  init_signals();
288
289
2363.1.8 by Brian Aker
--help and --version now work a bit more quickly. Also, we don't have to worry about root messing up file creation.
290
  select_thread= pthread_self();
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
291
  select_thread_in_use=1;
292
2392.1.1 by Brian Aker
Fixes for --help work.
293
  if (was_help_requested() == false)
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
294
  {
1813.2.9 by Monty Taylor
Made data_home be fs::path natively.
295
    if (chdir(getDataHome().file_string().c_str()))
1786.3.1 by Monty Taylor
Initial working local catalog.
296
    {
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
297
      unireg_abort << "Data directory " << getDataHome().file_string() << " does not exist";
1786.3.1 by Monty Taylor
Initial working local catalog.
298
    }
2290.1.1 by Joseph Daly
Add server uuid
299
300
    ifstream old_uuid_file ("server.uuid");
301
    if (old_uuid_file.is_open())
302
    {
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
303
      getline(old_uuid_file, server_uuid);
2290.1.1 by Joseph Daly
Add server uuid
304
      old_uuid_file.close();
305
    } 
306
    else 
307
    {
308
      uuid_t uu;
309
      char uuid_string[37];
310
      uuid_generate_random(uu);
311
      uuid_unparse(uu, uuid_string);
312
      ofstream new_uuid_file ("server.uuid");
313
      new_uuid_file << uuid_string;
314
      new_uuid_file.close();
315
      server_uuid= string(uuid_string);
316
    }
317
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
318
    if (mkdir("local", 0700) == -1)
1786.3.1 by Monty Taylor
Initial working local catalog.
319
    {
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
320
      switch (errno)
321
      {
322
      case EEXIST:
323
        break;
324
325
      case EACCES:
326
        {
327
          char cwd[1024];
328
          unireg_abort << "Could not create local catalog, permission denied in directory:" << getcwd(cwd, sizeof(cwd));
329
        }
330
331
      default:
332
        {
333
          char cwd[1024];
334
          unireg_abort << "Could not create local catalog, in directory:" << getcwd(cwd, sizeof(cwd)) << " system error was:" << strerror(errno);
335
        }
336
      }
1786.3.1 by Monty Taylor
Initial working local catalog.
337
    }
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
338
339
    if (chdir("local") == -1)
1786.3.1 by Monty Taylor
Initial working local catalog.
340
    {
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
341
      unireg_abort << "Local catalog does not exist, was unable to chdir() to " << getDataHome().file_string();
1786.3.1 by Monty Taylor
Initial working local catalog.
342
    }
1813.2.9 by Monty Taylor
Made data_home be fs::path natively.
343
2318.5.30 by Olaf van der Spek
Refactor
344
    setFullDataHome(boost::filesystem::system_complete(getDataHome()));
345
    errmsg_printf(error::INFO, "Data Home directory is : %s", getFullDataHome().native_file_string().c_str());
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
346
  }
1786.3.1 by Monty Taylor
Initial working local catalog.
347
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
348
  if (server_id == 0)
349
  {
350
    server_id= 1;
351
  }
352
2095.3.6 by Monty Taylor
Actually properly process module dependencies. w00t.
353
  try
354
  {
2318.6.57 by Olaf van der Spek
Refactor
355
    init_server_components(modules);
2095.3.6 by Monty Taylor
Actually properly process module dependencies. w00t.
356
  }
357
  catch (abort_exception& ex)
358
  {
359
#if defined(DEBUG)
360
    cout << _("Drizzle has receieved an abort event.") << endl;
361
    cout << _("In Function: ") << *::boost::get_error_info<boost::throw_function>(ex) << endl;
362
    cout << _("In File: ") << *::boost::get_error_info<boost::throw_file>(ex) << endl;
363
    cout << _("On Line: ") << *::boost::get_error_info<boost::throw_line>(ex) << endl;
364
#endif
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
365
    unireg_abort << "init_server_components() failed";
2095.3.6 by Monty Taylor
Actually properly process module dependencies. w00t.
366
  }
367
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
368
1471.3.2 by Monty Taylor
Merged in old drizzled-as-lib patch.
369
  /**
370
   * This check must be done after init_server_components for now
371
   * because we don't yet have plugin dependency tracking...
372
   *
373
   * ReplicationServices::evaluateRegisteredPlugins() will print error messages to stderr
374
   * via errmsg_printf().
375
   *
376
   * @todo
377
   *
378
   * not checking return since unireg_abort() hangs
379
   */
2318.6.73 by Olaf van der Spek
Refactor
380
  (void) ReplicationServices::evaluateRegisteredPlugins();
1471.3.2 by Monty Taylor
Merged in old drizzled-as-lib patch.
381
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
382
  if (plugin::Listen::setup())
2363.1.6 by Brian Aker
Add better error messages for issues on startup.
383
  {
384
    unireg_abort << "Failed plugin::Listen::setup()";
385
  }
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
386
1300.5.17 by Monty Taylor
Merged trunk.
387
  assert(plugin::num_trx_monitored_objects > 0);
2302.1.3 by Olaf van der Spek
New / make_shared doesn't return NULL
388
  drizzle_rm_tmp_tables();
389
  errmsg_printf(error::INFO, _(ER(ER_STARTUP)), internal::my_progname, PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
390
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
391
  /* Send server startup event */
392
  {
2302.1.4 by Olaf van der Spek
Refactor
393
    Session::shared_ptr session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local());
2318.6.22 by Olaf van der Spek
Refactor
394
    setCurrentSession(session.get());
2318.6.62 by Olaf van der Spek
Refactor
395
    TransactionServices::sendStartupEvent(*session);
2302.1.4 by Olaf van der Spek
Refactor
396
    plugin_startup_window(modules, *session.get());
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
397
  }
398
2131.10.2 by Stewart Smith
wait until after the server has started up properly and about ready to receive connections before returning control if --daemon. Also make errors/logs on stderr still appear.
399
  if (opt_daemon)
2363.1.7 by Brian Aker
This shifts the closing of the socket to after we know that no errors are going to occur.
400
  {
2131.10.2 by Stewart Smith
wait until after the server has started up properly and about ready to receive connections before returning control if --daemon. Also make errors/logs on stderr still appear.
401
    daemon_is_ready();
2363.1.7 by Brian Aker
This shifts the closing of the socket to after we know that no errors are going to occur.
402
  }
2040.7.2 by Monty Taylor
Revert unneeded change to the while loop.
403
2440.4.2 by Brian Aker
Fix level_t to be more inline with syslog
404
405
  errmsg_printf(error::INFO, "Drizzle startup complete, listening for connections will now begin.");
406
2227.4.3 by Olaf van der Spek
Remove unnecessary statement.h include
407
  /*
2039.6.3 by Brian Aker
Update for session to have a catalog object.
408
    Listen for new connections and start new session for each connection
2040.7.2 by Monty Taylor
Revert unneeded change to the while loop.
409
     accepted. The listen.getClient() method will return NULL when the server
2039.6.3 by Brian Aker
Update for session to have a catalog object.
410
     should be shutdown.
411
   */
2302.1.4 by Olaf van der Spek
Refactor
412
  while (plugin::Client* client= plugin::Listen::getClient())
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
413
  {
2281.4.5 by Olaf van der Spek
Prune & refactor
414
    Session::shared_ptr session= Session::make_shared(client, client->catalog());
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
415
2040.7.2 by Monty Taylor
Revert unneeded change to the while loop.
416
    /* If we error on creation we drop the connection and delete the session. */
417
    if (Session::schedule(session))
418
      Session::unlink(session);
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
419
  }
420
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
421
  /* Send server shutdown event */
422
  {
2302.1.4 by Olaf van der Spek
Refactor
423
    Session::shared_ptr session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local());
2318.6.22 by Olaf van der Spek
Refactor
424
    setCurrentSession(session.get());
2318.6.62 by Olaf van der Spek
Refactor
425
    TransactionServices::sendShutdownEvent(*session.get());
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
426
  }
427
1932.3.4 by Brian Aker
Move counter lock so that ownership is held by session_list.
428
  {
2275.3.2 by Olaf van der Spek
Session Cache
429
    boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
1932.3.4 by Brian Aker
Move counter lock so that ownership is held by session_list.
430
    select_thread_in_use= false;			// For close_connections
431
  }
1689.2.5 by Brian Aker
Convert COND_thread_count to boost.
432
  COND_thread_count.notify_all();
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
433
434
  /* Wait until cleanup is done */
2282.1.2 by Olaf van der Spek
Session Cache
435
  session::Cache::shutdownSecond();
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
436
437
  clean_up(1);
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
438
  module::Registry::shutdown();
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
439
  internal::my_end();
1798.3.1 by Brian Aker
Remove native_handle usage.
440
2440.4.2 by Brian Aker
Fix level_t to be more inline with syslog
441
  errmsg_printf(error::INFO, "Drizzle is now shutting down");
442
1300.5.2 by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then
443
  return 0;
444
}
445