1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

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.
This commit is contained in:
Werner Koch 2012-11-20 19:01:13 +01:00
parent e7bc5012c5
commit 835698b72b
6 changed files with 24 additions and 9 deletions

View File

@ -662,7 +662,7 @@ main (int argc, char **argv )
} }
if (!err) if (!err)
{ {
s = ttyname (0); s = gnupg_ttyname (0);
if (s) if (s)
err = session_env_setenv (opt.startup_env, "GPG_TTY", 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. */ /* Make sure that we have a default ttyname. */
if (!default_ttyname && ttyname (1)) if (!default_ttyname && gnupg_ttyname (1))
default_ttyname = xstrdup (ttyname (1)); default_ttyname = xstrdup (ttyname (1));
if (!default_ttytype && getenv ("TERM")) if (!default_ttytype && getenv ("TERM"))
default_ttytype = xstrdup (getenv ("TERM")); default_ttytype = xstrdup (getenv ("TERM"));

View File

@ -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. */ /* Get the default value with an additional fallback for GPG_TTY. */
defvalue = getenv (name); defvalue = getenv (name);
if ((!defvalue || !*defvalue) && !strcmp (name, "GPG_TTY") && ttyname (0)) if ((!defvalue || !*defvalue) && !strcmp (name, "GPG_TTY")
defvalue = ttyname (0); && gnupg_ttyname (0))
{
defvalue = gnupg_ttyname (0);
}
if (defvalue) if (defvalue)
{ {
/* Record the default value for later use so that we are safe /* Record the default value for later use so that we are safe

View File

@ -222,7 +222,7 @@ agent_send_all_options (int fd)
} }
dft_ttyname = getenv ("GPG_TTY"); 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)) if ((!dft_ttyname || !*dft_ttyname) && ttyname (0))
dft_ttyname = ttyname (0); dft_ttyname = ttyname (0);
#endif #endif

View File

@ -291,15 +291,21 @@ int gnupg_compare_version (const char *a, const char *b);
/*-- Simple replacement functions. */ /*-- 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. */ /* Systems without ttyname (W32) will merely return NULL. */
static inline char * static inline char *
ttyname (int fd) _gnupg_ttyname (int fd)
{ {
(void)fd; (void)fd;
return NULL; return NULL;
} }
#endif /* !HAVE_TTYNAME */ #else /*HAVE_TTYNAME*/
# define gnupg_ttyname(n) ttyname ((n))
#endif /*HAVE_TTYNAME */
#ifdef HAVE_W32CE_SYSTEM #ifdef HAVE_W32CE_SYSTEM
#define getpid() GetCurrentProcessId () #define getpid() GetCurrentProcessId ()

View File

@ -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([waitpid wait4 sigaction sigprocmask pipe getaddrinfo])
AC_CHECK_FUNCS([ttyname rand ftello fsync stat lstat]) 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>]) AC_CHECK_TYPES([struct sigaction, sigset_t],,,[#include <signal.h>])
# Dirmngr requires mmap on Unix systems. # Dirmngr requires mmap on Unix systems.

View File

@ -57,7 +57,7 @@ setup_pinentry_env (void)
{ {
log_error (_("GPG_TTY has not been set - " log_error (_("GPG_TTY has not been set - "
"using maybe bogus default\n")); "using maybe bogus default\n"));
lc = ttyname (0); lc = gnupg_ttyname (0);
if (!lc) if (!lc)
lc = "/dev/tty"; lc = "/dev/tty";
gnupg_setenv ("GPG_TTY", lc, 1); gnupg_setenv ("GPG_TTY", lc, 1);