2525
2626#include <sys/socket.h>
2727#include <netinet/in.h>
28+ #include <netinet/tcp.h>
2829
2930#if defined(HAVE_STDINT_H )
3031# include <stdint.h>
@@ -560,8 +561,12 @@ intercept_read(int fd, struct intercept_closure *closure)
560561 case false:
561562 goto done ;
562563 default :
563- if (errno == EINTR || errno == EAGAIN )
564+ if (errno == EINTR || errno == EAGAIN ) {
564565 debug_return_bool (true);
566+ sudo_debug_printf (
567+ SUDO_DEBUG_WARN |SUDO_DEBUG_ERRNO |SUDO_DEBUG_LINENO ,
568+ "reading intercept token" );
569+ }
565570 sudo_warn ("recv" );
566571 goto done ;
567572 }
@@ -574,8 +579,12 @@ intercept_read(int fd, struct intercept_closure *closure)
574579 nread = recv (fd , & req_len , sizeof (req_len ), 0 );
575580 if (nread != sizeof (req_len )) {
576581 if (nread == -1 ) {
577- if (errno == EINTR || errno == EAGAIN )
582+ if (errno == EINTR || errno == EAGAIN ) {
583+ sudo_debug_printf (
584+ SUDO_DEBUG_WARN |SUDO_DEBUG_ERRNO |SUDO_DEBUG_LINENO ,
585+ "reading intercept message size" );
578586 debug_return_bool (true);
587+ }
579588 sudo_warn ("recv" );
580589 }
581590 goto done ;
@@ -605,8 +614,12 @@ intercept_read(int fd, struct intercept_closure *closure)
605614 /* EOF, other side must have exited. */
606615 goto done ;
607616 case -1 :
608- if (errno == EINTR || errno == EAGAIN )
617+ if (errno == EINTR || errno == EAGAIN ) {
618+ sudo_debug_printf (
619+ SUDO_DEBUG_WARN |SUDO_DEBUG_ERRNO |SUDO_DEBUG_LINENO ,
620+ "reading intercept message" );
609621 debug_return_bool (true);
622+ }
610623 sudo_warn ("recv" );
611624 goto done ;
612625 default :
@@ -835,8 +848,12 @@ intercept_write(int fd, struct intercept_closure *closure)
835848 nwritten = send (fd , closure -> buf + closure -> off ,
836849 closure -> len - closure -> off , 0 );
837850 if (nwritten == -1 ) {
838- if (errno == EINTR || errno == EAGAIN )
851+ if (errno == EINTR || errno == EAGAIN ) {
852+ sudo_debug_printf (
853+ SUDO_DEBUG_WARN |SUDO_DEBUG_ERRNO |SUDO_DEBUG_LINENO ,
854+ "writing intercept message" );
839855 debug_return_bool (true);
856+ }
840857 sudo_warn ("send" );
841858 goto done ;
842859 }
@@ -930,7 +947,7 @@ intercept_accept_cb(int fd, int what, void *v)
930947 struct sudo_event_base * evbase = sudo_ev_get_base (& closure -> ev );
931948 struct sockaddr_in sin ;
932949 socklen_t sin_len = sizeof (sin );
933- int client_sock , flags ;
950+ int client_sock , flags , on = 1 ;
934951 debug_decl (intercept_accept_cb , SUDO_DEBUG_EXEC );
935952
936953 if (closure -> state != RECV_CONNECTION ) {
@@ -951,6 +968,9 @@ intercept_accept_cb(int fd, int what, void *v)
951968 if (flags != -1 )
952969 (void )fcntl (client_sock , F_SETFL , flags | O_NONBLOCK );
953970
971+ /* Send data immediately, we need low latency IPC. */
972+ (void )setsockopt (client_sock , IPPROTO_TCP , TCP_NODELAY , & on , sizeof (on ));
973+
954974 /*
955975 * Create a new intercept closure and register an event for client_sock.
956976 */
0 commit comments