[cpp-sp] 03/04: Check for strerror_r() with C++ language selected
Scott Cantor
cantor.2 at osu.edu
Fri Jun 29 12:32:57 EDT 2018
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository cpp-sp.
View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=926808051e06e2ce14ec0576d79ff05fc92029aa
commit 926808051e06e2ce14ec0576d79ff05fc92029aa
Author: Ferenc Wágner <wferi at niif.hu>
AuthorDate: Mon Jul 18 12:58:16 2016 +0200
Check for strerror_r() with C++ language selected
---
configure.ac | 7 ++++++-
shibsp/remoting/impl/SocketListener.cpp | 12 ++++++++----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index 6f3f6b4..eeed13b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,7 +77,6 @@ AC_HEADER_DIRENT
# Checks for library functions.
AC_FUNC_STRFTIME
-AC_FUNC_STRERROR_R
AC_CHECK_HEADERS([sys/utsname.h grp.h pwd.h])
AC_CHECK_HEADERS([sys/socket.h], [AC_DEFINE([SHIBSP_HAVE_SYS_SOCKET_H],[1],[Define to 1 if you have the <sys/socket> header file.])], [])
AC_CHECK_FUNCS([strchr strdup strstr timegm gmtime_r localtime_r strtok_r strcasecmp getpwnam getgrnam initgroups])
@@ -103,6 +102,12 @@ ACX_PTHREAD(
AC_LANG([C++])
+# On GNU/Linux, g++ always defines the preprocessor macro _GNU_SOURCE
+# because libstdc++ requires it. This in turn selects the GNU version of
+# strerror_r(), which returns char* and may not use the passed buffer
+# (see https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.predefined).
+AC_FUNC_STRERROR_R
+
# C++ requirements
AC_CXX_NAMESPACES
AC_CXX_REQUIRE_STL
diff --git a/shibsp/remoting/impl/SocketListener.cpp b/shibsp/remoting/impl/SocketListener.cpp
index d6f3145..af5e29f 100644
--- a/shibsp/remoting/impl/SocketListener.cpp
+++ b/shibsp/remoting/impl/SocketListener.cpp
@@ -402,14 +402,18 @@ bool SocketListener::log_error(const char* fn) const
#else
int rc=errno;
#endif
+ const char *msg;
#ifdef HAVE_STRERROR_R
char buf[256];
- memset(buf,0,sizeof(buf));
- strerror_r(rc,buf,sizeof(buf));
+#ifdef STRERROR_R_CHAR_P
+ msg = strerror_r(rc,buf,sizeof(buf));
#else
- const char* buf=strerror(rc);
+ msg = strerror_r(rc,buf,sizeof(buf)) ? "<translation failed>" : buf;
#endif
- log->error("failed socket call (%s), result (%d): %s", fn, rc, isprint(*buf) ? buf : "no message");
+#else
+ msg=strerror(rc);
+#endif
+ log->error("failed socket call (%s), result (%d): %s", fn, rc, isprint(*msg) ? msg : "no message");
return false;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list