LCOV - code coverage report
Current view: top level - util - signal.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 14 35.7 %
Date: 2016-06-29 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    signal handling functions
       4             : 
       5             :    Copyright (C) Andrew Tridgell 1998
       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; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "util/util.h"
      22             : #include <sys/types.h>
      23             : #include <sys/wait.h>
      24             : 
      25             : 
      26             : /**
      27             :  * @file
      28             :  * @brief Signal handling
      29             :  */
      30             : 
      31             : /**
      32             :  Block sigs.
      33             : **/
      34             : 
      35           1 : void BlockSignals(bool block, int signum)
      36             : {
      37             : #ifdef HAVE_SIGPROCMASK
      38             :         sigset_t set;
      39           1 :         sigemptyset(&set);
      40           1 :         sigaddset(&set,signum);
      41           1 :         sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL);
      42             : #elif defined(HAVE_SIGBLOCK)
      43             :         if (block) {
      44             :                 sigblock(sigmask(signum));
      45             :         } else {
      46             :                 sigsetmask(siggetmask() & ~sigmask(signum));
      47             :         }
      48             : #else
      49             :         /* yikes! This platform can't block signals? */
      50             :         static int done;
      51             :         if (!done) {
      52             :                 DEBUG(SSSDBG_FATAL_FAILURE,"WARNING: No signal blocking available\n");
      53             :                 done=1;
      54             :         }
      55             : #endif
      56           1 : }
      57             : 
      58             : /**
      59             :  Catch a signal. This should implement the following semantics:
      60             : 
      61             :  1) The handler remains installed after being called.
      62             :  2) The signal should be blocked during handler execution.
      63             : **/
      64             : 
      65           0 : void (*CatchSignal(int signum,void (*handler)(int )))(int)
      66             : {
      67             : #ifdef HAVE_SIGACTION
      68             :         struct sigaction act;
      69             :         struct sigaction oldact;
      70             : 
      71           0 :         ZERO_STRUCT(act);
      72             : 
      73           0 :         act.sa_handler = handler;
      74             : #ifdef SA_RESTART
      75             :         /*
      76             :          * We *want* SIGALRM to interrupt a system call.
      77             :          */
      78           0 :         if(signum != SIGALRM)
      79           0 :                 act.sa_flags = SA_RESTART;
      80             : #endif
      81           0 :         sigemptyset(&act.sa_mask);
      82           0 :         sigaddset(&act.sa_mask,signum);
      83           0 :         sigaction(signum,&act,&oldact);
      84           0 :         return oldact.sa_handler;
      85             : #else /* !HAVE_SIGACTION */
      86             :         /* FIXME: need to handle sigvec and systems with broken signal() */
      87             :         return signal(signum, handler);
      88             : #endif
      89             : }

Generated by: LCOV version 1.10