if( rc < 0 ) {
Debug( LDAP_DEBUG_TRACE,
- "connection_read(%d): input error id=%ld, closing.\n",
- s, c->c_connid, 0 );
+ "connection_read(%d): input error=%d id=%ld, closing.\n",
+ s, rc, c->c_connid );
connection_closing( c );
connection_close( c );
if ( (tag = ber_get_next( &conn->c_sb, &len, conn->c_currentber ))
!= LDAP_TAG_MESSAGE )
{
+ int err = errno;
+
Debug( LDAP_DEBUG_TRACE,
"ber_get_next on fd %d failed errno %d (%s)\n",
- lber_pvt_sb_get_desc(&conn->c_sb), errno,
- errno > -1 && errno < sys_nerr ? sys_errlist[errno] : "unknown" );
+ lber_pvt_sb_get_desc(&conn->c_sb), err,
+ err > -1 && err < sys_nerr ? sys_errlist[err] : "unknown" );
Debug( LDAP_DEBUG_TRACE,
"\t*** got %ld of %lu so far\n",
(long)(conn->c_currentber->ber_rwptr - conn->c_currentber->ber_buf),
conn->c_currentber->ber_len, 0 );
- if ( errno != EWOULDBLOCK && errno != EAGAIN ) {
+ if ( err != EWOULDBLOCK && err != EAGAIN ) {
/* log, close and send error */
ber_free( conn->c_currentber, 1 );
conn->c_currentber = NULL;
- return -1;
+ return -2;
}
return 1;
}
int tmp;
if ( (tcps = socket( AF_INET, SOCK_STREAM, 0 )) == -1 ) {
+ int err = errno;
Debug( LDAP_DEBUG_ANY,
- "daemon: socket() failed errno %d (%s)\n", errno,
- errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
+ "daemon: socket() failed errno %d (%s)\n", err,
+ err > -1 && err < sys_nerr ? sys_errlist[err] :
"unknown", 0 );
exit( 1 );
}
if ( setsockopt( tcps, SOL_SOCKET, SO_REUSEADDR,
(char *) &tmp, sizeof(tmp) ) == -1 )
{
+ int err = errno;
Debug( LDAP_DEBUG_ANY,
"slapd(%d): setsockopt() failed errno %d (%s)\n",
- tcps, errno,
- errno > -1 && errno < sys_nerr
- ? sys_errlist[errno] : "unknown" );
-
- errno = 0;
+ tcps, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
}
if ( bind( tcps, (struct sockaddr *) addr, sizeof(*addr) ) == -1 ) {
+ int err = errno;
Debug( LDAP_DEBUG_ANY, "daemon: bind(%d) failed errno %d (%s)\n",
- tcps, errno,
- errno > -1 && errno < sys_nerr
- ? sys_errlist[errno] : "unknown" );
+ tcps, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
exit( 1 );
}
}
if( !inetd ) {
if ( listen( tcps, 5 ) == -1 ) {
+ int err = errno;
Debug( LDAP_DEBUG_ANY,
"daemon: listen(%d, 5) failed errno %d (%s)\n",
- tcps, errno,
- errno > -1 && errno < sys_nerr
- ? sys_errlist[errno] : "unknown" );
+ tcps, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
exit( 1 );
}
ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
switch(ns = select( nfds, &readfds, &writefds, 0, tvp )) {
- case -1: /* failure - try again */
- if( errno != EINTR ) {
- Debug( LDAP_DEBUG_CONNS,
- "daemon: select failed (%d): %s\n",
- errno,
- errno >= 0 && errno < sys_nerr
- ? sys_errlist[errno] : "unknown",
- 0 );
-
- slapd_shutdown = -1;
+ case -1: { /* failure - try again */
+ int err = errno;
+ if( err != EINTR ) {
+ Debug( LDAP_DEBUG_CONNS,
+ "daemon: select failed (%d): %s\n",
+ err,
+ err >= 0 && err < sys_nerr
+ ? sys_errlist[err] : "unknown",
+ 0 );
+
+ slapd_shutdown = -1;
+ }
}
- errno = 0;
continue;
case 0: /* timeout - let threads run */
if ( (s = accept( tcps,
(struct sockaddr *) &from, &len )) == -1 )
{
+ int err = errno;
Debug( LDAP_DEBUG_ANY,
- "daemon: accept(%d) failed errno %d (%s)\n", errno,
- tcps, errno >= 0 && errno < sys_nerr ?
- sys_errlist[errno] : "unknown");
+ "daemon: accept(%d) failed errno %d (%s)\n", err,
+ tcps, err >= 0 && err < sys_nerr ?
+ sys_errlist[err] : "unknown");
continue;
}
if( slapd_shutdown > 0 ) {
Debug( LDAP_DEBUG_TRACE,
- "daemon: shutdown requested and initiated.\n",
- 0, 0, 0 );
+ "daemon: shutdown requested (%d) and initiated.\n",
+ (int) slapd_shutdown, 0, 0 );
} else if ( slapd_shutdown < 0 ) {
Debug( LDAP_DEBUG_TRACE,
- "daemon: abnormal condition, shutdown initiated.\n",
- 0, 0, 0 );
+ "daemon: abnormal condition (%d), shutdown initiated.\n",
+ (int) slapd_shutdown, 0, 0 );
} else {
Debug( LDAP_DEBUG_TRACE,
"daemon: no active streams, shutdown initiated.\n",
void
slap_set_shutdown( int sig )
{
- slapd_shutdown = 1;
+ slapd_shutdown = sig;
ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );
/* reinstall self */
bytes = ber->ber_ptr - ber->ber_buf;
while ( ber_flush( &conn->c_sb, ber, 1 ) != 0 ) {
+ int err = errno;
/*
* we got an error. if it's ewouldblock, we need to
* wait on the socket being writable. otherwise, figure
*/
Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno %d msg (%s)\n",
- errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno]
+ err, err > -1 && err < sys_nerr ? sys_errlist[err]
: "unknown", 0 );
- if ( errno != EWOULDBLOCK && errno != EAGAIN ) {
+ if ( err != EWOULDBLOCK && err != EAGAIN ) {
connection_closing( conn );
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
/* write the pdu */
while ( ber_flush( &conn->c_sb, ber, 1 ) != 0 ) {
+ int err = errno;
/*
* we got an error. if it's ewouldblock, we need to
* wait on the socket being writable. otherwise, figure
*/
Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno %d msg (%s)\n",
- errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno]
+ err, err > -1 && err < sys_nerr ? sys_errlist[err]
: "unknown", 0 );
- if ( errno != EWOULDBLOCK && errno != EAGAIN ) {
+ if ( err != EWOULDBLOCK && err != EAGAIN ) {
connection_closing( conn );
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );