~drizzle-trunk/drizzle/development

1300.5.22 by Monty Taylor
Moved and reworked a wrapper around sigset - which we shouldn't be using
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *  Copyright (C) 2010 Monty Taylor
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; version 2 of the License.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
#ifndef DRIZZLED_SIGNAL_HANDLER_H
22
#define DRIZZLED_SIGNAL_HANDLER_H
23
24
#include <signal.h>
25
26
#include <cstdlib>
27
#include <cassert>
1733.3.1 by LinuxJedi
Make exit happen in main thread rather than signal handler thread thus avoiding a segfault due to a double kill of the signal handler thread
28
static bool volatile signal_thread_in_use= false;
1300.5.22 by Monty Taylor
Moved and reworked a wrapper around sigset - which we shouldn't be using
29
extern "C" void drizzled_print_signal_warning(int sig);
30
extern "C" void drizzled_handle_segfault(int sig);
31
extern "C" void drizzled_end_thread_signal(int sig);
32
33
/*
34
  posix sigaction() based signal handler implementation
35
  On some systems, such as Mac OS X, sigset() results in flags
36
  such as SA_RESTART being set, and we want to make sure that no such
37
  flags are set.
38
*/
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
39
static inline void ignore_signal(int sig)
1300.5.22 by Monty Taylor
Moved and reworked a wrapper around sigset - which we shouldn't be using
40
{
41
  /* Wow. There is a function sigaction which takes a pointer to a
42
    struct sigaction. */
43
  struct sigaction l_s;
44
  sigset_t l_set;
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
45
  sigemptyset(&l_set);
1300.5.22 by Monty Taylor
Moved and reworked a wrapper around sigset - which we shouldn't be using
46
47
  assert(sig != 0);
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
48
  l_s.sa_handler= SIG_IGN;
1300.5.22 by Monty Taylor
Moved and reworked a wrapper around sigset - which we shouldn't be using
49
  l_s.sa_mask= l_set;
50
  l_s.sa_flags= 0;
1300.5.23 by Monty Taylor
Merged in revs removing depend on the plugin tree.
51
  int l_rc= sigaction(sig, &l_s, NULL);
1300.5.22 by Monty Taylor
Moved and reworked a wrapper around sigset - which we shouldn't be using
52
  assert(l_rc == 0);
53
}
54
55
#endif /* DRIZZLED_SIGNAL_HANDLER_H */