passfd module, part 1.
[pspp] / m4 / afunix.m4
1 # afunix.m4 serial 1
2 dnl Copyright (C) 2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_SOCKET_AFUNIX],
8 [
9   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
10   AC_REQUIRE([gl_SOCKET_FAMILIES])
11
12   AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHT])
13   AC_CACHE_VAL([gl_cv_socket_unix_scm_rights],
14   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
15 #ifdef HAVE_SYS_SOCKET_H
16 #include <sys/socket.h>
17 #endif
18 #ifdef HAVE_SYS_UN_H
19 #include <sys/un.h>
20 #endif
21 #ifdef HAVE_WINSOCK2_H
22 #include <winsock2.h>
23 #endif
24 ]],
25 [[struct cmsghdr cmh;
26   cmh.cmsg_level = SOL_SOCKET;
27   cmh.cmsg_type = SCM_RIGHTS;
28   if (&cmh) return 0;]])],
29   gl_cv_socket_unix_scm_rights=yes, gl_cv_socket_unix_scm_rights=no)])
30   AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights])
31   if test $gl_cv_socket_unix_scm_rights = yes; then
32     AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS], [1], [Define to 1 if <sys/socket.h> defines SCM_RIGHTS.])
33   fi 
34
35   AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHT behave in BSD4.4 way])
36   AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd44_way],
37   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 #include <sys/socket.h>
40 #endif
41 #ifdef HAVE_SYS_UN_H
42 #include <sys/un.h>
43 #endif
44 #ifdef HAVE_WINSOCK2_H
45 #include <winsock2.h>
46 #endif
47 ]],
48 [[struct msghdr msg = {0};
49   struct cmsghdr *cmsg;
50   int myfds[1] = {0};
51   char buf[CMSG_SPACE(sizeof(myfds))];
52   int *fdptr;
53
54   msg.msg_control = buf;
55   msg.msg_controllen = sizeof buf;
56   cmsg = CMSG_FIRSTHDR(&msg);
57   cmsg->cmsg_level = SOL_SOCKET;
58   cmsg->cmsg_type = SCM_RIGHTS;
59   cmsg->cmsg_len = CMSG_LEN(sizeof(int));
60   /* fake Initialize the payload: */
61   (void) CMSG_DATA(cmsg);
62   /* Sum of the length of all control messages in the buffer: */
63   msg.msg_controllen = cmsg->cmsg_len;
64   return 0;
65 ]])],
66   gl_cv_socket_unix_scm_rights_bsd44_way=yes, gl_cv_socket_unix_scm_rights_bsd44_way=no)])
67   AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd44_way])
68   if test $gl_cv_socket_unix_scm_rights_bsd44_way = yes; then
69     AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY], [1], [Define to 1 if fd could be send/received in the BSD4.4 way.])
70   fi
71
72   AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHT behave in BSD4.3 way])
73   AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd43_way],
74   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
75 #ifdef HAVE_SYS_SOCKET_H
76 #include <sys/socket.h>
77 #endif
78 #ifdef HAVE_SYS_UN_H
79 #include <sys/un.h>
80 #endif
81 #ifdef HAVE_WINSOCK2_H
82 #include <winsock2.h>
83 #endif
84 ]],
85 [[struct msghdr msg;
86   int fd = 0;
87   msg.msg_accrights = &fd;
88   msg.msg_accrightslen = sizeof(fd);
89   if (&msg) return 0;]])],
90   gl_cv_socket_unix_scm_rights_bsd43_way=yes, gl_cv_socket_unix_scm_rights_bsd43_way=no)])
91   AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd43_way])
92   if test $gl_cv_socket_unix_scm_rights_bsd43_way = yes; then
93     AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY], [1], [Define to 1 if fd could be send/received in the BSD4.3 way.])
94   fi
95 ])