LCOV - code coverage report
Current view: top level - src - setsignal.c (source / functions) Hit Total Coverage
Test: app.info Lines: 2 2 100.0 %
Date: 2010-12-13 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * See the file "COPYING" in the main distribution directory for copyright.
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef lint
       6                 :            : static const char rcsid[] =
       7                 :            :     "@(#) $Id: setsignal.c 6219 2008-10-01 05:39:07Z vern $ (LBL)";
       8                 :            : #endif
       9                 :            : 
      10                 :            : #include "config.h"                   /* must appear before first ifdef */
      11                 :            : 
      12                 :            : #include <sys/types.h>
      13                 :            : 
      14                 :            : #ifdef HAVE_MEMORY_H
      15                 :            : #include <memory.h>
      16                 :            : #endif
      17                 :            : #include <signal.h>
      18                 :            : #ifdef HAVE_SIGACTION
      19                 :            : #include <string.h>
      20                 :            : #endif
      21                 :            : 
      22                 :            : #include "setsignal.h"
      23                 :            : 
      24                 :            : /*
      25                 :            :  * An os independent signal() with BSD semantics, e.g. the signal
      26                 :            :  * catcher is restored following service of the signal.
      27                 :            :  *
      28                 :            :  * When sigset() is available, signal() has SYSV semantics and sigset()
      29                 :            :  * has BSD semantics and call interface. Unfortunately, Linux does not
      30                 :            :  * have sigset() so we use the more complicated sigaction() interface
      31                 :            :  * there.
      32                 :            :  *
      33                 :            :  * Did I mention that signals suck?
      34                 :            :  */
      35                 :            : RETSIGTYPE
      36                 :            : (*setsignal (int sig, RETSIGTYPE (*func)(int)))(int)
      37                 :          4 : {
      38                 :            : #ifdef HAVE_SIGACTION
      39                 :            :         struct sigaction old, new;
      40                 :            : 
      41                 :            :         memset(&new, 0, sizeof(new));
      42                 :            :         new.sa_handler = func;
      43                 :            : #ifdef SA_RESTART
      44                 :            :         new.sa_flags |= SA_RESTART;
      45                 :            : #endif
      46                 :            :         if (sigaction(sig, &new, &old) < 0)
      47                 :            :                 return (SIG_ERR);
      48                 :            :         return (old.sa_handler);
      49                 :            : 
      50                 :            : #else
      51                 :            : #ifdef HAVE_SIGSET
      52                 :          4 :         return (sigset(sig, func));
      53                 :            : #else
      54                 :            :         return (signal(sig, func));
      55                 :            : #endif
      56                 :            : #endif
      57                 :            : }
      58                 :            : 

Generated by: LCOV version 1.8