Coverage Report

Created: 2025-03-06 06:58

/src/gnutls/lib/atfork.c
Line
Count
Source (jump to first uncovered line)
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
static void fork_handler(void)
40
0
{
41
0
  _gnutls_forkid++;
42
0
}
43
#endif
44
45
#if defined(HAVE___REGISTER_ATFORK)
46
extern int __register_atfork(void (*)(void), void (*)(void), void (*)(void),
47
           void *);
48
extern void *__dso_handle;
49
50
int _gnutls_register_fork_handler(void)
51
2
{
52
2
  if (__register_atfork(NULL, NULL, fork_handler, __dso_handle) != 0)
53
0
    return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
54
2
  return 0;
55
2
}
56
57
#else
58
59
unsigned int _gnutls_get_forkid(void)
60
{
61
  return getpid();
62
}
63
64
int _gnutls_detect_fork(unsigned int forkid)
65
{
66
  if ((unsigned int)getpid() == forkid)
67
    return 0;
68
  return 1;
69
}
70
71
/* we have to detect fork manually */
72
int _gnutls_register_fork_handler(void)
73
{
74
  _gnutls_forkid = getpid();
75
  return 0;
76
}
77
78
#endif
79
80
#endif /* !_WIN32 */