[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ptsname_r on OSF/1
From: |
Bruno Haible |
Subject: |
Re: ptsname_r on OSF/1 |
Date: |
Thu, 10 Nov 2011 13:48:30 +0100 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
Let's try to deal with the compilation error first:
> * OSF/1 5.1:
>
> Compilation error
>
> cc -O -DHAVE_CONFIG_H -I. -I.. -DGNULIB_STRICT_CHECKING=1
> -DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib -c
> test-ptsname_r.c
> cc: Error: test-ptsname_r.c, line 22: In the initializer for
> signature_check22, "ptsname_r" is not declared. (undeclared)
> SIGNATURE_CHECK (ptsname_r, int, (int, char *, size_t));
> ^
> *** Exit 1
OSF/1 has a function
extern int ptsname_r __((int, char *, int));
and the manual page says:
[Tru64 UNIX] The ptsname_r() function is an obsolete reentrant version of
the ptsname() function. It is supported in order to maintain backward com-
patibility with previous versions of the operating system and should not be
used in new designs.
This function returns -1, not errno. This is allowed by the glibc documentation
and the Linux man page.
But this function ignores its buflen argument. I get trace output like this from
fprintf (stderr, "buflen=%d -> %d %d %s\n", (int)buflen, result, errno, buffer);
calling with buflen=0
buflen=0 -> 0 0 /dev/pts/9
calling with buflen=1
buflen=1 -> 0 0 /dev/pts/9
calling with buflen=2
buflen=2 -> 0 0 /dev/pts/9
calling with buflen=3
buflen=3 -> 0 0 /dev/pts/9
calling with buflen=4
buflen=4 -> 0 0 /dev/pts/9
calling with buflen=5
buflen=5 -> 0 0 /dev/pts/9
calling with buflen=6
buflen=6 -> 0 0 /dev/pts/9
calling with buflen=7
buflen=7 -> 0 0 /dev/pts/9
calling with buflen=8
buflen=8 -> 0 0 /dev/pts/9
calling with buflen=9
buflen=9 -> 0 0 /dev/pts/9
calling with buflen=10
buflen=10 -> 0 0 /dev/pts/9
calling with buflen=11
calling with buflen=12
calling with buflen=13
calling with buflen=14
calling with buflen=15
calling with buf=NULL
Segmentation fault (core dumped)
So we cannot use this function. I'm applying this fix, which makes it use the
same replacement as on other platforms. Still, the test fails:
PASS: test-ptsname
test-ptsname_r.c:77: assertion failed
FAIL: test-ptsname_r
Cause: ptsname_r fails with errno = ENOENT.
2011-11-10 Bruno Haible <address@hidden>
ptsname_r: Avoid compilation error on OSF/1 5.1.
* lib/stdlib.in.h (ptsname_r): Override if REPLACE_PTSNAME_R is 1.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_PTSNAME_R.
* m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): Set REPLACE_PTSNAME_R if the
function is not declared or incompatibly declared.
* modules/stdlib (Makefile.am): Substitute REPLACE_PTSNAME_R.
* modules/ptsname_r (Depends-on, configure.ac): Update.
* doc/glibc-functions/ptsname_r.texi: Mention the OSF/1 problems.
--- doc/glibc-functions/ptsname_r.texi.orig Thu Nov 10 13:43:36 2011
+++ doc/glibc-functions/ptsname_r.texi Thu Nov 10 13:35:40 2011
@@ -11,6 +11,13 @@
MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11 2010-11, Cygwin 1.7.9, mingw,
MSVC 9, BeOS.
address@hidden
+This function is not declared unless @code{_REENTRANT} is defined,
+on some platforms:
+OSF/1 5.1.
address@hidden
+This function has an incompatible declaration on some platforms:
+OSF/1 5.1.
@end itemize
Portability problems not fixed by Gnulib:
--- lib/stdlib.in.h.orig Thu Nov 10 13:43:36 2011
+++ lib/stdlib.in.h Thu Nov 10 12:41:37 2011
@@ -459,10 +459,19 @@
/* Set the pathname of the pseudo-terminal slave associated with
the master FD is open on and return 0, or set errno and return
non-zero on errors. */
-# if address@hidden@
+# if @REPLACE_PTSNAME_R@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef ptsname_r
+# define ptsname_r rpl_ptsname_r
+# endif
+_GL_FUNCDECL_RPL (ptsname_r, int, (int fd, char *buf, size_t len));
+_GL_CXXALIAS_RPL (ptsname_r, int, (int fd, char *buf, size_t len));
+# else
+# if address@hidden@
_GL_FUNCDECL_SYS (ptsname_r, int, (int fd, char *buf, size_t len));
-# endif
+# endif
_GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len));
+# endif
_GL_CXXALIASWARN (ptsname_r);
#elif defined GNULIB_POSIXCHECK
# undef ptsname_r
--- m4/ptsname_r.m4.orig Thu Nov 10 13:43:36 2011
+++ m4/ptsname_r.m4 Thu Nov 10 13:34:27 2011
@@ -1,4 +1,4 @@
-# ptsname_r.m4 serial 1
+# ptsname_r.m4 serial 2
dnl Copyright (C) 2010-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -14,6 +14,33 @@
AC_CHECK_FUNCS_ONCE([ptsname_r])
if test $ac_cv_func_ptsname_r = no; then
HAVE_PTSNAME_R=0
+ else
+ dnl On OSF/1 5.1, the type of the third argument is 'int', not 'size_t',
+ dnl and the declaration is missing if _REENTRANT is not defined.
+ AC_CACHE_CHECK([whether ptsname_r has the same signature as in glibc],
+ [gl_cv_func_ptsname_r_signature_ok],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stddef.h>
+ #include <stdlib.h>
+ /* Test whether ptsname_r is declared at all. */
+ int (*f) (int, char *, size_t) = ptsname_r;
+ /* Test whether it has the same declaration as in glibc. */
+ #undef ptsname_r
+ extern
+ #ifdef __cplusplus
+ "C"
+ #endif
+ int ptsname_r (int, char *, size_t);
+ ]],
+ [[return f (0, NULL, 0);]])
+ ],
+ [gl_cv_func_ptsname_r_signature_ok=yes],
+ [gl_cv_func_ptsname_r_signature_ok=no])
+ ])
+ if test $gl_cv_func_ptsname_r_signature_ok = no; then
+ REPLACE_PTSNAME_R=1
+ fi
fi
])
--- m4/stdlib_h.m4.orig Thu Nov 10 13:43:36 2011
+++ m4/stdlib_h.m4 Thu Nov 10 12:42:08 2011
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 38
+# stdlib_h.m4 serial 39
dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -99,6 +99,7 @@
REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC])
REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC])
REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
+ REPLACE_PTSNAME_R=0; AC_SUBST([REPLACE_PTSNAME_R])
REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC])
REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH])
--- modules/ptsname_r.orig Thu Nov 10 13:43:36 2011
+++ modules/ptsname_r Thu Nov 10 13:23:40 2011
@@ -8,11 +8,11 @@
Depends-on:
stdlib
extensions
-ttyname_r [test $HAVE_PTSNAME_R = 0]
+ttyname_r [test $HAVE_PTSNAME_R = 0 || test $REPLACE_PTSNAME_R = 1]
configure.ac:
gl_FUNC_PTSNAME_R
-if test $HAVE_PTSNAME_R = 0; then
+if test $HAVE_PTSNAME_R = 0 || test $REPLACE_PTSNAME_R = 1; then
AC_LIBOBJ([ptsname_r])
gl_PREREQ_PTSNAME_R
fi
--- modules/stdlib.orig Thu Nov 10 13:43:36 2011
+++ modules/stdlib Thu Nov 10 12:42:32 2011
@@ -93,6 +93,7 @@
-e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
-e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
-e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
+ -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
-e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
-e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
-e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
--
In memoriam Cornstalk <http://en.wikipedia.org/wiki/Cornstalk>
- [PATCH 0/4] add ptsname_r, Eric Blake, 2011/11/07
- [PATCH 2/4] ptsname_r-tests: new test module, Eric Blake, 2011/11/07
- Re: [PATCH 2/4] ptsname_r-tests: new test module, Bruno Haible, 2011/11/08
- Re: [PATCH 2/4] ptsname_r-tests: new test module, Bruno Haible, 2011/11/10
- Re: [PATCH 2/4] ptsname_r-tests: new test module, Bruno Haible, 2011/11/10
- Re: [PATCH 2/4] ptsname_r-tests: new test module, Eric Blake, 2011/11/10
- Re: [PATCH 2/4] ptsname_r-tests: new test module, Bruno Haible, 2011/11/10
- Re: [PATCH 2/4] ptsname_r-tests: new test module, Eric Blake, 2011/11/10
[PATCH 4/4] ptsname_r: work around FreeBSD issue, Eric Blake, 2011/11/07
[PATCH 3/4] ptsname_r: port to Solaris, Eric Blake, 2011/11/07
[PATCH 1/4] ptsname_r: new module, Eric Blake, 2011/11/07