ITS#9348 replace all uses of STRERROR with AC_STRERROR_R

Avoid using sys_errlist unless there's no other choice
This commit is contained in:
Howard Chu 2020-09-16 15:33:13 +01:00 committed by Quanah Gibson-Mount
parent bf2b88f0fc
commit c3131eb5a3
7 changed files with 44 additions and 51 deletions

View File

@ -29,23 +29,4 @@
LDAP_LIBC_V(char) *sys_errlist[];
#endif
#undef _AC_ERRNO_UNKNOWN
#define _AC_ERRNO_UNKNOWN "unknown error"
#ifdef HAVE_SYS_ERRLIST
/* this is thread safe */
# define STRERROR(e) ( (e) > -1 && (e) < sys_nerr \
? sys_errlist[(e)] : _AC_ERRNO_UNKNOWN )
#elif defined( HAVE_STRERROR )
/* this may not be thread safe */
/* and, yes, some implementations of strerror may return NULL */
# define STRERROR(e) ( strerror(e) \
? strerror(e) : _AC_ERRNO_UNKNOWN )
#else
/* this is thread safe */
# define STRERROR(e) ( _AC_ERRNO_UNKNOWN )
#endif
#endif /* _AC_ERRNO_H */

View File

@ -82,7 +82,7 @@
#undef sock_errno
#undef sock_errstr
#define sock_errno() errno
#define sock_errstr(e) STRERROR(e)
#define sock_errstr(e, b, l) AC_STRERROR_R(e, b, l)
#define sock_errset(e) ((void) (errno = (e)))
#ifdef HAVE_WINSOCK
@ -106,7 +106,7 @@
#undef sock_errstr
#undef sock_errset
#define sock_errno() WSAGetLastError()
#define sock_errstr(e) ber_pvt_wsa_err2string(e)
#define sock_errstr(e, b, l) ber_pvt_wsa_err2string(e)
#define sock_errset(e) WSASetLastError(e)
LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));

View File

