GPGME CVS branched

Marcus Brinkmann marcus.brinkmann at ruhr-uni-bochum.de
Sat Dec 11 14:42:23 CET 2004


At Sat, 11 Dec 2004 13:04:43 +0100,
Michael Nottebrock <michaelnottebrock at gmx.net> wrote:
> 
> [1  <text/plain; iso-8859-1 (quoted-printable)>]
> On Tuesday, 7. December 2004 19:54, Marcus Brinkmann wrote:
> 
> gpgme has recently been changed to use ttyname_r in gpgsm-engine.c. ttyname_r 
> is not available on a lot of platforms, including FreeBSD - it would be nice 
> if ttyname_r usage could be optionalised and checked for by configure.

Please add ttyname_r to FreeBSD if at all possible.  It is POSIX by now.

Is ttyname() on FreeBSD thread safe?  Not having a thread-safe way
means you make GPGME thread-unsafe.  It's a small race, and ttyname is
not used much, and even if it is used its value usually doesn't
change.  But nevertheless it is there.  So please consider adding
ttyname_r to FreeBSD also.

I can put in a check and fall back to ttyname with a warning.  It's
what we do for getenv already.  Can you please test the patch below?
If it detects the lack of ttyname_r, issues a warning and compiles and
links in the replacement function, I will apply it.  Please let me
know.  (Of course you need to rerun autogen.sh after applying).

Thanks,
Marcus


Index: configure.ac
===================================================================
RCS file: /cvs/gnupg/gpgme/configure.ac,v
retrieving revision 1.94
diff -u -p -r1.94 configure.ac
--- configure.ac	7 Dec 2004 21:13:36 -0000	1.94
+++ configure.ac	11 Dec 2004 13:36:13 -0000
@@ -169,6 +170,15 @@ AC_REPLACE_FUNCS(stpcpy)
 AC_REPLACE_FUNCS(vasprintf)
 if test "$ac_cv_func_vasprintf" != yes; then
   GNUPG_CHECK_VA_COPY
+fi
+
+# Try to find a thread-safe version of ttyname().
+AC_REPLACE_FUNCS(ttyname_r)
+if test "$ac_cv_func_ttyname_r" != yes; then
+  AC_MSG_WARN([
+***
+*** ttyname() is not thread-safe and ttyname_r() does not exist
+***])
 fi
 
 # Try to find a thread-safe version of getenv().
--- /dev/null	2004-09-14 00:34:58.000000000 +0200
+++ gpgme/ttyname_r.c	2004-12-11 14:32:29.000000000 +0100
@@ -0,0 +1,43 @@
+/* ttyname_r.c - A ttyname_r() replacement.
+   Copyright (C) 2003, 2004 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 Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 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
+   Lesser General Public License for more details.
+   
+   You should have received a copy of the GNU Lesser General Public
+   License along with this program; 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 <unistd.h>
+
+
+#warning ttyname is not thread-safe, and ttyname_r is missing
+
+int ttyname_r(int fd, char *buf, size_t buflen)
+{
+  char *tty;
+
+  tty = ttyname (fd);
+  if (!tty)
+    return errno;
+  
+  strncpy (buf, tty, buflen);
+  buf[buflen - 1] = '\0';
+  return (strlen (tty) >= buflen) ? ERANGE : 0;
+}




More information about the Gnupg-devel mailing list