LCOV - code coverage report
Current view: top level - builds/gnutls/coverage/gnutls-git/lib - atfork.c (source / functions) Hit Total Coverage
Test: GnuTLS-3.6.14 Code Coverage Lines: 5 6 83.3 %
Date: 2020-10-30 04:50:48 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2010-2012 Free Software Foundation, Inc.
       3             :  * Copyright (C) 2014 Red Hat
       4             :  *
       5             :  * Author: Nikos Mavrogiannopoulos
       6             :  *
       7             :  * This file is part of GnuTLS.
       8             :  *
       9             :  * The GnuTLS is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public License
      11             :  * as published by the Free Software Foundation; either version 2.1 of
      12             :  * the License, or (at your option) any later version.
      13             :  *
      14             :  * This library is distributed in the hope that it will be useful, but
      15             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  *
      19             :  * You should have received a copy of the GNU Lesser General Public License
      20             :  * along with this program.  If not, see <https://www.gnu.org/licenses/>
      21             :  *
      22             :  */
      23             : 
      24             : #include <config.h>
      25             : #include "gnutls_int.h"
      26             : #include "errors.h"
      27             : 
      28             : #include <sys/socket.h>
      29             : #include <errno.h>
      30             : #include <sys/stat.h>
      31             : #include <sys/types.h>
      32             : #include <atfork.h>
      33             : 
      34             : unsigned int _gnutls_forkid = 0;
      35             : 
      36             : #ifndef _WIN32
      37             : 
      38             : # ifdef HAVE_ATFORK
      39         541 : static void fork_handler(void)
      40             : {
      41         541 :         _gnutls_forkid++;
      42         541 : }
      43             : # endif
      44             : 
      45             : # if defined(HAVE___REGISTER_ATFORK)
      46             : extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
      47             : extern void *__dso_handle;
      48             : 
      49        3400 : int _gnutls_register_fork_handler(void)
      50             : {
      51        3400 :         if (__register_atfork(NULL, NULL, fork_handler, __dso_handle) != 0)
      52           0 :                 return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
      53             :         return 0;
      54             : }
      55             : 
      56             : # else
      57             : 
      58             : unsigned int _gnutls_get_forkid(void)
      59             : {
      60             :         return getpid();
      61             : }
      62             : 
      63             : int _gnutls_detect_fork(unsigned int forkid)
      64             : {
      65             :         if ((unsigned int)getpid() == forkid)
      66             :                 return 0;
      67             :         return 1;
      68             : }
      69             : 
      70             : /* we have to detect fork manually */
      71             : int _gnutls_register_fork_handler(void)
      72             : {
      73             :         _gnutls_forkid = getpid();
      74             :         return 0;
      75             : }
      76             : 
      77             : # endif
      78             : 
      79             : #endif /* !_WIN32 */

Generated by: LCOV version 1.14