@@ -316,7 +316,7 @@ linux_to_darwin_msg_flags(l_int flags)
316316 }
317317
318318 if (flags ) {
319- warnk ("unsupported msg_flags: 0x%x" , flags );
319+ warnk ("unsupported msg_flags: 0x%x\n " , flags );
320320 return - LINUX_EOPNOTSUPP ;
321321 }
322322
@@ -378,18 +378,34 @@ do_sendmsg(int sockfd, const struct l_msghdr *msg, int flags)
378378 if (copy_from_user (hdr .msg_iov [i ].iov_base , liov [i ].iov_base , hdr .msg_iov [i ].iov_len ))
379379 return - LINUX_EFAULT ;
380380 }
381- hdr .msg_flags = linux_to_darwin_msg_flags (msg -> msg_flags );
382- if (hdr .msg_flags < 0 ) {
383- warnk ("do_sendmsg: unsupported flags\n" );
384- return hdr .msg_flags ;
385- }
381+
386382 if (LINUX_CMSG_FIRSTHDR (msg ) != 0 ) {
387383 warnk ("we do not support ancillary data yet\n" );
388384 return - LINUX_EINVAL ;
389385 }
390386 hdr .msg_control = NULL ;
391387 hdr .msg_controllen = 0 ;
392- return syswrap (sendmsg (sockfd , & hdr , flags ));
388+
389+ /*
390+ On Mac OS X MSG_NOSIGNAL is not supported, so we need to set SO_NOSIGPIPE
391+ option on the socket.
392+ See https://lists.apple.com/archives/macnetworkprog/2002/Dec/msg00091.html.
393+ */
394+ int msg_flags = linux_to_darwin_msg_flags (flags & ~LINUX_MSG_NOSIGNAL );
395+ if (msg_flags < 0 ) {
396+ warnk ("do_sendmsg: unsupported flags\n" );
397+ return hdr .msg_flags ;
398+ }
399+ if (flags & LINUX_MSG_NOSIGNAL ) {
400+ int val = 1 ;
401+ int r = syswrap (setsockopt (sockfd , SOL_SOCKET , SO_NOSIGPIPE ,
402+ (void * )& val , sizeof (val )));
403+ if (r < 0 ) {
404+ panic ("Noah cannot set SO_NOSIGPIPE option." );
405+ }
406+ }
407+
408+ return syswrap (sendmsg (sockfd , & hdr , msg_flags ));
393409}
394410
395411DEFINE_SYSCALL (sendmsg , int , sockfd , gaddr_t , msg_ptr , int , flags )
0 commit comments