Mercurial > hg > nginx
comparison src/os/unix/ngx_channel.c @ 1901:d880fa02fb65
use CMSG_LEN(), this fixes an alert "sendmsg() failed (9: Bad file descriptor)"
on some 64-bit platforms
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 19 Feb 2008 16:34:55 +0000 |
parents | 4d9ea73a627a |
children | 2c5e269d0608 |
comparison
equal
deleted
inserted
replaced
1900:55a9d867e3c8 | 1901:d880fa02fb65 |
---|---|
31 | 31 |
32 } else { | 32 } else { |
33 msg.msg_control = (caddr_t) &cmsg; | 33 msg.msg_control = (caddr_t) &cmsg; |
34 msg.msg_controllen = sizeof(cmsg); | 34 msg.msg_controllen = sizeof(cmsg); |
35 | 35 |
36 cmsg.cm.cmsg_len = sizeof(cmsg); | 36 cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int)); |
37 cmsg.cm.cmsg_level = SOL_SOCKET; | 37 cmsg.cm.cmsg_level = SOL_SOCKET; |
38 cmsg.cm.cmsg_type = SCM_RIGHTS; | 38 cmsg.cm.cmsg_type = SCM_RIGHTS; |
39 *(int *) CMSG_DATA(&cmsg.cm) = ch->fd; | 39 *(int *) CMSG_DATA(&cmsg.cm) = ch->fd; |
40 } | 40 } |
41 | 41 |
136 | 136 |
137 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) | 137 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) |
138 | 138 |
139 if (ch->command == NGX_CMD_OPEN_CHANNEL) { | 139 if (ch->command == NGX_CMD_OPEN_CHANNEL) { |
140 | 140 |
141 if (cmsg.cm.cmsg_len < (socklen_t) sizeof(cmsg)) { | 141 if (cmsg.cm.cmsg_len < (socklen_t) CMSG_LEN(sizeof(int))) { |
142 ngx_log_error(NGX_LOG_ALERT, log, 0, | 142 ngx_log_error(NGX_LOG_ALERT, log, 0, |
143 "recvmsg() returned too small ancillary data"); | 143 "recvmsg() returned too small ancillary data"); |
144 return NGX_ERROR; | 144 return NGX_ERROR; |
145 } | 145 } |
146 | 146 |