]> git.kaiwu.me - nginx.git/commitdiff
use CMSG_LEN(), this fixes an alert "sendmsg() failed (9: Bad file descriptor)"
authorIgor Sysoev <igor@sysoev.ru>
Tue, 19 Feb 2008 16:34:55 +0000 (16:34 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Tue, 19 Feb 2008 16:34:55 +0000 (16:34 +0000)
on some 64-bit platforms

src/os/unix/ngx_channel.c
src/os/unix/ngx_freebsd_config.h
src/os/unix/ngx_posix_config.h

index 62ea7cc30077be026858029ec2a6b3331356a616..f0f337d0684154e281d58e2af0fb155542fa2cb6 100644 (file)
@@ -33,7 +33,7 @@ ngx_write_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
         msg.msg_control = (caddr_t) &cmsg;
         msg.msg_controllen = sizeof(cmsg);
 
-        cmsg.cm.cmsg_len = sizeof(cmsg);
+        cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int));
         cmsg.cm.cmsg_level = SOL_SOCKET;
         cmsg.cm.cmsg_type = SCM_RIGHTS;
         *(int *) CMSG_DATA(&cmsg.cm) = ch->fd;
@@ -138,7 +138,7 @@ ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, ngx_log_t *log)
 
     if (ch->command == NGX_CMD_OPEN_CHANNEL) {
 
-        if (cmsg.cm.cmsg_len < (socklen_t) sizeof(cmsg)) {
+        if (cmsg.cm.cmsg_len < (socklen_t) CMSG_LEN(sizeof(int))) {
             ngx_log_error(NGX_LOG_ALERT, log, 0,
                           "recvmsg() returned too small ancillary data");
             return NGX_ERROR;
index 818e230ba01d0e4993f572b71ea44bbb2d245727..24dcdcb468ea076f9cca89b47f1b2f6338711e81 100644 (file)
 
 #if __FreeBSD_version < 400017
 
-/* FreeBSD 3.x has no CMSG_SPACE() at all and has the broken CMSG_DATA() */
+/*
+ * FreeBSD 3.x has no CMSG_SPACE() and CMSG_LEN() and has the broken CMSG_DATA()
+ */
 
 #undef  CMSG_SPACE
 #define CMSG_SPACE(l)       (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
 
+#undef  CMSG_LEN
+#define CMSG_LEN(l)         (ALIGN(sizeof(struct cmsghdr)) + (l))
+
 #undef  CMSG_DATA
 #define CMSG_DATA(cmsg)     ((u_char *)(cmsg) + ALIGN(sizeof(struct cmsghdr)))
 
index 49c3c4d6c0f5e768a84d205292bfe0074bcbb862..37176e0d25c76fc417082f1d53e3ec792bdb34f3 100644 (file)
 
 #include <sys/param.h>          /* ALIGN() */
 
-/* FreeBSD 3.x has no CMSG_SPACE() at all and has the broken CMSG_DATA() */
+/* 
+ * FreeBSD 3.x has no CMSG_SPACE() and CMSG_LEN() and has the broken CMSG_DATA()
+ */
 
 #undef  CMSG_SPACE
 #define CMSG_SPACE(l)       (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
 
+#undef  CMSG_LEN
+#define CMSG_LEN(l)         (ALIGN(sizeof(struct cmsghdr)) + (l))
+
 #undef  CMSG_DATA
 #define CMSG_DATA(cmsg)     ((u_char *)(cmsg) + ALIGN(sizeof(struct cmsghdr)))