~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/main.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-26 08:33:47 UTC
  • mto: (1795.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1796.
  • Revision ID: andrew@linuxjedi.co.uk-20100926083347-fzsc9e7w0j4u7bj1
Disable boost:po allow_guessing which was making some wrong assumptions

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <signal.h>
24
24
#include <sys/resource.h>
25
25
#include <unistd.h>
26
 
#include <sys/stat.h>
27
 
#include <sys/types.h>
28
 
 
29
26
 
30
27
#if TIME_WITH_SYS_TIME
31
28
# include <sys/time.h>
42
39
# include <locale.h>
43
40
#endif
44
41
 
45
 
#include <boost/filesystem.hpp>
46
42
 
47
43
#include "drizzled/plugin.h"
48
44
#include "drizzled/gettext.h"
49
45
#include "drizzled/configmake.h"
50
46
#include "drizzled/session.h"
51
 
#include "drizzled/session/cache.h"
52
47
#include "drizzled/internal/my_sys.h"
53
48
#include "drizzled/unireg.h"
54
49
#include "drizzled/drizzled.h"
60
55
#include "drizzled/tztime.h"
61
56
#include "drizzled/signal_handler.h"
62
57
#include "drizzled/replication_services.h"
63
 
#include "drizzled/transaction_services.h"
64
 
 
65
 
#include "drizzled/util/backtrace.h"
66
58
 
67
59
using namespace drizzled;
68
60
using namespace std;
69
 
namespace fs=boost::filesystem;
70
61
 
71
62
static pthread_t select_thread;
72
63
static uint32_t thr_kill_signal;
73
64
 
74
 
 
75
65
/**
76
66
  All global error messages are sent here where the first one is stored
77
67
  for the client.
205
195
  (void)filename;
206
196
  (void)line;
207
197
  (void)message;
208
 
  std::cerr << "\n";
209
 
  drizzled::util::custom_backtrace();
210
 
  std::cerr << "\n";
211
198
  switch(level)
212
199
  {
213
200
  case google::protobuf::LOGLEVEL_INFO:
216
203
  case google::protobuf::LOGLEVEL_ERROR:
217
204
  case google::protobuf::LOGLEVEL_FATAL:
218
205
  default:
219
 
    std::cerr << "GoogleProtoErrorThrower(" << filename << ", " << line << ", " << message << ")";
220
206
    throw("error in google protocol buffer parsing");
221
207
  }
222
208
}
233
219
 
234
220
  module::Registry &modules= module::Registry::singleton();
235
221
  plugin::Client *client;
 
222
  Session *session;
236
223
 
237
224
  MY_INIT(argv[0]);             // init my_sys library & pthreads
238
225
  /* nothing should come before this line ^^^ */
243
230
  google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
244
231
 
245
232
  /* Function generates error messages before abort */
246
 
  error_handler_hook= my_message_sql;
247
233
  /* init_common_variables must get basic settings such as data_home_dir
248
234
     and plugin_load_list. */
249
 
  if (init_common_variables(argc, argv, modules))
 
235
  if (init_common_variables(argc, argv))
250
236
    unireg_abort(1);                            // Will do exit
251
237
 
252
 
  /*
253
 
    init signals & alarm
254
 
    After this we can't quit by a simple unireg_abort
255
 
  */
256
238
  init_signals();
257
239
 
258
240
 
259
241
  select_thread=pthread_self();
260
242
  select_thread_in_use=1;
261
243
 
262
 
  if (not opt_help)
 
244
  if (chdir(data_home_real) && !opt_help)
263
245
  {
264
 
    if (chdir(getDataHome().file_string().c_str()))
265
 
    {
266
 
      errmsg_printf(ERRMSG_LVL_ERROR,
267
 
                    _("Data directory %s does not exist\n"),
268
 
                    getDataHome().file_string().c_str());
269
 
      unireg_abort(1);
270
 
    }
271
 
    if (mkdir("local", 0700))
272
 
    {
273
 
      /* We don't actually care */
274
 
    }
275
 
    if (chdir("local"))
276
 
    {
277
 
      errmsg_printf(ERRMSG_LVL_ERROR,
278
 
                    _("Local catalog %s/local does not exist\n"),
279
 
                    getDataHome().file_string().c_str());
280
 
      unireg_abort(1);
281
 
    }
282
 
 
283
 
    full_data_home= fs::system_complete(getDataHome());
284
 
    getDataHomeCatalog()= "./";
285
 
    getDataHome()= "../";
 
246
    errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), data_home_real);
 
