Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix SO_PEERCRED and struct ucred support under glibc 2.8.

  • Loading branch information...
commit 64a3779811dd9965d864c8b9c85c49a261c4eb69 1 parent 8cd9250
@bos bos authored
Showing with 38 additions and 4 deletions.
  1. +2 −2 Network/Socket.hsc
  2. +34 −0 configure.ac
  3. +2 −2 network.buildinfo.in
View
4 Network/Socket.hsc
@@ -95,7 +95,7 @@ module Network.Socket (
getPeerName, -- :: Socket -> IO SockAddr
getSocketName, -- :: Socket -> IO SockAddr
-#ifdef SO_PEERCRED
+#ifdef HAVE_STRUCT_UCRED
-- get the credentials of our domain socket peer.
getPeerCred, -- :: Socket -> IO (CUInt{-pid-}, CUInt{-uid-}, CUInt{-gid-})
#endif
@@ -1171,7 +1171,7 @@ getSocketOption (MkSocket s _ _ _ _) so = do
fromIntegral `liftM` peek ptr_v
-#ifdef SO_PEERCRED
+#ifdef HAVE_STRUCT_UCRED
-- | Returns the processID, userID and groupID of the socket's peer.
--
-- Only available on platforms that support SO_PEERCRED on domain sockets.
View
34 configure.ac
@@ -40,6 +40,39 @@ AC_EGREP_HEADER(in_addr_t, netinet/in.h,
AC_MSG_RESULT(no))
dnl --------------------------------------------------
+dnl * test for SO_PEERCRED and struct ucred
+dnl --------------------------------------------------
+AC_MSG_CHECKING(for SO_PEERCRED and struct ucred in sys/socket.h)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#include <sys/socket.h>
+#ifndef SO_PEERCRED
+# error no SO_PEERCRED
+#endif
+struct ucred u;]])],ac_cv_ucred=yes,ac_cv_ucred=no)
+if test "x$ac_cv_ucred" = xno; then
+ old_CFLAGS="$CFLAGS"
+ CFLAGS="-D_GNU_SOURCE $CFLAGS"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#include <sys/socket.h>
+#ifndef SO_PEERCRED
+# error no SO_PEERCRED
+#endif
+struct ucred u;]])],ac_cv_ucred=yes,ac_cv_ucred=no)
+ if test "x$ac_cv_ucred" = xyes; then
+ EXTRA_CPPFLAGS=-D_GNU_SOURCE
+ fi
+else
+ old_CFLAGS="$CFLAGS"
+fi
+if test "x$ac_cv_ucred" = xno; then
+ CFLAGS="$old_CFLAGS"
+ AC_MSG_RESULT(no)
+else
+ AC_DEFINE([HAVE_STRUCT_UCRED], [1], [Define to 1 if you have both SO_PEERCRED and struct ucred.])
+ AC_MSG_RESULT(yes)
+fi
+
+dnl --------------------------------------------------
dnl * test for getaddrinfo as proxy for IPv6 support
dnl --------------------------------------------------
AC_CHECK_FUNCS(getaddrinfo)
@@ -83,6 +116,7 @@ case "$host" in
CALLCONV=ccall ;;
esac
AC_SUBST([CALLCONV])
+AC_SUBST([EXTRA_CPPFLAGS])
AC_SUBST([EXTRA_LIBS])
AC_SUBST([EXTRA_SRCS])
View
4 network.buildinfo.in
@@ -1,4 +1,4 @@
-ghc-options: -DCALLCONV=@CALLCONV@
-cc-options: -DCALLCONV=@CALLCONV@
+ghc-options: -DCALLCONV=@CALLCONV@ @EXTRA_CPPFLAGS@
+cc-options: -DCALLCONV=@CALLCONV@ @EXTRA_CPPFLAGS@
c-sources: @EXTRA_SRCS@
extra-libraries: @EXTRA_LIBS@
Please sign in to comment.
Something went wrong with that request. Please try again.