Commit 67d005ee authored by Ondřej Kuzník's avatar Ondřej Kuzník

ITS#9348 Stop using plain strerror()

parent f3e86d3d
Pipeline #1109 passed with stage
in 26 minutes and 7 seconds
......@@ -168,8 +168,10 @@ static int dsaschema_read_config(const char *fname, int depth)
fp = fopen(fname, "r");
if (fp == NULL) {
char ebuf[128];
int saved_errno = errno;
fprintf(stderr, "could not open config file \"%s\": %s (%d)\n",
fname, strerror(errno), errno);
fname, AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)), saved_errno);
return 1;
}
fp_getline_init(&lineno);
......
......@@ -86,8 +86,10 @@ static void debug_dump(const void *ptr, size_t size)
DEBUG_DUMP(ptr, size); \
if (tio_write(fp, ptr, (size_t)size)) \
{ \
char ebuf[128]; \
int saved_errno = errno; \
DEBUG_PRINT("WRITE : var="__STRING(ptr)" error: %s", \
strerror(errno)); \
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf))); \
ERROR_OUT_WRITEERROR(fp); \
}
......@@ -161,8 +163,10 @@ static void debug_dump(const void *ptr, size_t size)
#define READ(fp, ptr, size) \
if (tio_read(fp, ptr, (size_t)size)) \
{ \
char ebuf[128]; \
int saved_errno = errno; \
DEBUG_PRINT("READ : var="__STRING(ptr)" error: %s", \
strerror(errno)); \
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf))); \
ERROR_OUT_READERROR(fp); \
} \
DEBUG_PRINT("READ : var="__STRING(ptr)" size=%d", (int)(size)); \
......@@ -301,7 +305,10 @@ static void debug_dump(const void *ptr, size_t size)
/* read (skip) the specified number of bytes */ \
if (tio_skip(fp, sz)) \
{ \
DEBUG_PRINT("READ : skip error: %s", strerror(errno)); \
char ebuf[128]; \
int saved_errno = errno; \
DEBUG_PRINT("READ : skip error: %s", \
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf))); \
ERROR_OUT_READERROR(fp); \
}
......@@ -350,7 +357,10 @@ TFILE *nslcd_client_open(void)
/* flush the stream */ \
if (tio_flush(fp) < 0) \
{ \
DEBUG_PRINT("WRITE_FLUSH : error: %s", strerror(errno)); \
char ebuf[128]; \
int saved_errno = errno; \
DEBUG_PRINT("WRITE_FLUSH : error: %s", \
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf))); \
ERROR_OUT_WRITEERROR(fp); \
} \
/* read and check response version number */ \
......
......@@ -298,11 +298,15 @@ static void handleconnection(nssov_info *ni,int sock,Operation *op)
struct berval peerbv = { sizeof(peerbuf), peerbuf };
/* log connection */
if (LUTIL_GETPEEREID(sock,&uid,&gid,&peerbv))
Debug( LDAP_DEBUG_TRACE,"nssov: connection from unknown client: %s\n",strerror(errno) );
else
if (LUTIL_GETPEEREID(sock,&uid,&gid,&peerbv)) {
char ebuf[128];
int saved_errno = errno;
Debug( LDAP_DEBUG_TRACE,"nssov: connection from unknown client: %s\n",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
} else {
Debug( LDAP_DEBUG_TRACE,"nssov: connection from uid=%d gid=%d\n",
(int)uid,(int)gid );
}
/* Should do authid mapping too */
op->o_dn.bv_len = sprintf(authid,"gidNumber=%d+uidNumber=%d,cn=peercred,cn=external,cn=auth",
......@@ -322,7 +326,10 @@ static void handleconnection(nssov_info *ni,int sock,Operation *op)
READBUFFER_MINSIZE,READBUFFER_MAXSIZE,
WRITEBUFFER_MINSIZE,WRITEBUFFER_MAXSIZE))==NULL)
{
Debug( LDAP_DEBUG_ANY,"nssov: cannot create stream for writing: %s",strerror(errno) );
char ebuf[128];
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: cannot create stream for writing: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
(void)close(sock);
return;
}
......@@ -403,27 +410,43 @@ static void *acceptconn(void *ctx, void *arg)
connection_client_enable(ni->ni_conn);
if (csock<0)
{
char ebuf[128];
int saved_errno = errno;
if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK))
{
Debug( LDAP_DEBUG_TRACE,"nssov: accept() failed (ignored): %s",strerror(errno) );
Debug( LDAP_DEBUG_TRACE,"nssov: accept() failed (ignored): %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
return NULL;
}
Debug( LDAP_DEBUG_ANY,"nssov: accept() failed: %s",strerror(errno) );
Debug( LDAP_DEBUG_ANY,"nssov: accept() failed: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
return NULL;
}
/* make sure O_NONBLOCK is not inherited */
if ((j=fcntl(csock,F_GETFL,0))<0)
{
Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_GETFL) failed: %s",strerror(errno) );
if (close(csock))
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
char ebuf[128];
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_GETFL) failed: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
if (close(csock)) {
saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
return NULL;
}
if (fcntl(csock,F_SETFL,j&~O_NONBLOCK)<0)
{
Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_SETFL,~O_NONBLOCK) failed: %s",strerror(errno) );
if (close(csock))
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
char ebuf[128];
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_SETFL,~O_NONBLOCK) failed: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
if (close(csock)) {
saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
return NULL;
}
}
......@@ -868,10 +891,12 @@ nssov_db_open(
}
}
if ( slapMode & SLAP_SERVER_MODE ) {
char ebuf[128];
/* make sure /var/run/nslcd exists */
if (mkdir(NSLCD_PATH, (mode_t) 0555)) {
int saved_errno = errno;
Debug(LDAP_DEBUG_TRACE,"nssov: mkdir(%s) failed (ignored): %s\n",
NSLCD_PATH,strerror(errno) );
NSLCD_PATH, AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
} else {
Debug(LDAP_DEBUG_TRACE,"nssov: created %s\n",NSLCD_PATH );
}
......@@ -879,14 +904,17 @@ nssov_db_open(
/* create a socket */
if ( (sock=socket(PF_UNIX,SOCK_STREAM,0))<0 )
{
Debug(LDAP_DEBUG_ANY,"nssov: cannot create socket: %s\n",strerror(errno) );
int saved_errno = errno;
Debug(LDAP_DEBUG_ANY,"nssov: cannot create socket: %s\n",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
return -1;
}
/* remove existing named socket */
if (unlink(NSLCD_SOCKET)<0)
{
int saved_errno = errno;
Debug( LDAP_DEBUG_TRACE,"nssov: unlink() of "NSLCD_SOCKET" failed (ignored): %s\n",
strerror(errno) );
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
/* create socket address structure */
memset(&addr,0,sizeof(struct sockaddr_un));
......@@ -896,18 +924,27 @@ nssov_db_open(
/* bind to the named socket */
if (bind(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr_un)))
{
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: bind() to "NSLCD_SOCKET" failed: %s",
strerror(errno) );
if (close(sock))
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
if (close(sock)) {
saved_errno = errno
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
return -1;
}
/* close the file descriptor on exit */
if (fcntl(sock,F_SETFD,FD_CLOEXEC)<0)
{
Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_SETFL,O_NONBLOCK) failed: %s",strerror(errno) );
if (close(sock))
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_SETFL,O_NONBLOCK) failed: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
if (close(sock)) {
saved_errno = errno
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
return -1;
}
/* set permissions of socket so anybody can do requests */
......@@ -917,17 +954,27 @@ nssov_db_open(
http://lkml.org/lkml/2005/5/16/11 */
if (chmod(NSLCD_SOCKET,(mode_t)0666))
{
Debug( LDAP_DEBUG_ANY,"nssov: chmod(0666) failed: %s",strerror(errno) );
if (close(sock))
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: chmod(0666) failed: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
if (close(sock)) {
saved_errno = errno
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
return -1;
}
/* start listening for connections */
if (listen(sock,SOMAXCONN)<0)
{
Debug( LDAP_DEBUG_ANY,"nssov: listen() failed: %s",strerror(errno) );
if (close(sock))
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"nssov: listen() failed: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
if (close(sock)) {
saved_errno = errno
Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
return -1;
}
ni->ni_socket = sock;
......@@ -946,18 +993,23 @@ nssov_db_close(
nssov_info *ni = on->on_bi.bi_private;
if ( slapMode & SLAP_SERVER_MODE ) {
char ebuf[128];
/* close socket if it's still in use */
if (ni->ni_socket >= 0)
{
if (close(ni->ni_socket))
Debug( LDAP_DEBUG_ANY,"problem closing server socket (ignored): %s",strerror(errno) );
if (close(ni->ni_socket)) {
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,"problem closing server socket (ignored): %s",
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
ni->ni_socket = -1;
}
/* remove existing named socket */
if (unlink(NSLCD_SOCKET)<0)
{
int saved_errno = errno;
Debug( LDAP_DEBUG_TRACE,"unlink() of "NSLCD_SOCKET" failed (ignored): %s",
strerror(errno) );
AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
}
}
return 0;
......
......@@ -1143,9 +1143,11 @@ file2anlist( AttributeName *an, const char *fname, const char *brkstr )
fp = fopen( fname, "r" );
if ( fp == NULL ) {
char ebuf[128];
int saved_errno = errno;
Debug( LDAP_DEBUG_ANY,
"get_attrs_from_file: failed to open attribute list file "
"\"%s\": %s\n", fname, strerror(errno) );
"\"%s\": %s\n", fname, AC_STRERROR_R( saved_errno, ebuf, sizeof(ebuf) ) );
return NULL;
}
......
......@@ -700,8 +700,10 @@ mdb_cf_gen( ConfigArgs *c )
}
ch_free( testpath );
if ( !f ) {
char ebuf[128];
int saved_errno = errno;
snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: invalid path: %s",
c->log, strerror( errno ));
c->log, AC_STRERROR_R( saved_errno, ebuf, sizeof(ebuf) ) );
Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg );
return -1;
}
......
......@@ -787,11 +787,12 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
init_config_argv( c );
if ( stat( fname, &s ) != 0 ) {
char ebuf[128];
int saved_errno = errno;
ldap_syslog = 1;
Debug(LDAP_DEBUG_ANY,
"could not stat config file \"%s\": %s (%d)\n",
fname, strerror(saved_errno), saved_errno);
fname, AC_STRERROR_R( saved_errno, ebuf, sizeof(ebuf) ), saved_errno);
ch_free( c->argv );
ch_free( c );
return(1);
......@@ -809,11 +810,12 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
fp = fopen( fname, "r" );
if ( fp == NULL ) {
char ebuf[128];
int saved_errno = errno;
ldap_syslog = 1;
Debug(LDAP_DEBUG_ANY,
"could not open config file \"%s\": %s (%d)\n",
fname, strerror(saved_errno), saved_errno);
fname, AC_STRERROR_R( saved_errno, ebuf, sizeof(ebuf) ), saved_errno);
ch_free( c->argv );
ch_free( c );
return(1);
......
......@@ -945,12 +945,13 @@ unhandled_option:;
FILE *fp = fopen( slapd_pid_file, "w" );
if ( fp == NULL ) {
char ebuf[128];
int save_errno = errno;
Debug( LDAP_DEBUG_ANY, "unable to open pid file "
"\"%s\": %d (%s)\n",
slapd_pid_file,
save_errno, strerror( save_errno ) );
save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
free( slapd_pid_file );
slapd_pid_file = NULL;
......@@ -967,12 +968,13 @@ unhandled_option:;
FILE *fp = fopen( slapd_args_file, "w" );
if ( fp == NULL ) {
char ebuf[128];
int save_errno = errno;
Debug( LDAP_DEBUG_ANY, "unable to open args file "
"\"%s\": %d (%s)\n",
slapd_args_file,
save_errno, strerror( save_errno ) );
save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
free( slapd_args_file );
slapd_args_file = NULL;
......
......@@ -46,6 +46,7 @@ static int
test_file( const char *fname, const char *ftype )
{
struct stat st;
char ebuf[128];
int save_errno;
switch ( stat( fname, &st ) ) {
......@@ -70,7 +71,7 @@ test_file( const char *fname, const char *ftype )
Debug( LDAP_DEBUG_ANY, "unable to open file "
"\"%s\": %d (%s)\n",
fname,
save_errno, strerror( save_errno ) );
save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
return -1;
}
......@@ -82,7 +83,7 @@ test_file( const char *fname, const char *ftype )
Debug( LDAP_DEBUG_ANY, "unable to stat file "
"\"%s\": %d (%s)\n",
slapd_pid_file,
save_errno, strerror( save_errno ) );
save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
return -1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment