Skip to content

Commit

Permalink
add support for SO_NOSIGPIPE
Browse files Browse the repository at this point in the history
The code for creating network sockets previously used `MSG_NOSIGNAL`
unconditionally, which may not exist on non-Linux systems such as
MacOS or some BSD variants. This change adds configuration checks for
`MSG_NOSIGNAL` and it's BSD name, `SO_NOSIGPIPE`, allowing systems with
either socket option to work as intended.
  • Loading branch information
vasiliyk authored Oct 25, 2024
1 parent 71dc567 commit 5f68b8f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ endif()


# configuration-specific source files

# we don't check for win32 as on win32 socket operations are handled directly through return values
# Check if SO_NOSIGPIPE exists
check_symbol_exists(SO_NOSIGPIPE "sys/socket.h" HAVE_SO_NOSIGPIPE)

# Check if MSG_NOSIGNAL exists
check_symbol_exists(MSG_NOSIGNAL "sys/socket.h" HAVE_MSG_NOSIGNAL)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(SUPPORT_ABSTRACT_SOCKET_NAMES TRUE)
list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/abstract_socket_names_supported.c)
Expand Down
3 changes: 3 additions & 0 deletions include/private/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#cmakedefine HAVE_VSNPRINTF_S 1
#cmakedefine HAVE_WCSRTOMBS_S 1
#cmakedefine HAVE_WCSTOMBS_S 1
#cmakedefine HAVE_SO_NOSIGPIPE 1
#cmakedefine HAVE_MSG_NOSIGNAL 1


/* function support checks */
#cmakedefine SUPPORT_ABSTRACT_SOCKET_NAMES 1
Expand Down
7 changes: 7 additions & 0 deletions include/private/config/have_sys_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
# define __STUMPLESS_PRIVATE_CONFIG_HAVE_SYS_SOCKET_H

# include <stddef.h>
# include <sys/socket.h>
# include "private/target/network.h"

# ifdef HAVE_SO_NOSIGPIPE
# define config_disallow_signal_during_sending_flag SO_NOSIGPIPE
# elif defined(HAVE_MSG_NOSIGNAL)
# define config_disallow_signal_during_sending_flag MSG_NOSIGNAL
# endif

void
sys_socket_close_network_target( const struct network_target *target );

Expand Down
4 changes: 2 additions & 2 deletions src/config/have_sys_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ sys_socket_sendto_tcp_target( struct network_target *target,
send_result = send( target->handle,
msg,
msg_size - sent_bytes,
MSG_NOSIGNAL );
config_disallow_signal_during_sending_flag );

if( unlikely( send_result == -1 ) ){
raise_socket_send_failure( L10N_SEND_SYS_SOCKET_FAILED_ERROR_MESSAGE,
Expand All @@ -231,7 +231,7 @@ sys_socket_sendto_udp_target( const struct network_target *target,
send_result = send( target->handle,
msg,
msg_size,
MSG_NOSIGNAL );
config_disallow_signal_during_sending_flag );

if( unlikely( send_result == -1 ) ){
unlock_network_target( target );
Expand Down

0 comments on commit 5f68b8f

Please sign in to comment.