~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/signal_handler/signal_handler.cc

  • Committer: Olaf van der Spek
  • Date: 2011-04-20 09:27:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2285.
  • Revision ID: olafvdspek@gmail.com-20110420092749-hw1q9rfj1pumc2no
Session Cache

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2006 MySQL AB
 
1
/* 
 
2
   Copyright (C) 2011 Brian Aker
 
3
   Copyright (C) 2006 MySQL AB
2
4
 
3
5
   This program is free software; you can redistribute it and/or modify
4
6
   it under the terms of the GNU General Public License as published by
13
15
   along with this program; if not, write to the Free Software
14
16
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
17
 
16
 
#include "config.h"
 
18
#include <config.h>
17
19
#include <drizzled/gettext.h>
18
20
#include <drizzled/error.h>
19
21
#include <drizzled/unireg.h>
20
22
#include <drizzled/plugin/storage_engine.h>
21
 
#include <drizzled/cursor.h> /* for refresh_version */
22
 
#include "drizzled/pthread_globals.h"
23
 
#include "drizzled/internal/my_pthread.h"
24
 
#include "drizzled/internal/my_sys.h"
25
 
#include "drizzled/plugin/daemon.h"
26
 
#include "drizzled/signal_handler.h"
27
 
 
28
 
#include "drizzled/session/cache.h"
29
 
 
30
 
#include "drizzled/drizzled.h"
 
23
#include <drizzled/pthread_globals.h>
 
24
#include <drizzled/internal/my_pthread.h>
 
25
#include <drizzled/internal/my_sys.h>
 
26
#include <drizzled/plugin/daemon.h>
 
27
#include <drizzled/signal_handler.h>
 
28
#include <drizzled/session.h>
 
29
#include <drizzled/session/cache.h>
 
30
#include <drizzled/debug.h>
 
31
#include <drizzled/drizzled.h>
 
32
#include <drizzled/open_tables_state.h>
31
33
 
32
34
#include <boost/thread/thread.hpp>
33
35
#include <boost/filesystem.hpp>
47
49
extern boost::filesystem::path pid_file;
48
50
/* Prototypes -> all of these should be factored out into a propper shutdown */
49
51
extern void close_connections(void);
50
 
extern std::bitset<12> test_flags;
51
52
}
52
53
 
53
54
using namespace drizzled;
76
77
  if (sig != 0) // 0 is not a valid signal number
77
78
    ignore_signal(sig);                    /* purify inspected */
78
79
  if (sig == SIGTERM || sig == 0)
79
 
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_NORMAL_SHUTDOWN)),internal::my_progname);
 
80
    errmsg_printf(error::INFO, _(ER(ER_NORMAL_SHUTDOWN)),internal::my_progname);
80
81
  else
81
 
    errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_GOT_SIGNAL)),internal::my_progname,sig);
 
82
    errmsg_printf(error::ERROR, _(ER(ER_GOT_SIGNAL)),internal::my_progname,sig);
 
83
 
82
84
  close_connections();
83
85
  clean_up(1);
84
86
}
117
119
  sigset_t set;
118
120
  int sig;
119
121
  internal::my_thread_init();                           // Init new thread
120
 
  boost::this_thread::at_thread_exit(&internal::my_thread_end);
121
122
  signal_thread_in_use= true;
122
123
 
123
 
  if ((test_flags.test(TEST_SIGINT)))
 
124
  if ((drizzled::getDebug().test(drizzled::debug::ALLOW_SIGINT)))
124
125
  {
125
126
    (void) sigemptyset(&set);                   // Setup up SIGINT for debug
126
127
    (void) sigaddset(&set,SIGINT);              // For debugging
127
 
    (void) pthread_sigmask(SIG_UNBLOCK,&set,NULL);
 
128
    (void) pthread_sigmask(SIG_UNBLOCK, &set, NULL);
128
129
  }
129
130
  (void) sigemptyset(&set);                     // Setup up SIGINT for debug
130
131
#ifndef IGNORE_SIGHUP_SIGQUIT
161
162
    (Asked MontyW over the phone about this.) -Brian
162
163
 
163
164
  */
164
 
  session::Cache::singleton().mutex().lock();
165
 
  session::Cache::singleton().mutex().unlock();
 
165
  session::Cache::mutex().lock();
 
166
  session::Cache::mutex().unlock();
166
167
  COND_thread_count.notify_all();
167
168
 
168
169
  if (pthread_sigmask(SIG_BLOCK, &set, NULL))
205
206
    case SIGHUP:
206
207
      if (!abort_loop)
207
208
      {
208
 
        refresh_version++;
 
209
        g_refresh_version++;
209
210
        drizzled::plugin::StorageEngine::flushLogs(NULL);
210
211
      }
211
212
      break;
227
228
    drizzled::plugin::Daemon("Signal Handler")
228
229
  {
229
230
    // @todo fix spurious wakeup issue
230
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
231
    boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
231
232
    thread= boost::thread(signal_hand);
232
233
    signal_thread= thread.native_handle();
233
234
    COND_thread_count.wait(scopedLock);
279
280
}
280
281
 
281
282
 
282
 
static drizzle_sys_var* system_variables[]= {
283
 
  NULL
284
 
};
285
 
 
286
283
DRIZZLE_DECLARE_PLUGIN
287
284
{
288
285
  DRIZZLE_VERSION_ID,
292
289
  "Default Signal Handler",
293
290
  PLUGIN_LICENSE_GPL,
294
291
  init, /* Plugin Init */
295
 
  system_variables,   /* system variables */
 
292
  NULL,   /* depends */
296
293
  NULL    /* config options */
297
294
}
298
295
DRIZZLE_DECLARE_PLUGIN_END;