Klaus Demo nginx / 09248b7
use CMSG_LEN(), this fixes an alert "sendmsg() failed (9: Bad file descriptor)" on some 64-bit platforms Igor Sysoev 14 years ago
3 changed file(s) with 14 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
3232 msg.msg_control = (caddr_t) &cmsg;
3333 msg.msg_controllen = sizeof(cmsg);
3434
35 cmsg.cm.cmsg_len = sizeof(cmsg);
35 cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int));
3636 cmsg.cm.cmsg_level = SOL_SOCKET;
3737 cmsg.cm.cmsg_type = SCM_RIGHTS;
3838 *(int *) CMSG_DATA(&cmsg.cm) = ch->fd;
137137
138138 if (ch->command == NGX_CMD_OPEN_CHANNEL) {
139139
140 if (cmsg.cm.cmsg_len < (socklen_t) sizeof(cmsg)) {
140 if (cmsg.cm.cmsg_len < (socklen_t) CMSG_LEN(sizeof(int))) {
141141 ngx_log_error(NGX_LOG_ALERT, log, 0,
142142 "recvmsg() returned too small ancillary data");
143143 return NGX_ERROR;
4747
4848 #if __FreeBSD_version < 400017
4949
50 /* FreeBSD 3.x has no CMSG_SPACE() at all and has the broken CMSG_DATA() */
50 /*
51 * FreeBSD 3.x has no CMSG_SPACE() and CMSG_LEN() and has the broken CMSG_DATA()
52 */
5153
5254 #undef CMSG_SPACE
5355 #define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
56
57 #undef CMSG_LEN
58 #define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l))
5459
5560 #undef CMSG_DATA
5661 #define CMSG_DATA(cmsg) ((u_char *)(cmsg) + ALIGN(sizeof(struct cmsghdr)))
109109
110110 #include <sys/param.h> /* ALIGN() */
111111
112 /* FreeBSD 3.x has no CMSG_SPACE() at all and has the broken CMSG_DATA() */
112 /*
113 * FreeBSD 3.x has no CMSG_SPACE() and CMSG_LEN() and has the broken CMSG_DATA()
114 */
113115
114116 #undef CMSG_SPACE
115117 #define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
118
119 #undef CMSG_LEN
120 #define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l))
116121
117122 #undef CMSG_DATA
118123 #define CMSG_DATA(cmsg) ((u_char *)(cmsg) + ALIGN(sizeof(struct cmsghdr)))