2003-09-13 Marcus Brinkmann <marcus@g10code.de>

* acinclude.m4: Remove libtool cruft, add jm_GLIBC21.
	* configure.ac: Add check for getenv_r, and call jm_GLIBC21.
	Define HAVE_THREAD_SAFE_GETENV if appropriate.

gpgme/
2003-09-13  Marcus Brinkmann  <marcus@g10code.de>

	* get-env.c: New file.
	* util.h (_gpgme_getenv): Add prototype.
	* Makefile.am (libgpgme_real_la_SOURCES): Add get-env.c.
	* rungpg.c (build_argv): Use _gpgme_getenv.
	* debug.c (debug_init): Likewise.
	* engine-gpgsm.c (gpgsm_new): Likewise.
	(gpgsm_new): Use ttyname_r.
	* w32-io.c (_gpgme_io_spawn): Disable debugging for now.
This commit is contained in:
Marcus Brinkmann 2003-09-13 17:45:04 +00:00
parent e4045aa72f
commit 727f0ba45d
12 changed files with 174 additions and 3706 deletions

View File

@ -1,3 +1,9 @@
2003-09-13 Marcus Brinkmann <marcus@g10code.de>
* acinclude.m4: Remove libtool cruft, add jm_GLIBC21.
* configure.ac: Add check for getenv_r, and call jm_GLIBC21.
Define HAVE_THREAD_SAFE_GETENV if appropriate.
2003-09-03 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Remove GPGME_CONFIG_LIBS and GPGME_CONFIG_CFLAGS.

4
TODO
View File

@ -1,7 +1,8 @@
Hey Emacs, this is -*- outline -*- mode!
* Before release:
** currently nothing
** set_locale for thread safe and env independent locale selection.
** Add gpgme_strerror_r() when gpg_strerror_r() exists.
* ABI's to break:
** I/O and User Data could be made extensible. But this can be done
@ -38,7 +39,6 @@ Hey Emacs, this is -*- outline -*- mode!
** --learn-code support
This might be integrated with import. we still need to work out how
to learn a card when gpg and gpgsm have support for smartcards.
** set_locale for thread safe and env independent locale selection.
** How to terminate a pending operation? Something like gpgme_op_reset,
but where are you allowed to call it (think callback handlers).
Then gpgme_op_*list_end can go. Update: The only place where this

File diff suppressed because it is too large Load Diff

View File

@ -157,10 +157,28 @@ if test "$ac_cv_func_vasprintf" != yes; then
GNUPG_CHECK_VA_COPY
fi
# Try to find a thread-safe version of getenv().
have_thread_safe_getenv=no
jm_GLIBC21
if test $GLIBC21 = yes; then
have_thread_safe_getenv=yes
fi
if test $have_thread_safe_getenv = yes; then
AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
fi
have_getenv_r=no
AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
AC_MSG_WARN([getenv() is not thread-safe and getenv_r() does not exist])
fi
# Checking for libgpg-error.
AM_PATH_GPG_ERROR(0.3,, AC_MSG_ERROR([libgpg-error was not found]))
AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
[The default error source for GPGME.])
# Checks for system services
NO_OVERRIDE=no
AC_ARG_WITH(gpg,

View File

@ -1,3 +1,14 @@
2003-09-13 Marcus Brinkmann <marcus@g10code.de>
* get-env.c: New file.
* util.h (_gpgme_getenv): Add prototype.
* Makefile.am (libgpgme_real_la_SOURCES): Add get-env.c.
* rungpg.c (build_argv): Use _gpgme_getenv.
* debug.c (debug_init): Likewise.
* engine-gpgsm.c (gpgsm_new): Likewise.
(gpgsm_new): Use ttyname_r.
* w32-io.c (_gpgme_io_spawn): Disable debugging for now.
2003-09-03 Marcus Brinkmann <marcus@g10code.de>
* gpgme-config.in: Use $libdir, not @libdir@, for the echo

View File

@ -68,7 +68,7 @@ gpgsm_components =
endif
libgpgme_real_la_SOURCES = \
gpgme.h util.h conversion.c context.h ops.h \
gpgme.h util.h conversion.c get-env.c context.h ops.h \
data.h data.c data-fd.c data-stream.c data-mem.c data-user.c \
data-compat.c \
signers.c \

View File

@ -84,9 +84,17 @@ debug_init (void)
LOCK (debug_lock);
if (!initialized)
{
const char *e = getenv ("GPGME_DEBUG");
gpgme_error_t err;
const char *e;
const char *s1, *s2;;
err = _gpgme_getenv ("GPGME_DEBUG", &e);
if (err)
{
UNLOCK (debug_lock);
return;
}
initialized = 1;
errfp = stderr;
if (e)
@ -123,6 +131,7 @@ debug_init (void)
}
#endif
}
free (e);
}
if (debug_level > 0)

