diff options
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r-- | monitor_fdpass.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c index cab538bc9..28296d64b 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 | ||
44 | static int | ||
45 | cmsg_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 | |||
43 | int | 67 | int |
44 | mm_send_fd(int sock, int fd) | 68 | mm_send_fd(int sock, int fd) |
45 | { | 69 | { |
@@ -145,13 +169,11 @@ mm_receive_fd(int sock) | |||
145 | error("%s: no message header", __func__); | 169 | error("%s: no message header", __func__); |
146 | return -1; | 170 | return -1; |
147 | } | 171 | } |
148 | #ifndef BROKEN_CMSG_TYPE | 172 | if (!cmsg_type_is_broken() && cmsg->cmsg_type != SCM_RIGHTS) { |
149 | if (cmsg->cmsg_type != SCM_RIGHTS) { | ||
150 | error("%s: expected type %d got %d", __func__, | 173 | error("%s: expected type %d got %d", __func__, |
151 | SCM_RIGHTS, cmsg->cmsg_type); | 174 | SCM_RIGHTS, cmsg->cmsg_type); |
152 | return -1; | 175 | return -1; |
153 | } | 176 | } |
154 | #endif | ||
155 | fd = (*(int *)CMSG_DATA(cmsg)); | 177 | fd = (*(int *)CMSG_DATA(cmsg)); |
156 | #endif | 178 | #endif |
157 | return fd; | 179 | return fd; |