summaryrefslogtreecommitdiff
path: root/monitor_fdpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r--monitor_fdpass.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c
index 4b9a066bc..3d3a78391 100644
--- a/monitor_fdpass.c
+++ b/monitor_fdpass.c
@@ -32,6 +32,7 @@
32#ifdef HAVE_SYS_UN_H 32#ifdef HAVE_SYS_UN_H
33#include <sys/un.h> 33#include <sys/un.h>
34#endif 34#endif
35#include <sys/utsname.h>
35 36
36#include <errno.h> 37#include <errno.h>
37#include <string.h> 38#include <string.h>
@@ -40,6 +41,29 @@
40#include "log.h" 41#include "log.h"
41#include "monitor_fdpass.h" 42#include "monitor_fdpass.h"
42 43
44static int
45cmsg_type_is_broken(void)
46{
47 static int broken_cmsg_type = -1;
48
49 if (broken_cmsg_type != -1)
50 return broken_cmsg_type;
51 else {
52 struct utsname uts;
53 /* If uname() fails, play safe and assume that cmsg_type
54 * isn't broken.
55 */
56 if (!uname(&uts) &&
57 strcmp(uts.sysname, "Linux") == 0 &&
58 strncmp(uts.release, "2.0.", 4) == 0)
59 broken_cmsg_type = 1;
60 else
61 broken_cmsg_type = 0;
62 }
63
64 return broken_cmsg_type;
65}
66
43int 67int
44mm_send_fd(int sock, int fd) 68mm_send_fd(int sock, int fd)
45{ 69{
@@ -152,13 +176,11 @@ mm_receive_fd(int sock)
152 return -1; 176 return -1;
153 } 177 }
154 178
155#ifndef BROKEN_CMSG_TYPE 179 if (!cmsg_type_is_broken() && cmsg->cmsg_type != SCM_RIGHTS) {
156 if (cmsg->cmsg_type != SCM_RIGHTS) {
157 error("%s: expected type %d got %d", __func__, 180 error("%s: expected type %d got %d", __func__,
158 SCM_RIGHTS, cmsg->cmsg_type); 181 SCM_RIGHTS, cmsg->cmsg_type);
159 return -1; 182 return -1;
160 } 183 }
161#endif
162 fd = (*(int *)CMSG_DATA(cmsg)); 184 fd = (*(int *)CMSG_DATA(cmsg));
163#endif 185#endif
164 return fd; 186 return fd;