From dc4413349eb6027897d00ee1850e9e12e27437e6 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sun, 28 Jul 2002 05:30:39 +0000 Subject: [PATCH] Fix up restart code for EINTR --- libraries/libldap/options.c | 6 ++---- libraries/libldap/os-ip.c | 20 +++++++++++--------- libraries/libldap/os-local.c | 12 +++++++----- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index 7e6de7f206..45ceae125f 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -158,16 +158,14 @@ ldap_get_option( case LDAP_OPT_TIMEOUT: /* the caller has to free outvalue ! */ - if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_api) != 0 ) - { + if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_api) != 0 ) { return LDAP_OPT_ERROR; } return LDAP_OPT_SUCCESS; case LDAP_OPT_NETWORK_TIMEOUT: /* the caller has to free outvalue ! */ - if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_net ) != 0 ) - { + if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_net ) != 0 ) { return LDAP_OPT_ERROR; } return LDAP_OPT_SUCCESS; diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index d8a6039978..d549c7f324 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -201,6 +201,7 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr *sin, socklen_t addrlen, int async) { + int rc; struct timeval tv, *opt_tv=NULL; fd_set wfds, *z=NULL; #ifdef HAVE_WINSOCK @@ -230,8 +231,7 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, if ( ldap_pvt_ndelay_on(ld, s) == -1 ) return ( -1 ); - if ( connect(s, sin, addrlen) != AC_SOCKET_ERROR ) - { + if ( connect(s, sin, addrlen) != AC_SOCKET_ERROR ) { if ( ldap_pvt_ndelay_off(ld, s) == -1 ) return ( -1 ); return ( 0 ); @@ -257,16 +257,18 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, FD_SET(s, &efds ); #endif - if ( select(ldap_int_tblsize, z, &wfds, + do { + rc = select(ldap_int_tblsize, z, &wfds, #ifdef HAVE_WINSOCK - &efds, + &efds, #else - z, + z, #endif - opt_tv ? &tv : NULL) == AC_SOCKET_ERROR ) - { - return ( -1 ); - } + opt_tv ? &tv : NULL); + } while( rc == AC_SOCKET_ERROR && errno == EINTR && + LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART )); + + if( rc == AC_SOCKET_ERROR ) return rc; #ifdef HAVE_WINSOCK /* This means the connection failed */ diff --git a/libraries/libldap/os-local.c b/libraries/libldap/os-local.c index 8b3da9f228..b752a382fe 100644 --- a/libraries/libldap/os-local.c +++ b/libraries/libldap/os-local.c @@ -134,6 +134,7 @@ ldap_pvt_is_socket_ready(LDAP *ld, int s) static int ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async) { + int rc; struct timeval tv, *opt_tv=NULL; fd_set wfds, *z=NULL; @@ -168,11 +169,12 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async) FD_ZERO(&wfds); FD_SET(s, &wfds ); - if ( select(ldap_int_tblsize, z, &wfds, z, opt_tv ? &tv : NULL) - == AC_SOCKET_ERROR ) - { - return ( -1 ); - } + do { + rc = select(ldap_int_tblsize, z, &wfds, z, opt_tv ? &tv : NULL); + } while( rc == AC_SOCKET_ERROR && errno == EINTR && + LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART )); + + if( rc == AC_SOCKET_ERROR ) return rc; if ( FD_ISSET(s, &wfds) ) { if ( ldap_pvt_is_socket_ready(ld, s) == -1 ) -- 2.39.5