aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/session-env.c7
-rw-r--r--common/simple-pwquery.c2
-rw-r--r--common/util.h12
3 files changed, 15 insertions, 6 deletions
diff --git a/common/session-env.c b/common/session-env.c
index ff9044732..478d5e3be 100644
--- a/common/session-env.c
+++ b/common/session-env.c
@@ -338,8 +338,11 @@ session_env_getenv_or_default (session_env_t se, const char *name,
/* Get the default value with an additional fallback for GPG_TTY. */
defvalue = getenv (name);
- if ((!defvalue || !*defvalue) && !strcmp (name, "GPG_TTY") && ttyname (0))
- defvalue = ttyname (0);
+ if ((!defvalue || !*defvalue) && !strcmp (name, "GPG_TTY")
+ && gnupg_ttyname (0))
+ {
+ defvalue = gnupg_ttyname (0);
+ }
if (defvalue)
{
/* Record the default value for later use so that we are safe
diff --git a/common/simple-pwquery.c b/common/simple-pwquery.c
index 23e4b893a..08f59d246 100644
--- a/common/simple-pwquery.c
+++ b/common/simple-pwquery.c
@@ -222,7 +222,7 @@ agent_send_all_options (int fd)
}
dft_ttyname = getenv ("GPG_TTY");
-#ifndef HAVE_W32_SYSTEM
+#if !defined(HAVE_W32_SYSTEM) && !defined(HAVE_BROKEN_TTYNAME)
if ((!dft_ttyname || !*dft_ttyname) && ttyname (0))
dft_ttyname = ttyname (0);
#endif
diff --git a/common/util.h b/common/util.h
index 5ea7b819a..c8a008fd7 100644
--- a/common/util.h
+++ b/common/util.h
@@ -291,15 +291,21 @@ int gnupg_compare_version (const char *a, const char *b);
/*-- Simple replacement functions. */
-#ifndef HAVE_TTYNAME
+
+/* We use the gnupg_ttyname macro to be safe not to run into conflicts
+ which an extisting but broken ttyname. */
+#if !defined(HAVE_TTYNAME) || defined(HAVE_BROKEN_TTYNAME)
+# define gnupg_ttyname(n) _gnupg_ttyname ((n))
/* Systems without ttyname (W32) will merely return NULL. */
static inline char *
-ttyname (int fd)
+_gnupg_ttyname (int fd)
{
(void)fd;
return NULL;
}
-#endif /* !HAVE_TTYNAME */
+#else /*HAVE_TTYNAME*/
+# define gnupg_ttyname(n) ttyname ((n))
+#endif /*HAVE_TTYNAME */
#ifdef HAVE_W32CE_SYSTEM
#define getpid() GetCurrentProcessId ()