mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
Kernel: Add support for MSG_NOSIGNAL and properly send SIGPIPE
Previously we didn't send the SIGPIPE signal to processes when sendto()/sendmsg()/etc. returned EPIPE. And now we do. This also adds support for MSG_NOSIGNAL to suppress the signal.
This commit is contained in:
parent
e5e7ea90b1
commit
ce4b66e908
4 changed files with 16 additions and 5 deletions
|
@ -194,8 +194,11 @@ ErrorOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghdr*
|
|||
return ENOTSOCK;
|
||||
|
||||
auto& socket = *description->socket();
|
||||
if (socket.is_shut_down_for_writing())
|
||||
if (socket.is_shut_down_for_writing()) {
|
||||
if ((flags & MSG_NOSIGNAL) == 0)
|
||||
Thread::current()->send_signal(SIGPIPE, &Process::current());
|
||||
return EPIPE;
|
||||
}
|
||||
auto data_buffer = TRY(UserOrKernelBuffer::for_user_buffer((u8*)iovs[0].iov_base, iovs[0].iov_len));
|
||||
|
||||
while (true) {
|
||||
|
@ -211,7 +214,14 @@ ErrorOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghdr*
|
|||
// TODO: handle exceptions in unblock_flags
|
||||
}
|
||||
|
||||
auto bytes_sent = TRY(socket.sendto(*description, data_buffer, iovs[0].iov_len, flags, user_addr, addr_length));
|
||||
auto bytes_sent_or_error = socket.sendto(*description, data_buffer, iovs[0].iov_len, flags, user_addr, addr_length);
|
||||
if (bytes_sent_or_error.is_error()) {
|
||||
if ((flags & MSG_NOSIGNAL) == 0 && bytes_sent_or_error.error().code() == EPIPE)
|
||||
Thread::current()->send_signal(SIGPIPE, &Process::current());
|
||||
return bytes_sent_or_error.release_error();
|
||||
}
|
||||
|
||||
auto bytes_sent = bytes_sent_or_error.release_value();
|
||||
if (bytes_sent > 0)
|
||||
return bytes_sent;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue