~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/signal_handler/signal_handler.cc

  • Committer: lbieber
  • Date: 2010-10-05 22:23:12 UTC
  • mfrom: (1813.1.4 build)
  • Revision ID: lbieber@orisndriz08-20101005222312-weuq0ardk3gcryau
Merge Travis - 621861 - convert structs to classes
Merge Billy - 621331 - Replace use of stringstream with boost::lexical_cast
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle
Merge Andrew - fix bug 653300 - Syntax error on inport of a SQL file produced by drizzledump

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
   Copyright (C) 2011 Brian Aker
3
 
   Copyright (C) 2006 MySQL AB
 
1
/* Copyright (C) 2006 MySQL AB
4
2
 
5
3
   This program is free software; you can redistribute it and/or modify
6
4
   it under the terms of the GNU General Public License as published by
16
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
17
15
 
18
16
#include "config.h"
19
 
 
20
17
#include <drizzled/gettext.h>
21
18
#include <drizzled/error.h>
22
19
#include <drizzled/unireg.h>
23
20
#include <drizzled/plugin/storage_engine.h>
 
21
#include <drizzled/cursor.h> /* for refresh_version */
24
22
#include "drizzled/pthread_globals.h"
25
23
#include "drizzled/internal/my_pthread.h"
26
24
#include "drizzled/internal/my_sys.h"
27
25
#include "drizzled/plugin/daemon.h"
28
26
#include "drizzled/signal_handler.h"
29
27
 
30
 
#include <drizzled/session.h>
31
 
#include <drizzled/session/cache.h>
32
 
 
33
 
#include "drizzled/debug.h"
34
 
 
35
28
#include "drizzled/drizzled.h"
36
29
 
37
 
#include <drizzled/refresh_version.h>
38
 
 
39
30
#include <boost/thread/thread.hpp>
40
 
#include <boost/filesystem.hpp>
41
31
 
42
32
#include <sys/stat.h>
43
33
#include <fcntl.h>
51
41
extern int cleanup_done;
52
42
extern bool volatile abort_loop;
53
43
extern bool volatile shutdown_in_progress;
54
 
extern boost::filesystem::path pid_file;
 
44
extern char pidfile_name[FN_REFLEN];
55
45
/* Prototypes -> all of these should be factored out into a propper shutdown */
56
46
extern void close_connections(void);
 
47
extern std::bitset<12> test_flags;
57
48
}
58
49
 
59
50
using namespace drizzled;
60
51
 
61
52
 
62
53
 
63
 
 
64
54
/**
65
55
  Force server down. Kill all connections and threads and exit.
66
56
 
72
62
    or stop, we just want to kill the server.
73
63
*/
74
64
 
75
 
static void kill_server(int sig)
 
65
static void kill_server(void *sig_ptr)
76
66
{
 
67
  int sig=(int) (long) sig_ptr;                 // This is passed a int
77
68
  // if there is a signal during the kill in progress, ignore the other
78
69
  if (kill_in_progress)                         // Safety
79
70
    return;
82
73
  if (sig != 0) // 0 is not a valid signal number
83
74
    ignore_signal(sig);                    /* purify inspected */
84
75
  if (sig == SIGTERM || sig == 0)
85
 
    errmsg_printf(error::INFO, _(ER(ER_NORMAL_SHUTDOWN)),internal::my_progname);
 
76
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_NORMAL_SHUTDOWN)),internal::my_progname);
86
77
  else
87
 
    errmsg_printf(error::ERROR, _(ER(ER_GOT_SIGNAL)),internal::my_progname,sig);
88
 
 
 
78
    errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_GOT_SIGNAL)),internal::my_progname,sig);
89
79
  close_connections();
90
80
  clean_up(1);
91
81
}
98
88
  int file;
99
89
  char buff[1024];
100
90
 
101
 
  if ((file = open(pid_file.file_string().c_str(), O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU|S_IRGRP|S_IROTH)) > 0)
 
91
  assert(pidfile_name[0]);
 
92
  if ((file = open(pidfile_name, O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU|S_IRGRP|S_IROTH)) > 0)
102
93
  {
103
94
    int length;
104
95
 
112
103
    (void)close(file); /* We can ignore the error, since we are going to error anyway at this point */
113
104
  }
114
105
  memset(buff, 0, sizeof(buff));
115
 
  snprintf(buff, sizeof(buff)-1, "Can't start server: can't create PID file (%s)", pid_file.file_string().c_str());
 
106
  snprintf(buff, sizeof(buff)-1, "Can't start server: can't create PID file (%s)", pidfile_name);
116
107
  sql_perror(buff);
117
108
  exit(1);
118
109
}
127
118
  boost::this_thread::at_thread_exit(&internal::my_thread_end);
128
119
  signal_thread_in_use= true;
129
120
 
130
 
  if ((drizzled::getDebug().test(drizzled::debug::ALLOW_SIGINT)))
 
121
  if ((test_flags.test(TEST_SIGINT)))
131
122
  {
132
123
    (void) sigemptyset(&set);                   // Setup up SIGINT for debug
133
124
    (void) sigaddset(&set,SIGINT);              // For debugging
134
 
    (void) pthread_sigmask(SIG_UNBLOCK, &set, NULL);
 
125
    (void) pthread_sigmask(SIG_UNBLOCK,&set,NULL);
135
126
  }
136
127
  (void) sigemptyset(&set);                     // Setup up SIGINT for debug
137
128
#ifndef IGNORE_SIGHUP_SIGQUIT
168
159
    (Asked MontyW over the phone about this.) -Brian
169
160
 
170
161
  */
171
 
  session::Cache::singleton().mutex().lock();
172
 
  session::Cache::singleton().mutex().unlock();
 
162
  LOCK_thread_count.lock();
 
163
  LOCK_thread_count.unlock();
173
164
  COND_thread_count.notify_all();
174
165
 
175
166
  if (pthread_sigmask(SIG_BLOCK, &set, NULL))
206
197
      if (!abort_loop)
207
198
      {
208
199
        abort_loop=1;                           // mark abort for threads
209
 
        kill_server(sig);               // MIT THREAD has a alarm thread
 
200
        kill_server((void*) sig);       // MIT THREAD has a alarm thread
210
201
      }
211
202
      break;
212
203
    case SIGHUP:
234
225
    drizzled::plugin::Daemon("Signal Handler")
235
226
  {
236
227
    // @todo fix spurious wakeup issue
237
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
228
    boost::mutex::scoped_lock scopedLock(LOCK_thread_count);
238
229
    thread= boost::thread(signal_hand);
239
230
    signal_thread= thread.native_handle();
240
231
    COND_thread_count.wait(scopedLock);
286
277
}
287
278
 
288
279
 
 
280
static drizzle_sys_var* system_variables[]= {
 
281
  NULL
 
282
};
 
283
 
289
284
DRIZZLE_DECLARE_PLUGIN
290
285
{
291
286
  DRIZZLE_VERSION_ID,
295
290
  "Default Signal Handler",
296
291
  PLUGIN_LICENSE_GPL,
297
292
  init, /* Plugin Init */
298
 
  NULL,   /* depends */
 
293
  system_variables,   /* system variables */
299
294
  NULL    /* config options */
300
295
}
301
296
DRIZZLE_DECLARE_PLUGIN_END;