1 /* g13-common.c - Common code for G13 modules
2 * Copyright (C) 2009, 2015 Werner Koch
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
29 #include "g13-common.h"
37 /* Global variable to keep an error count. */
38 int g13_errors_seen = 0;
42 /* Note: This function is used by signal handlers!. */
44 emergency_cleanup (void)
46 gcry_control (GCRYCTL_TERM_SECMEM);
50 /* Wrapper around gnupg_init_signals. */
52 g13_init_signals (void)
54 gnupg_init_signals (0, emergency_cleanup);
58 /* Install a regular exit handler to make real sure that the secure
59 memory gets wiped out. */
61 g13_install_emergency_cleanup (void)
63 if (atexit (emergency_cleanup))
65 log_error ("atexit failed\n");
71 /* Use this function instead of exit() in all g13 modules. */
75 gcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE);
76 if (opt.debug & DBG_MEMSTAT_VALUE)
78 gcry_control( GCRYCTL_DUMP_MEMORY_STATS );
79 gcry_control( GCRYCTL_DUMP_RANDOM_STATS );
82 gcry_control (GCRYCTL_DUMP_SECMEM_STATS );
84 rc = rc? rc : log_get_errorcount(0)? 2 : g13_errors_seen? 1 : 0;