View File

@ -302,7 +302,7 @@ gpgsm_new (void **engine)
int fds[2];
int child_fds[4];
char *dft_display = NULL;
char *dft_ttyname = NULL;
char dft_ttyname[64];
char *dft_ttytype = NULL;
char *old_lc = NULL;
char *dft_lc = NULL;
@ -403,14 +403,19 @@ gpgsm_new (void **engine)
gpgsm->status_cb.dir = 1;
gpgsm->status_cb.data = gpgsm;
dft_display = getenv ("DISPLAY");
err = _gpgme_getenv ("DISPLAY", &dft_display);
if (err)
goto leave;
if (dft_display)
{
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{
free (dft_display);
err = gpg_error_from_errno (errno);
goto leave;
}
free (dft_display);
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL);
free (optstr);
@ -420,8 +425,13 @@ gpgsm_new (void **engine)
goto leave;
}
}
dft_ttyname = ttyname (1);
if (dft_ttyname)
if (ttyname_r (1, dft_ttyname, sizeof (dft_ttyname)))
{
err = gpg_error_from_errno (errno);
goto leave;
}
else
{
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{
@ -437,14 +447,19 @@ gpgsm_new (void **engine)
goto leave;
}
dft_ttytype = getenv ("TERM");
err = _gpgme_getenv ("TERM", &dft_ttytype);
if (err)
goto leave;
if (dft_ttytype)
{
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{
free (dft_ttytype);
err = gpg_error_from_errno (errno);
goto leave;
}
free (dft_ttytype);
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
NULL, NULL, NULL);
free (optstr);

58
gpgme/get-env.c Normal file
View File

@ -0,0 +1,58 @@
/* get_env.c - A getenv() replacement.
Copyright (C) 2003 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPGME; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "util.h"
#if defined(HAVE_THREAD_SAFE_GETENV) || !defined (HAVE_GETENV_R)
/* We prefer using getenv() if it is thread-safe. */
/* Retrieve the environment variable NAME and return a copy of it in a
malloc()'ed buffer in *VALUE. If the environment variable is not
set, return NULL in *VALUE. */
gpgme_error_t
_gpgme_getenv (const char *name, char **value)
{
char *env_value;
env_value = getenv (name);
if (!env_value)
*value = NULL;
else
{
*value = strdup (env_value);
if (!*value)
return gpg_error_from_errno (errno);
}
return 0;
}
#else
/* FIXME: Implement this when we have the specification for it. */
#error Use of getenv_r not implemented.
#endif

View File

@ -503,6 +503,7 @@ gpg_set_command_handler (void *engine, engine_command_handler_t fnc,
static gpgme_error_t
build_argv (engine_gpg_t gpg)
{
gpgme_error_t err;
struct arg_and_data_s *a;
struct fd_data_map_s *fd_data_map;
size_t datac=0, argc=0;
@ -514,9 +515,13 @@ build_argv (engine_gpg_t gpg)
/* We don't want to use the agent with a malformed environment
variable. This is only a very basic test but sufficient to make
our life in the regression tests easier. */
p = getenv ("GPG_AGENT_INFO");
err = _gpgme_getenv ("GPG_AGENT_INFO", &p);
if (err)
return err;
use_agent = (p && strchr (p, ':'));
if (p)
free (p);
if (gpg->argv)
{
free_argv (gpg->argv);

View File

@ -72,4 +72,10 @@ gpgme_error_t _gpgme_decode_percent_string (const char *src, char **destp,
gpgme_error_t _gpgme_map_gnupg_error (char *err);
/* Retrieve the environment variable NAME and return a copy of it in a
malloc()'ed buffer in *VALUE. If the environment variable is not
set, return NULL in *VALUE. */
gpgme_error_t _gpgme_getenv (const char *name, char **value);
#endif /* UTIL_H */

View File

@ -806,7 +806,8 @@ _gpgme_io_spawn ( const char *path, char **argv,
int duped_stdin = 0;
int duped_stderr = 0;
HANDLE hnul = INVALID_HANDLE_VALUE;
int debug_me = !!getenv ("GPGME_DEBUG");
/* FIXME. */
int debug_me = 0;
memset (&sec_attr, 0, sizeof sec_attr );
sec_attr.nLength = sizeof sec_attr;