mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-02 12:01:32 +01:00
common: Add a global variable to for the default error source.
For the shared code parts it is cumbersome to pass an error sourse variable to each function. Its value is always a constant for a given binary and thus a global variable makes things a lot easier than the former macro stuff. * common/init.c (default_errsource): New global var. (init_common_subsystems): Rename to _init_common_subsystems. Set DEFAULT_ERRSOURCE. * common/init.h: Assert value of GPG_ERR_SOURCE_DEFAULT. (init_common_subsystems): New macro. * common/util.h (default_errsource): Add declaration. * kbx/keybox-defs.h: Add some GPG_ERR_SOURCE_DEFAULT trickery.
This commit is contained in:
parent
ecda65498a
commit
eb0faef81d
@ -52,6 +52,8 @@
|
||||
#include "exechelp.h"
|
||||
#include "asshelp.h"
|
||||
#include "../include/cipher.h" /* for PUBKEY_ALGO_ECDSA, PUBKEY_ALGO_ECDH */
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
enum cmd_and_opt_values
|
||||
{ aNull = 0,
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "simple-pwquery.h"
|
||||
#include "i18n.h"
|
||||
#include "sysutils.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
enum cmd_and_opt_values
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "i18n.h"
|
||||
#include "get-passphrase.h"
|
||||
#include "sysutils.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
enum cmd_and_opt_values
|
||||
|
@ -37,6 +37,12 @@
|
||||
#include "util.h"
|
||||
|
||||
|
||||
/* The default error source of the application. This is different
|
||||
from GPG_ERR_SOURCE_DEFAULT in that it does not depend on the
|
||||
source file and thus is usable in code shared by applications. */
|
||||
gpg_err_source_t default_errsource;
|
||||
|
||||
|
||||
#ifdef HAVE_W32CE_SYSTEM
|
||||
static void parse_std_file_handles (int *argcp, char ***argvp);
|
||||
static void
|
||||
@ -74,10 +80,16 @@ writestring_via_estream (int mode, const char *string)
|
||||
required for logging is ready. ARGCP and ARGVP are the addresses
|
||||
of the parameters given to main. This function may modify them.
|
||||
|
||||
This function should be called only via the macro
|
||||
init_common_subsystems.
|
||||
|
||||
CAUTION: This might be called while running suid(root). */
|
||||
void
|
||||
init_common_subsystems (int *argcp, char ***argvp)
|
||||
_init_common_subsystems (gpg_err_source_t errsource, int *argcp, char ***argvp)
|
||||
{
|
||||
/* Store the error source in a gloabl variable. */
|
||||
default_errsource = errsource;
|
||||
|
||||
/* Try to auto set the character set. */
|
||||
set_native_charset (NULL);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* init.h - Definitions for init fucntions.
|
||||
* Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2007, 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
@ -20,7 +20,15 @@
|
||||
#ifndef GNUPG_COMMON_INIT_H
|
||||
#define GNUPG_COMMON_INIT_H
|
||||
|
||||
void init_common_subsystems (int *argcp, char ***argvp);
|
||||
#ifndef GPG_ERR_SOURCE_DEFAULT
|
||||
# error GPG_ERR_SOURCE_DEFAULT is not defined
|
||||
#elseif GPG_ERR_SOURCE_DEFAULT == GPG_ERR_SOURCE_UNKNOWN
|
||||
# error GPG_ERR_SOURCE_DEFAULT has default value
|
||||
#endif
|
||||
|
||||
void _init_common_subsystems (gpg_err_source_t errsource,
|
||||
int *argcp, char ***argvp);
|
||||
#define init_common_subsystems(a,b) \
|
||||
_init_common_subsystems (GPG_ERR_SOURCE_DEFAULT, (a), (b))
|
||||
|
||||
#endif /*GNUPG_COMMON_INIT_H*/
|
||||
|
@ -63,7 +63,6 @@
|
||||
#include "../common/utf8conv.h"
|
||||
#include "../common/dynload.h"
|
||||
|
||||
#include "init.h"
|
||||
#include "gettime.h"
|
||||
|
||||
/* Redefine asprintf by our estream version which uses our own memory
|
||||
@ -113,6 +112,12 @@ typedef char **rl_completion_func_t (const char *, int, int);
|
||||
#define xmalloc_clear(a) gcry_xcalloc (1, (a))
|
||||
#define xmalloc_secure_clear(a) gcry_xcalloc_secure (1, (a))
|
||||
|
||||
/* The default error source of the application. This is different
|
||||
from GPG_ERR_SOURCE_DEFAULT in that it does not depend on the
|
||||
source file and thus is usable in code shared by applications.
|
||||
Defined by init.c. */
|
||||
extern gpg_err_source_t default_errsource;
|
||||
|
||||
/* Convenience function to return a gpg-error code for memory
|
||||
allocation failures. This function makes sure that an error will
|
||||
be returned even if accidently ERRNO is not set. */
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include "ldapserver.h"
|
||||
#include "asshelp.h"
|
||||
#include "ldap-wrapper.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
/* The plain Windows version uses the windows service system. For
|
||||
example to start the service you may use "sc start dirmngr".
|
||||
|
@ -57,6 +57,7 @@
|
||||
|
||||
#include "i18n.h"
|
||||
#include "util.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
/* With the ldap wrapper, there is no need for the npth_unprotect and leave
|
||||
functions; thus we redefine them to nops. If we are not using the
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include "gc-opt-flags.h"
|
||||
#include "asshelp.h"
|
||||
#include "call-dirmngr.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
#if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__)
|
||||
#define MY_O_BINARY O_BINARY
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "sysutils.h"
|
||||
#include "status.h"
|
||||
#include "call-agent.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
enum cmd_and_opt_values {
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "sysutils.h"
|
||||
#include "gc-opt-flags.h"
|
||||
#include "asshelp.h"
|
||||
#include "../common/init.h"
|
||||
#include "keyblob.h"
|
||||
#include "server.h"
|
||||
#include "runner.h"
|
||||
|
@ -34,11 +34,11 @@
|
||||
#include "../common/stringhelp.h"
|
||||
#include "../common/utf8conv.h"
|
||||
#include "i18n.h"
|
||||
#include "init.h"
|
||||
#include "keybox-defs.h"
|
||||
|
||||
#include "../common/init.h"
|
||||
#include <gcrypt.h>
|
||||
|
||||
|
||||
enum cmd_and_opt_values {
|
||||
aNull = 0,
|
||||
oArmor = 'a',
|
||||
|
@ -21,9 +21,12 @@
|
||||
#define KEYBOX_DEFS_H 1
|
||||
|
||||
#ifdef GPG_ERR_SOURCE_DEFAULT
|
||||
#error GPG_ERR_SOURCE_DEFAULT already defined
|
||||
# if GPG_ERR_SOURCE_DEFAULT != GPG_ERR_SOURCE_KEYBOX
|
||||
# error GPG_ERR_SOURCE_DEFAULT already defined
|
||||
# endif
|
||||
#else
|
||||
# define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_KEYBOX
|
||||
#endif
|
||||
#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_KEYBOX
|
||||
#include <gpg-error.h>
|
||||
#define map_assuan_err(a) \
|
||||
map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
|
||||
|
@ -53,6 +53,8 @@
|
||||
#include "mkdtemp.h"
|
||||
#include "gc-opt-flags.h"
|
||||
#include "asshelp.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
enum cmd_and_opt_values
|
||||
{ aNull = 0,
|
||||
|
@ -38,6 +38,8 @@
|
||||
#include "sysutils.h"
|
||||
#include "gc-opt-flags.h"
|
||||
#include "asshelp.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "util.h"
|
||||
#include "i18n.h"
|
||||
#include "sysutils.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
enum cmd_and_opt_values
|
||||
|
@ -37,6 +37,7 @@
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
# include "../common/exechelp.h"
|
||||
#endif
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
#define CONTROL_D ('D' - 'A' + 1)
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "gpgconf.h"
|
||||
#include "i18n.h"
|
||||
#include "sysutils.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
|
||||
/* Constants to identify the commands and options. */
|
||||
enum cmd_and_opt_values
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "i18n.h"
|
||||
#include "sysutils.h"
|
||||
#include "../common/openpgpdefs.h"
|
||||
#include "../common/init.h"
|
||||
|
||||
#include "gpgtar.h"
|
||||
|
||||
|
@ -89,6 +89,7 @@
|
||||
#define JNLIB_NEED_LOG_LOGV
|
||||
#include "i18n.h"
|
||||
#include "../common/util.h"
|
||||
#include "../common/init.h"
|
||||
#include "mkdtemp.h"
|
||||
|
||||
/* FIXME: Bah. For spwq_secure_free. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user