247
    unireg_abort(1);
286
248
  }
287
 
 
288
 
 
 
249
  data_home= data_home_buff;
 
250
  data_home[0]=FN_CURLIB;               // all paths are relative from here
 
251
  data_home[1]=0;
 
252
  data_home_len= 2;
289
253
 
290
254
  if (server_id == 0)
291
255
  {
312
276
  if (plugin::Listen::setup())
313
277
    unireg_abort(1);
314
278
 
 
279
  /*
 
280
    init signals & alarm
 
281
    After this we can't quit by a simple unireg_abort
 
282
  */
 
283
  error_handler_hook= my_message_sql;
315
284
 
316
285
  assert(plugin::num_trx_monitored_objects > 0);
317
286
  if (drizzle_rm_tmp_tables() ||
321
290
    select_thread_in_use=0;
322
291
    (void) pthread_kill(signal_thread, SIGTERM);
323
292
 
324
 
    (void) unlink(pid_file.file_string().c_str());      // Not needed anymore
 
293
    (void) unlink(pidfile_name);        // Not needed anymore
325
294
 
326
295
    exit(1);
327
296
  }
330
299
                PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
331
300
 
332
301
 
333
 
  TransactionServices &transaction_services= TransactionServices::singleton();
334
 
 
335
 
  /* Send server startup event */
336
 
  {
337
 
    Session *session;
338
 
 
339
 
    if ((session= new Session(plugin::Listen::getNullClient())))
340
 
    {
341
 
      currentSession().release();
342
 
      currentSession().reset(session);
343
 
      transaction_services.sendStartupEvent(session);
344
 
      delete session;
345
 
    }
346
 
  }
347
 
 
348
 
 
349
302
  /* Listen for new connections and start new session for each connection
350
303
     accepted. The listen.getClient() method will return NULL when the server
351
304
     should be shutdown. */
352
305
  while ((client= plugin::Listen::getClient()) != NULL)
353
306
  {
354
 
    Session::shared_ptr session(new Session(client));
355
 
 
356
 
    if (not session)
 
307
    if (!(session= new Session(client)))
357
308
    {
358
309
      delete client;
359
310
      continue;
360
311
    }
361
312
 
362
313
    /* If we error on creation we drop the connection and delete the session. */
363
 
    if (Session::schedule(session))
 
314
    if (session->schedule())
364
315
      Session::unlink(session);
365
316
  }
366
317
 
367
 
  /* Send server shutdown event */
368
 
  {
369
 
    Session *session;
370
 
 
371
 
    if ((session= new Session(plugin::Listen::getNullClient())))
372
 
    {
373
 
      currentSession().release();
374
 
      currentSession().reset(session);
375
 
      transaction_services.sendShutdownEvent(session);
376
 
      delete session;
377
 
    }
378
 
  }
379
 
 
380
 
  {
381
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
382
 
    select_thread_in_use= false;                        // For close_connections
383
 
  }
 
318
  LOCK_thread_count.lock();
 
319
  select_thread_in_use=0;                       // For close_connections
 
320
  LOCK_thread_count.unlock();
384
321
  COND_thread_count.notify_all();
385
322
 
386
323
  /* Wait until cleanup is done */
387
 
  {
388
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
389
 
    while (not ready_to_exit)
390
 
      COND_server_end.wait(scopedLock);
391
 
  }
 
324
  LOCK_thread_count.lock();
 
325
  while (!ready_to_exit)
 
326
    pthread_cond_wait(COND_server_end.native_handle(), LOCK_thread_count.native_handle());
 
327
  LOCK_thread_count.unlock();
392
328
 
393
329
  clean_up(1);
394
330
  module::Registry::shutdown();
395
331
  internal::my_end();
396
 
 
397
332
  return 0;
398
333
}
399
334