Skip to content
Snippets Groups Projects
Commit 0300bdac authored by tewk's avatar tewk
Browse files

Fixed SIGPIPE error by ignoring the signal and returning an error_code

parent 0a20952e
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define SLURM_PROTOCOL_VERSION_ERROR -100 #define SLURM_PROTOCOL_VERSION_ERROR -100
#define SLURM_SOCKET_ERROR -1 #define SLURM_SOCKET_ERROR -1
#define SLURM_PROTOCOL_SUCCESS 0 #define SLURM_PROTOCOL_SUCCESS 0
#define SLURM_PROTOCOL_ERROR -1
#define SLURM_PROTOCOL_FAILURE -1 #define SLURM_PROTOCOL_FAILURE -1
/* general return codes */ /* general return codes */
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <signal.h>
#if HAVE_SYS_SOCKET_H #if HAVE_SYS_SOCKET_H
# include <sys/socket.h> # include <sys/socket.h>
...@@ -52,24 +53,35 @@ ssize_t _slurm_msg_recvfrom ( slurm_fd open_fd, char *buffer , size_t size , uin ...@@ -52,24 +53,35 @@ ssize_t _slurm_msg_recvfrom ( slurm_fd open_fd, char *buffer , size_t size , uin
char size_buffer_temp [8] ; char size_buffer_temp [8] ;
char * size_buffer = size_buffer_temp ; char * size_buffer = size_buffer_temp ;
char * moving_buffer = buffer ; char * moving_buffer = NULL ;
unsigned int size_buffer_len = 8 ; unsigned int size_buffer_len = 8 ;
unsigned int transmit_size ; unsigned int transmit_size ;
unsigned int total_len ; unsigned int total_len ;
if ( ( recv_len = _slurm_recv ( open_fd , size_buffer_temp , sizeof ( uint32_t ) , SLURM_PROTOCOL_NO_SEND_RECV_FLAGS ) ) != sizeof ( uint32_t ) ) moving_buffer = size_buffer ;
{ total_len = 0 ;
info ( "Error receiving length of datagram. Total bytes received %i", recv_len ) ; while ( total_len < sizeof ( uint32_t ) )
return 0 ; {
if ( ( recv_len = _slurm_recv ( open_fd , moving_buffer , sizeof ( uint32_t ) , SLURM_PROTOCOL_NO_SEND_RECV_FLAGS ) ) == SLURM_SOCKET_ERROR )
{
info ( "Error receiving length of datagram. errno %i", errno ) ;
return recv_len ;
}
if ( recv_len >= 0 )
{
total_len += recv_len ;
moving_buffer += recv_len ;
}
} }
unpack32 ( & transmit_size , ( void ** ) & size_buffer , & size_buffer_len ) ; unpack32 ( & transmit_size , ( void ** ) & size_buffer , & size_buffer_len ) ;
moving_buffer = buffer ;
total_len = 0 ; total_len = 0 ;
while ( total_len < transmit_size ) while ( total_len < transmit_size )
{ {
if ( ( recv_len = _slurm_recv ( open_fd , moving_buffer , transmit_size , SLURM_PROTOCOL_NO_SEND_RECV_FLAGS ) ) == SLURM_SOCKET_ERROR ) if ( ( recv_len = _slurm_recv ( open_fd , moving_buffer , transmit_size , SLURM_PROTOCOL_NO_SEND_RECV_FLAGS ) ) == SLURM_SOCKET_ERROR )
{ {
info ( "Error receiving length of datagram. errno %i", errno ) ; info ( "Error receiving datagram. errno %i", errno ) ;
return recv_len ; return recv_len ;
} }
if ( recv_len >= 0 ) if ( recv_len >= 0 )
...@@ -89,18 +101,23 @@ ssize_t _slurm_msg_sendto ( slurm_fd open_fd, char *buffer , size_t size , uint3 ...@@ -89,18 +101,23 @@ ssize_t _slurm_msg_sendto ( slurm_fd open_fd, char *buffer , size_t size , uint3
char size_buffer_temp [8] ; char size_buffer_temp [8] ;
char * size_buffer = size_buffer_temp ; char * size_buffer = size_buffer_temp ;
unsigned int size_buffer_len = 8 ; unsigned int size_buffer_len = 8 ;
/* ignore SIGPIPE so that send can return a error code if the other side closes the socket */
signal(SIGPIPE, SIG_IGN);
pack32 ( size , ( void ** ) & size_buffer , & size_buffer_len ) ; pack32 ( size , ( void ** ) & size_buffer , & size_buffer_len ) ;
if ( ( send_len = _slurm_send ( open_fd , size_buffer_temp , sizeof ( uint32_t ) , SLURM_PROTOCOL_NO_SEND_RECV_FLAGS ) ) != sizeof ( uint32_t ) ) if ( ( send_len = _slurm_send ( open_fd , size_buffer_temp , sizeof ( uint32_t ) , SLURM_PROTOCOL_NO_SEND_RECV_FLAGS ) ) != sizeof ( uint32_t ) )
{ {
info ( "Error sending length of datagram" ) ; info ( "Error sending length of datagram" ) ;
return SLURM_PROTOCOL_ERROR ;
} }
send_len = _slurm_send ( open_fd , buffer , size , SLURM_PROTOCOL_NO_SEND_RECV_FLAGS ) ; send_len = _slurm_send ( open_fd , buffer , size , SLURM_PROTOCOL_NO_SEND_RECV_FLAGS ) ;
if ( send_len != size ) if ( send_len != size )
{ {
info ( "_slurm_msg_sendto only transmitted %i of %i bytes", send_len , size ) ; info ( "_slurm_msg_sendto only transmitted %i of %i bytes", send_len , size ) ;
return SLURM_PROTOCOL_ERROR ;
} }
return send_len ; return send_len ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment