Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MSG_NOSIGNAL if SOCK_NOSIGPIPE not available #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/libknc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2248,8 +2248,20 @@ fdwritev(void *cookie, const struct iovec *iov, int iovcnt)
{
int fd = ((struct fd_cookie *)cookie)->wfd;

#ifdef O_NOSIGPIPE
return writev(fd, iov, iovcnt);
#if defined(O_NOSIGPIPE) || defined(MSG_NOSIGNAL)
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
struct msghdr msg = { 0 };

msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = (void *)(uintptr_t)iov;
msg.msg_iovlen = iovcnt;
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
return sendmsg(fd, &msg, MSG_NOSIGNAL);
#else
struct timespec ts_zero = {0, 0};
sigset_t blocked;
Expand All @@ -2264,6 +2276,10 @@ fdwritev(void *cookie, const struct iovec *iov, int iovcnt)
* outside our control. Basically, check to see if there's
* one pending, if not block SIGPIPE, do the writev(2),
* consume any generated SIGPIPE, and restore the old sigmask.
*
* pthread_sigmask() is thread-safe, but sigismember() and
* sigtimedwait() are not. We might end up consuming a SIGPIPE
* we shouldn't consume.
*/

sigemptyset(&blocked);
Expand Down