#define _LUTIL_H 1
#include <ldap_cdefs.h>
+#include <lber_types.h>
+
/*
* Include file for LDAP utility routine
*/
int argc,
char *argv[] ));
+/* sockpair.c */
+LDAP_F( int )
+lutil_pair( LBER_SOCKET_T sd[2] );
LDAP_END_DECL
*/
#include "portable.h"
-
#include <ac/socket.h>
-/* Return a pair of descriptors that are connected to each other. The
- * returned descriptors are suitable for use with select(). The two
+#include <lutil.h>
+
+/* Return a pair of socket descriptors that are connected to each other.
+ * The returned descriptors are suitable for use with select(). The two
* descriptors may or may not be identical; the function may return
* the same descriptor number in both slots. It is guaranteed that
- * data written on fds[1] will be readable on fds[0]. The returned
+ * data written on sds[1] will be readable on sds[0]. The returned
* descriptors may be datagram oriented, so data should be written
* in reasonably small pieces and read all at once. On Unix systems
* this function is best implemented using a single pipe() call.
*/
-int lutil_pair( int fds[2] )
+
+int lutil_pair( LBER_SOCKET_T sds[2] )
{
struct sockaddr_in si;
int rc, len = sizeof(si);
- int fd;
+ LBER_SOCKET_T sd;
- fd = socket( AF_INET, SOCK_DGRAM, 0 );
- if (fd < 0)
- return fd;
+ sd = socket( AF_INET, SOCK_DGRAM, 0 );
+ if (sd < 0)
+ return sd;
(void) memset( (void*) &si, 0, len );
si.sin_family = AF_INET;
si.sin_port = 0;
si.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
- if ( rc = bind( fd, (struct sockaddr *)&si, len ) )
- {
-fail: tcp_close(fd);
+ if ( rc = bind( sd, (struct sockaddr *)&si, len ) ) {
+ tcp_close(sd);
+ return rc;
+ }
+
+ if ( rc = getsockname( sd, (struct sockaddr *)&si, &len ) ) {
+ tcp_close(sd);
return rc;
}
- if ( rc = getsockname( fd, (struct sockaddr *)&si, &len ) )
- goto fail;
- if ( rc = connect( fd, (struct sockaddr *)&si, len ) )
- goto fail;
- fds[0] = fds[1] = fd;
+
+ if ( rc = connect( sd, (struct sockaddr *)&si, len ) ) {
+ tcp_close(sd);
+ return rc;
+ }
+
+ sds[0] = sds[1] = sd;
return 0;
}
Listener **slap_listeners = NULL;
-static int sel_exit_fds[2];
+static ber_socket_t wake_sds[2];
#define WAKE_LISTENER(w) \
-do { if (w) tcp_write( sel_exit_fds[1], "0", 1 ); } while(0)
+do { if (w) tcp_write( wake_sds[1], "0", 1 ); } while(0)
#ifdef HAVE_WINSOCK2
/* in nt_main.c */
* loop will be select'ing on this socket, and will wake up when
* this byte arrives.
*/
- if( (rc = lutil_pair( sel_exit_fds )) < 0 )
+ if( (rc = lutil_pair( wake_sds )) < 0 )
{
Debug( LDAP_DEBUG_ANY,
"daemon: lutil_pair() failed rc=%d\n", rc, 0, 0 );
slapd_daemon_destroy(void)
{
connections_destroy();
- tcp_close( sel_exit_fds[1] );
- tcp_close( sel_exit_fds[0] );
+ tcp_close( wake_sds[1] );
+ tcp_close( wake_sds[0] );
sockdestroy();
return 0;
}
memcpy( &readfds, &slap_daemon.sd_readers, sizeof(fd_set) );
memcpy( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) );
#endif
- FD_SET( sel_exit_fds[0], &readfds );
+ FD_SET( wake_sds[0], &readfds );
for ( l = 0; slap_listeners[l] != NULL; l++ ) {
if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
/* FALL THRU */
}
- if( FD_ISSET( sel_exit_fds[0], &readfds ) )
- {
+ if( FD_ISSET( wake_sds[0], &readfds ) ) {
char c;
- tcp_read( sel_exit_fds[0], &c, 1 );
+ tcp_read( wake_sds[0], &c, 1 );
continue;
}
+
for ( l = 0; slap_listeners[l] != NULL; l++ ) {
ber_int_t s;
socklen_t len = sizeof(from);
}
#endif
-void
-slap_set_shutdown( int sig )
+RETSIGTYPE
+slap_sig_shutdown( int sig )
{
slapd_shutdown = sig;
WAKE_LISTENER(1);
/* reinstall self */
- (void) SIGNAL( sig, slap_set_shutdown );
+ (void) SIGNAL( sig, slap_sig_shutdown );
}
-void
-slap_do_nothing( int sig )
+RETSIGTYPE
+slap_sig_wake( int sig )
{
+ WAKE_LISTENER(1);
+
/* reinstall self */
- (void) SIGNAL( sig, slap_do_nothing );
+ (void) SIGNAL( sig, slap_sig_wake );
}
{
int *i;
char *newConfigFile;
- if ( is_NT_Service ) CommenceStartupProcessing( NTservice, slap_set_shutdown );
+
+ if ( is_NT_Service ) {
+ CommenceStartupProcessing( NTservice, slap_sig_shutdown );
+ }
+
i = (int*)getRegParam( NULL, "Port" );
if ( i != NULL )
{
ldap_pvt_tls_init_def_ctx();
#endif
- (void) SIGNAL( LDAP_SIGUSR1, slap_do_nothing );
- (void) SIGNAL( LDAP_SIGUSR2, slap_set_shutdown );
+ (void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
+ (void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );
+
#ifdef SIGPIPE
(void) SIGNAL( SIGPIPE, SIG_IGN );
#endif
#ifdef SIGHUP
- (void) SIGNAL( SIGHUP, slap_set_shutdown );
+ (void) SIGNAL( SIGHUP, slap_sig_shutdown );
#endif
- (void) SIGNAL( SIGINT, slap_set_shutdown );
- (void) SIGNAL( SIGTERM, slap_set_shutdown );
+ (void) SIGNAL( SIGINT, slap_sig_shutdown );
+ (void) SIGNAL( SIGTERM, slap_sig_shutdown );
#ifdef LDAP_SIGCHLD
(void) SIGNAL( LDAP_SIGCHLD, wait4child );
#endif
#ifdef SIGBREAK
/* SIGBREAK is generated when Ctrl-Break is pressed. */
- (void) SIGNAL( SIGBREAK, slap_set_shutdown );
+ (void) SIGNAL( SIGBREAK, slap_sig_shutdown );
#endif
#ifndef HAVE_WINSOCK
extern void slapd_remove LDAP_P((ber_socket_t s, int wake));
-extern void slap_set_shutdown LDAP_P((int sig));
-extern void slap_do_nothing LDAP_P((int sig));
+extern RETSIGTYPE slap_sig_shutdown LDAP_P((int sig));
+extern RETSIGTYPE slap_sig_wake LDAP_P((int sig));
extern void config_info LDAP_P((
Connection *conn,