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 dd1a13984..f384c174c 100644
--- a/monitor_fdpass.c
+++ b/monitor_fdpass.c
@@ -27,10 +27,34 @@
27RCSID("$OpenBSD: monitor_fdpass.c,v 1.6 2004/08/13 02:51:48 djm Exp $"); 27RCSID("$OpenBSD: monitor_fdpass.c,v 1.6 2004/08/13 02:51:48 djm Exp $");
28 28
29#include <sys/uio.h> 29#include <sys/uio.h>
30#include <sys/utsname.h>
30 31
31#include "log.h" 32#include "log.h"
32#include "monitor_fdpass.h" 33#include "monitor_fdpass.h"
33 34
35static int
36cmsg_type_is_broken(void)
37{
38 static int broken_cmsg_type = -1;
39
40 if (broken_cmsg_type != -1)
41 return broken_cmsg_type;
42 else {
43 struct utsname uts;
44 /* If uname() fails, play safe and assume that cmsg_type
45 * isn't broken.
46 */
47 if (!uname(&uts) &&
48 strcmp(uts.sysname, "Linux") == 0 &&
49 strncmp(uts.release, "2.0.", 4) == 0)
50 broken_cmsg_type = 1;
51 else
52 broken_cmsg_type = 0;
53 }
54
55 return broken_cmsg_type;
56}
57
34void 58void
35mm_send_fd(int sock, int fd) 59mm_send_fd(int sock, int fd)
36{ 60{
@@ -115,11 +139,9 @@ mm_receive_fd(int sock)
115 cmsg = CMSG_FIRSTHDR(&msg); 139 cmsg = CMSG_FIRSTHDR(&msg);
116 if (cmsg == NULL) 140 if (cmsg == NULL)
117 fatal("%s: no message header", __func__); 141 fatal("%s: no message header", __func__);
118#ifndef BROKEN_CMSG_TYPE 142 if (!cmsg_type_is_broken() && cmsg->cmsg_type != SCM_RIGHTS)
119 if (cmsg->cmsg_type != SCM_RIGHTS)
120 fatal("%s: expected type %d got %d", __func__, 143 fatal("%s: expected type %d got %d", __func__,
121 SCM_RIGHTS, cmsg->cmsg_type); 144 SCM_RIGHTS, cmsg->cmsg_type);
122#endif
123 fd = (*(int *)CMSG_DATA(cmsg)); 145 fd = (*(int *)CMSG_DATA(cmsg));
124#endif 146#endif
125 return fd; 147 return fd;