diff options
author | Werner Koch <[email protected]> | 2012-11-20 18:01:13 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2012-11-20 18:03:49 +0000 |
commit | 835698b72bc509565aad52b0753f1c56c1a8f062 (patch) | |
tree | dd5352b45d74cb3ef4b3091dcc16824ce57e4991 | |
parent | Fix non-portable use of chmod in autogen.sh. (diff) | |
download | gnupg-835698b72bc509565aad52b0753f1c56c1a8f062.tar.gz gnupg-835698b72bc509565aad52b0753f1c56c1a8f062.zip |
Do not use a broken ttyname.
* configure.ac (HAVE_BROKEN_TTYNAME): New ac_define set for Android
systems.
* common/util.h (gnupg_ttyname): New macro. Change all callers of
ttyname to use this macro instead.
(ttyname) [W32]: Rename to _gnupg_ttyname and use also if
HAVE_BROKEN_TTYNAME is defined.
* common/simple-pwquery.c (agent_send_all_options): Keep on using
ttyname unless HAVE_BROKEN_TTYNAME is set. This is because this file
may be used standalone.
-rw-r--r-- | agent/gpg-agent.c | 4 | ||||
-rw-r--r-- | common/session-env.c | 7 | ||||
-rw-r--r-- | common/simple-pwquery.c | 2 | ||||
-rw-r--r-- | common/util.h | 12 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | sm/misc.c | 2 |
6 files changed, 24 insertions, 9 deletions
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index b117849c5..32da578f0 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -662,7 +662,7 @@ main (int argc, char **argv ) } if (!err) { - s = ttyname (0); + s = gnupg_ttyname (0); if (s) err = session_env_setenv (opt.startup_env, "GPG_TTY", s); } @@ -984,7 +984,7 @@ main (int argc, char **argv ) } /* Make sure that we have a default ttyname. */ - if (!default_ttyname && ttyname (1)) + if (!default_ttyname && gnupg_ttyname (1)) default_ttyname = xstrdup (ttyname (1)); if (!default_ttytype && getenv ("TERM")) default_ttytype = xstrdup (getenv ("TERM")); 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 () diff --git a/configure.ac b/configure.ac index 90c77faaa..e821b997e 100644 --- a/configure.ac +++ b/configure.ac @@ -1247,6 +1247,12 @@ AC_CHECK_FUNCS([atexit raise getpagesize strftime nl_langinfo setlocale]) AC_CHECK_FUNCS([waitpid wait4 sigaction sigprocmask pipe getaddrinfo]) AC_CHECK_FUNCS([ttyname rand ftello fsync stat lstat]) +if test "$have_android_system" = yes; then + # On Android ttyname is a stub but prints an error message. + AC_DEFINE(HAVE_BROKEN_TTYNAME,1, + [Defined if ttyname does not work properly]) +fi + AC_CHECK_TYPES([struct sigaction, sigset_t],,,[#include <signal.h>]) # Dirmngr requires mmap on Unix systems. @@ -57,7 +57,7 @@ setup_pinentry_env (void) { log_error (_("GPG_TTY has not been set - " "using maybe bogus default\n")); - lc = ttyname (0); + lc = gnupg_ttyname (0); if (!lc) lc = "/dev/tty"; gnupg_setenv ("GPG_TTY", lc, 1); |