aboutsummaryrefslogtreecommitdiffstats
path: root/src/debug.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2012-09-25 13:38:26 +0000
committerWerner Koch <[email protected]>2012-09-25 13:38:26 +0000
commitc62b79a1d6e576d94e08cb81c2f5dbcb42ecf8cf (patch)
tree0c659d95d2a93943c65f86e2d8e626ad335081c8 /src/debug.c
parentRemove all trailing whitespace from source files (diff)
downloadgpgme-c62b79a1d6e576d94e08cb81c2f5dbcb42ecf8cf.tar.gz
gpgme-c62b79a1d6e576d94e08cb81c2f5dbcb42ecf8cf.zip
Add gpgme_set_global_flag to help debugging
* src/gpgme.c (gpgme_set_global_flag): New. * src/gpgme.h.in (gpgme_set_global_flag): New. * src/gpgme.def, src/libgpgme.vers: Add new public function. * src/debug.c (envvar_override): New.: (_gpgme_debug_set_debug_envvar): New. (debug_init): Take ENVVAR_OVERRIDE in account. -- On Android envvars can't be used, thus we need another way to enable GPGME debugging. The new function allows this and may be used in the future to implement similar things.
Diffstat (limited to '')
-rw-r--r--src/debug.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/debug.c b/src/debug.c
index 8e293b4e..56effa75 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -60,6 +60,12 @@ static int debug_level;
/* The output stream for the debug messages. */
static FILE *errfp;
+/* If not NULL, this malloced string is used instead of the
+ GPGME_DEBUG envvar. It must have been set before the debug
+ subsystem has been initialized. Using it later may or may not have
+ any effect. */
+static char *envvar_override;
+
#ifdef HAVE_TLS
#define FRAME_NR
@@ -109,6 +115,19 @@ trim_spaces (char *str)
}
+/* This is an internal function to set debug info. The caller must
+ assure that this function is called only by one thread at a time.
+ The function may have no effect if called after the debug system
+ has been initialized. Returns 0 on success. */
+int
+_gpgme_debug_set_debug_envvar (const char *value)
+{
+ free (envvar_override);
+ envvar_override = strdup (value);
+ return !envvar_override;
+}
+
+
static void
debug_init (void)
{
@@ -121,16 +140,25 @@ debug_init (void)
char *e;
const char *s1, *s2;;
+ if (envvar_override)
+ {
+ e = strdup (envvar_override);
+ free (envvar_override);
+ envvar_override = NULL;
+ }
+ else
+ {
#ifdef HAVE_W32CE_SYSTEM
- e = _gpgme_w32ce_get_debug_envvar ();
+ e = _gpgme_w32ce_get_debug_envvar ();
#else /*!HAVE_W32CE_SYSTEM*/
- err = _gpgme_getenv ("GPGME_DEBUG", &e);
- if (err)
- {
- UNLOCK (debug_lock);
- return;
- }
+ err = _gpgme_getenv ("GPGME_DEBUG", &e);
+ if (err)
+ {
+ UNLOCK (debug_lock);
+ return;
+ }
#endif /*!HAVE_W32CE_SYSTEM*/
+ }
initialized = 1;
errfp = stderr;