@ -200,10 +200,11 @@ ldap_int_prepare_socket(LDAP *ld, int s, int proto )
#undef TRACE
#define TRACE do { \
char ebuf[128]; \
Debug3(LDAP_DEBUG_TRACE, "ldap_is_socket_ready: error on socket %d: errno: %d (%s)\n", \
s, \
errno, \
sock_errstr(errno) ); \
sock_errstr(errno, ebuf, sizeof(ebuf)) ); \
} while( 0 )
/*
@ -371,7 +372,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 ));
"errno: %d (%s)\n", s, errno, sock_errstr( errno, dummy, dummy ));
return -1;
}
#endif

View File

@ -480,12 +480,13 @@ ldif_read_file( const char *path, char **datap )
Debug( LDAP_DEBUG_TRACE, "ldif_read_file: %s: \"%s\"\n", msg, path );
#endif /* LDAP_DEBUG */
} else {
char ebuf[128];
if ( res < 0 && errno == ENOENT ) {
Debug( LDAP_DEBUG_TRACE, "ldif_read_file: "
"no entry file \"%s\"\n", path );
rc = LDAP_NO_SUCH_OBJECT;
} else {
msg = res < 0 ? STRERROR( errno ) : "bad stat() size";
msg = res < 0 ? AC_STRERROR_R( errno, ebuf, sizeof(ebuf) ) : "bad stat() size";
Debug( LDAP_DEBUG_ANY, "ldif_read_file: %s for \"%s\"\n",
msg, path );
rc = LDAP_OTHER;
@ -543,6 +544,7 @@ ldif_write_entry(
int rc = LDAP_OTHER, res, save_errno = 0;
int fd, entry_length;
char *entry_as_string, *tmpfname;
char ebuf[128];
if ( op->o_abandon )
return SLAPD_ABANDON;
@ -551,7 +553,7 @@ ldif_write_entry(
save_errno = errno;
Debug( LDAP_DEBUG_ANY, "ldif_write_entry: %s \"%s\": %s\n",
"cannot create parent directory",
parentdir, STRERROR( save_errno ) );
parentdir, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
*text = "internal error (cannot create parent directory)";
return rc;
}
@ -561,7 +563,7 @@ ldif_write_entry(
if ( fd < 0 ) {
save_errno = errno;
Debug( LDAP_DEBUG_ANY, "ldif_write_entry: %s for \"%s\": %s\n",
"cannot create file", e->e_dn, STRERROR( save_errno ) );
"cannot create file", e->e_dn, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
*text = "internal error (cannot create file)";
} else {
@ -602,12 +604,12 @@ ldif_write_entry(
save_errno = errno;
Debug( LDAP_DEBUG_ANY, "ldif_write_entry: "
"could not put entry file for \"%s\" in place: %s\n",
e->e_name.bv_val, STRERROR( save_errno ) );
e->e_name.bv_val, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
*text = "internal error (could not put entry file in place)";
}
} else if ( res == -1 ) {
Debug( LDAP_DEBUG_ANY, "ldif_write_entry: %s \"%s\": %s\n",
"write error to", tmpfname, STRERROR( save_errno ) );
"write error to", tmpfname, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
*text = "internal error (write error to entry file)";
}
@ -807,6 +809,7 @@ ldif_readdir(
{
int rc = LDAP_SUCCESS;
DIR *dir_of_path;
char ebuf[128];
*listp = NULL;
*fname_maxlenp = 0;
@ -821,7 +824,7 @@ ldif_readdir(
if ( is_rootDSE || save_errno != ENOENT ) {
Debug( LDAP_DEBUG_ANY,
"=> ldif_search_entry: failed to opendir \"%s\": %s\n",
path->bv_val, STRERROR( save_errno ) );
path->bv_val, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
rc = LDAP_OTHER;
if ( rs != NULL )
rs->sr_text =
@ -894,7 +897,7 @@ ldif_readdir(
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "ldif_search_entry: %s \"%s\": %s\n",
"error reading directory", path->bv_val,
STRERROR( save_errno ) );
AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
}
}
@ -1052,6 +1055,7 @@ ldif_prepare_create(
struct stat st;
Entry *parent = NULL;
int rc;
char ebuf[128];
if ( op->o_abandon )
return SLAPD_ABANDON;
@ -1067,7 +1071,7 @@ ldif_prepare_create(
} else if ( errno != ENOENT ) {
Debug( LDAP_DEBUG_ANY,
"ldif_prepare_create: cannot stat \"%s\": %s\n",
dnpath->bv_val, STRERROR( errno ) );
dnpath->bv_val, AC_STRERROR_R( errno, ebuf, sizeof(ebuf) ) );
rc = LDAP_OTHER;
*text = "internal error (cannot check entry file)";
@ -1120,7 +1124,7 @@ ldif_prepare_create(
case LDAP_OTHER:
Debug( LDAP_DEBUG_ANY,
"ldif_prepare_create: cannot stat \"%s\" parent dir: %s\n",
ndn->bv_val, STRERROR( errno ) );
ndn->bv_val, AC_STRERROR_R( errno, ebuf, sizeof(ebuf) ) );
*text = "internal error (cannot stat parent dir)";
break;
}
@ -1473,6 +1477,7 @@ ldif_back_delete( Operation *op, SlapReply *rs )
struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
struct berval path;
int rc = LDAP_SUCCESS;
char ebuf[128];
if ( BER_BVISEMPTY( &op->o_csn )) {
struct berval csn;
@ -1525,7 +1530,7 @@ ldif_back_delete( Operation *op, SlapReply *rs )
if ( rc == LDAP_OTHER ) {
Debug( LDAP_DEBUG_ANY, "ldif_back_delete: %s \"%s\": %s\n",
"cannot delete", path.bv_val, STRERROR( errno ) );
"cannot delete", path.bv_val, AC_STRERROR_R( errno, ebuf, sizeof(ebuf) ) );
}
SLAP_FREE( path.bv_val );
@ -1551,6 +1556,7 @@ ldif_move_entry(
struct berval newpath;
char *parentdir = NULL, *trash;
int rc, rename_res;
char ebuf[128];
if ( same_ndn ) {
rc = LDAP_SUCCESS;
@ -1606,7 +1612,7 @@ ldif_move_entry(
if ( rc != LDAP_SUCCESS ) {
Debug(LDAP_DEBUG_ANY,
"ldif_move_entry: %s (%s): \"%s\" -> \"%s\"\n",
*text, STRERROR(errno),
*text, AC_STRERROR_R(errno, ebuf, sizeof(ebuf)),
op->o_req_dn.bv_val, entry->e_dn );
}
}

View File

@ -1598,10 +1598,11 @@ connection_input( Connection *conn , conn_readinfo *cri )
int err = sock_errno();
if ( err != EWOULDBLOCK && err != EAGAIN ) {
char ebuf[128];
/* log, close and send error */
Debug( LDAP_DEBUG_TRACE,
"ber_get_next on fd %d failed errno=%d (%s)\n",
conn->c_sd, err, sock_errstr(err) );
conn->c_sd, err, sock_errstr(err, ebuf, sizeof(ebuf)) );
ber_free( conn->c_currentber, 1 );
conn->c_currentber = NULL;

View File

@ -1560,6 +1560,7 @@ slap_open_listener(
struct sockaddr **sal = NULL, **psal;
int socktype = SOCK_STREAM; /* default to COTS */
ber_socket_t s;
char ebuf[128];
#if defined(LDAP_PF_LOCAL) || defined(SLAP_X_LISTENER_MOD)
/*
@ -1690,7 +1691,7 @@ slap_open_listener(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"daemon: %s socket() failed errno=%d (%s)\n",
af, err, sock_errstr(err) );
af, err, sock_errstr(err, ebuf, sizeof(ebuf)) );
sal++;
continue;
}
@ -1720,7 +1721,7 @@ slap_open_listener(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY, "slapd(%ld): "
"setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n",
(long) l.sl_sd, err, sock_errstr(err) );
(long) l.sl_sd, err, sock_errstr(err, ebuf, sizeof(ebuf)) );
}
#endif /* SO_REUSEADDR */
}
@ -1740,7 +1741,7 @@ slap_open_listener(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY, "slapd(%ld): "
"setsockopt(IPV6_V6ONLY) failed errno=%d (%s)\n",
(long) l.sl_sd, err, sock_errstr(err) );
(long) l.sl_sd, err, sock_errstr(err, ebuf, sizeof(ebuf)) );
}
#endif /* IPV6_V6ONLY */
addrlen = sizeof(struct sockaddr_in6);
@ -1787,7 +1788,7 @@ slap_open_listener(
err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"daemon: bind(%ld) failed errno=%d (%s)\n",
(long)l.sl_sd, err, sock_errstr( err ) );
(long)l.sl_sd, err, sock_errstr( err, ebuf, sizeof(ebuf) ) );
tcp_close( s );
sal++;
continue;
@ -2219,6 +2220,7 @@ slap_listener(
#endif
int cflag;
int tid;
char ebuf[128];
Debug( LDAP_DEBUG_TRACE,
">>> slap_listener(%s)\n",
@ -2270,7 +2272,7 @@ slap_listener(
Debug( LDAP_DEBUG_ANY,
"daemon: accept(%ld) failed errno=%d (%s)\n",
(long) sl->sl_sd, err, sock_errstr(err) );
(long) sl->sl_sd, err, sock_errstr(err, ebuf, sizeof(ebuf)) );
ldap_pvt_thread_yield();
return 0;
}
@ -2312,7 +2314,7 @@ slap_listener(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(SO_KEEPALIVE) failed "
"errno=%d (%s)\n", (long) sfd, err, sock_errstr(err) );
"errno=%d (%s)\n", (long) sfd, err, sock_errstr(err, ebuf, sizeof(ebuf)) );
slapd_close(sfd);
return 0;
}
@ -2326,7 +2328,7 @@ slap_listener(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(TCP_NODELAY) failed "
"errno=%d (%s)\n", (long) sfd, err, sock_errstr(err) );
"errno=%d (%s)\n", (long) sfd, err, sock_errstr(err, ebuf, sizeof(ebuf)) );
slapd_close(sfd);
return 0;
}
@ -2503,6 +2505,7 @@ slapd_daemon_task(
int ebadf = 0;
int tid = (slap_daemon_st *) ptr - slap_daemon;
int old_threads = slapd_daemon_threads;
char ebuf[128];
#define SLAPD_IDLE_CHECK_LIMIT 4
@ -2551,7 +2554,7 @@ slapd_daemon_task(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd_daemon_task: getsockopt(SO_RCVBUF) failed errno=%d (%s)\n",
err, sock_errstr(err) );
err, sock_errstr(err, ebuf, sizeof(ebuf)) );
}
optlen = sizeof( size );
@ -2565,7 +2568,7 @@ slapd_daemon_task(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd_daemon_task: setsockopt(SO_RCVBUF) failed errno=%d (%s)\n",
err, sock_errstr(err) );
err, sock_errstr(err, ebuf, sizeof(ebuf)) );
}
optlen = sizeof( realsize );
@ -2579,7 +2582,7 @@ slapd_daemon_task(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd_daemon_task: getsockopt(SO_RCVBUF) failed errno=%d (%s)\n",
err, sock_errstr(err) );
err, sock_errstr(err, ebuf, sizeof(ebuf)) );
}
Debug(LDAP_DEBUG_ANY,
@ -2607,7 +2610,7 @@ slapd_daemon_task(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd_daemon_task: getsockopt(SO_SNDBUF) failed errno=%d (%s)\n",
err, sock_errstr(err) );
err, sock_errstr(err, ebuf, sizeof(ebuf)) );
}
optlen = sizeof( size );
@ -2621,7 +2624,7 @@ slapd_daemon_task(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd_daemon_task: setsockopt(SO_SNDBUF) failed errno=%d (%s)",
err, sock_errstr(err) );
err, sock_errstr(err, ebuf, sizeof(ebuf)) );
}
optlen = sizeof( realsize );
@ -2635,7 +2638,7 @@ slapd_daemon_task(
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd_daemon_task: getsockopt(SO_SNDBUF) failed errno=%d (%s)\n",
err, sock_errstr(err) );
err, sock_errstr(err, ebuf, sizeof(ebuf)) );
}
Debug(LDAP_DEBUG_ANY,
@ -2686,7 +2689,7 @@ slapd_daemon_task(
Debug( LDAP_DEBUG_ANY,
"daemon: listen(%s, 5) failed errno=%d (%s)\n",
slap_listeners[l]->sl_url.bv_val, err,
sock_errstr(err) );
sock_errstr(err, ebuf, sizeof(ebuf)) );
return (void*)-1;
}
@ -2916,7 +2919,7 @@ loop:
" failed count %d "
"err (%d): %s\n",
ebadf, err,
sock_errstr( err ) );
sock_errstr( err, ebuf, sizeof(ebuf) ) );
}
if ( ebadf >= SLAPD_EBADF_LIMIT ) {
slapd_shutdown = 2;

View File

@ -375,6 +375,7 @@ static long send_ldap_ber(
/* write the pdu */
while( 1 ) {
int err;
char ebuf[128];
if ( ber_flush2( conn->c_sb, ber, LBER_FLUSH_FREE_NEVER ) == 0 ) {
ret = bytes;
@ -390,7 +391,7 @@ static long send_ldap_ber(
*/
Debug( LDAP_DEBUG_CONNS, "ber_flush2 failed errno=%d reason=\"%s\"\n",
err, sock_errstr(err) );
err, sock_errstr(err, ebuf, sizeof(ebuf)) );
if ( err != EWOULDBLOCK && err != EAGAIN ) {
close_reason = "connection lost on write";