Drizzled Public API Documentation

signal_handler.h

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *  Copyright (C) 2010 Monty Taylor
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; version 2 of the License.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <signal.h>
00024 
00025 #include <cstdlib>
00026 #include <cassert>
00027 static bool volatile signal_thread_in_use= false;
00028 extern "C" void drizzled_print_signal_warning(int sig);
00029 extern "C" void drizzled_handle_segfault(int sig);
00030 extern "C" void drizzled_end_thread_signal(int sig);
00031 
00032 /*
00033   posix sigaction() based signal handler implementation
00034   On some systems, such as Mac OS X, sigset() results in flags
00035   such as SA_RESTART being set, and we want to make sure that no such
00036   flags are set.
00037 */
00038 static inline void ignore_signal(int sig)
00039 {
00040   /* Wow. There is a function sigaction which takes a pointer to a
00041     struct sigaction. */
00042   struct sigaction l_s;
00043   sigset_t l_set;
00044   sigemptyset(&l_set);
00045 
00046   assert(sig != 0);
00047   l_s.sa_handler= SIG_IGN;
00048   l_s.sa_mask= l_set;
00049   l_s.sa_flags= 0;
00050   int l_rc= sigaction(sig, &l_s, NULL);
00051   assert(l_rc == 0);
00052 }
00053