ITS#5422 Save errno before passing it to Debug()

This commit is contained in:
Ondřej Kuzník 2020-09-24 15:51:41 +01:00 committed by Quanah Gibson-Mount
parent 81e43a6335
commit 3f5293e145
9 changed files with 33 additions and 18 deletions

View File

@ -201,10 +201,11 @@ ldap_int_prepare_socket(LDAP *ld, int s, int proto )
#undef TRACE
#define TRACE do { \
char ebuf[128]; \
int saved_errno = errno; \
Debug3(LDAP_DEBUG_TRACE, "ldap_is_socket_ready: error on socket %d: errno: %d (%s)\n", \
s, \
errno, \
sock_errstr(errno, ebuf, sizeof(ebuf)) ); \
saved_errno, \
sock_errstr(saved_errno, ebuf, sizeof(ebuf)) ); \
} while( 0 )
/*
@ -372,7 +373,7 @@ ldap_int_poll(
ldap_pvt_set_errno( so_errno );
Debug3(LDAP_DEBUG_TRACE,
"ldap_int_poll: error on socket %d: "
"errno: %d (%s)\n", s, errno, sock_errstr( errno, dummy, dummy ));
"errno: %d (%s)\n", s, so_errno, sock_errstr( so_errno, dummy, dummy ));
return -1;
}
#endif

View File

@ -95,10 +95,11 @@ ldap_pvt_close_socket(LDAP *ld, int s)
#undef TRACE
#define TRACE do { \
char ebuf[128]; \
int saved_errno = errno; \
Debug3(LDAP_DEBUG_TRACE, "ldap_is_socket_ready: error on socket %d: errno: %d (%s)\n", \
s, \
errno, \
AC_STRERROR_R(errno, ebuf, sizeof ebuf)); \
saved_errno, \
AC_STRERROR_R(saved_errno, ebuf, sizeof ebuf)); \
} while( 0 )
/*

View File

@ -104,10 +104,11 @@ mdb_db_open( BackendDB *be, ConfigReply *cr )
/* Check existence of dbenv_home. Any error means trouble */
rc = stat( mdb->mi_dbenv_home, &stat1 );
if( rc != 0 ) {
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,
LDAP_XSTRING(mdb_db_open) ": database \"%s\": "
"cannot access database directory \"%s\" (%d).\n",
be->be_suffix[0].bv_val, mdb->mi_dbenv_home, errno );
be->be_suffix[0].bv_val, mdb->mi_dbenv_home, saved_errno );
return -1;
}

View File

@ -59,10 +59,11 @@ read_and_send_results(
while ( !feof(fp) ) {
errno = 0;
if ( fgets( line, sizeof(line), fp ) == NULL ) {
int saved_errno = errno;
if ( errno == EINTR ) continue;
Debug( LDAP_DEBUG_ANY, "shell: fgets failed: %s (%d)\n",
AC_STRERROR_R(errno, ebuf, sizeof ebuf), errno );
AC_STRERROR_R(saved_errno, ebuf, sizeof ebuf), saved_errno );
break;
}

View File

@ -57,10 +57,11 @@ sock_read_and_send_results(
while ( !feof(fp) ) {
errno = 0;
if ( fgets( line, sizeof(line), fp ) == NULL ) {
int saved_errno = errno;
if ( errno == EINTR ) continue;
Debug( LDAP_DEBUG_ANY, "sock: fgets failed: %s (%d)\n",
AC_STRERROR_R(errno, ebuf, sizeof ebuf), errno );
AC_STRERROR_R(saved_errno, ebuf, sizeof ebuf), saved_errno );
break;
}

View File

@ -71,10 +71,11 @@ wt_db_open( BackendDB *be, ConfigReply *cr )
/* Check existence of home. Any error means trouble */
rc = stat( wi->wi_dbenv_home, &st );
if( rc ) {
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,
LDAP_XSTRING(wt_db_open) ": database \"%s\": "
"cannot access database directory \"%s\" (%d).\n",
be->be_suffix[0].bv_val, wi->wi_dbenv_home, errno );
be->be_suffix[0].bv_val, wi->wi_dbenv_home, saved_errno );
return -1;
}
@ -82,10 +83,11 @@ wt_db_open( BackendDB *be, ConfigReply *cr )
rc = wiredtiger_open(wi->wi_dbenv_home, NULL,
wi->wi_dbenv_config, &conn);
if( rc ) {
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,
LDAP_XSTRING(wt_db_open) ": database \"%s\": "
"cannot open database \"%s\" (%d).\n",
be->be_suffix[0].bv_val, wi->wi_dbenv_home, errno );
be->be_suffix[0].bv_val, wi->wi_dbenv_home, saved_errno );
return -1;
}
@ -178,10 +180,11 @@ wt_db_close( BackendDB *be, ConfigReply *cr )
rc = wi->wi_conn->close(wi->wi_conn, NULL);
if( rc ) {
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,
LDAP_XSTRING(wt_db_close)
": cannot close database (%d).\n",
errno );
saved_errno );
return -1;
}

