in sb_debug_read/write save errno before logging a failure.

ber_log_printf can cause errors of its own and obscure the original.
This commit is contained in:
Howard Chu 2001-12-31 12:50:09 +00:00
parent e823c74811
commit d8e70bd5f4

View File

@ -822,10 +822,11 @@ sb_debug_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS) if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS)
{ {
if ( ret < 0 ) { if ( ret < 0 ) {
int err = errno;
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
"%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt, "%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt,
(long)len, STRERROR( errno ) ); (long)len, STRERROR( errno ) );
errno = err;
} else { } else {
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
"%sread: want=%ld, got=%ld\n", (char *)sbiod->sbiod_pvt, "%sread: want=%ld, got=%ld\n", (char *)sbiod->sbiod_pvt,
@ -846,11 +847,12 @@ sb_debug_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS) if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS)
{ {
if ( ret < 0 ) { if ( ret < 0 ) {
int err = errno;
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
"%swrite: want=%ld error=%s\n", "%swrite: want=%ld error=%s\n",
(char *)sbiod->sbiod_pvt, (long)len, (char *)sbiod->sbiod_pvt, (long)len,
STRERROR( errno ) ); STRERROR( errno ) );
errno = err;
} else { } else {
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
"%swrite: want=%ld, written=%ld\n", "%swrite: want=%ld, written=%ld\n",