View File

@ -4570,9 +4570,10 @@ read_config(const char *fname, const char *dir) {
struct stat st;
if ( stat( dir, &st ) < 0 ) {
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,
"invalid config directory %s, error %d\n",
dir, errno );
dir, saved_errno );
return 1;
}
cfdir = dir;

View File

@ -787,10 +787,11 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
init_config_argv( c );
if ( stat( fname, &s ) != 0 ) {
int saved_errno = errno;
ldap_syslog = 1;
Debug(LDAP_DEBUG_ANY,
"could not stat config file \"%s\": %s (%d)\n",
fname, strerror(errno), errno);
fname, strerror(saved_errno), saved_errno);
ch_free( c->argv );
ch_free( c );
return(1);
@ -808,10 +809,11 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
fp = fopen( fname, "r" );
if ( fp == NULL ) {
int saved_errno = errno;
ldap_syslog = 1;
Debug(LDAP_DEBUG_ANY,
"could not open config file \"%s\": %s (%d)\n",
fname, strerror(errno), errno);
fname, strerror(saved_errno), saved_errno);
ch_free( c->argv );
ch_free( c );
return(1);

View File

@ -242,7 +242,8 @@ static slap_daemon_st *slap_daemon;
} \
slap_daemon[t].sd_kq = kqueue(); \
if (slap_daemon[t].sd_kq < 0) { \
Debug(LDAP_DEBUG_ANY, "daemon: SLAP_SOCK_INIT: kqueue() failed, errno=%d, shutting down\n", errno); \
int saved_errno = errno; \
Debug(LDAP_DEBUG_ANY, "daemon: SLAP_SOCK_INIT: kqueue() failed, errno=%d, shutting down\n", saved_errno); \
slapd_shutdown = 2; \
} \
} while (0)
@ -466,9 +467,10 @@ static slap_daemon_st *slap_daemon;
if ( rc == 0 ) { \
slap_daemon[t].sd_nfds++; \
} else { \
int saved_errno = errno; \
Debug( LDAP_DEBUG_ANY, \
"daemon: epoll_ctl(ADD,fd=%d) failed, errno=%d, shutting down\n", \
s, errno ); \
s, saved_errno ); \
slapd_shutdown = 2; \
} \
} while (0)
@ -573,9 +575,10 @@ static slap_daemon_st *slap_daemon;
/* FIXME: use pwrite? */ \
rc = write( slap_daemon[t].sd_dpfd, (pfd), size ); \
if ( rc != size ) { \
int saved_errno = errno; \
Debug( LDAP_DEBUG_ANY, "daemon: " SLAP_EVENT_FNAME ": " \
"%s fd=%d failed errno=%d\n", \
(what), (s), errno ); \
(what), (s), saved_errno ); \
if ( (shdn) ) { \
slapd_shutdown = 2; \
} \
@ -691,9 +694,10 @@ static slap_daemon_st *slap_daemon;
slap_daemon[t].sd_l = (Listener **)&slap_daemon[t].sd_index[ dtblsize ]; \
slap_daemon[t].sd_dpfd = open( SLAP_EVENT_FNAME, O_RDWR ); \
if ( slap_daemon[t].sd_dpfd == -1 ) { \
int saved_errno = errno; \
Debug( LDAP_DEBUG_ANY, "daemon: " SLAP_EVENT_FNAME ": " \
"open(\"" SLAP_EVENT_FNAME "\") failed errno=%d\n", \
errno ); \
saved_errno ); \
SLAP_SOCK_DESTROY(t); \
return -1; \
} \