X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=servers%2Fslapd%2Fdaemon.c;h=3412fec5e4090afc03128da783faf2a06cae2587;hb=dacc0bfc7da20b4d0c669038a6289dc370098381;hp=509ed6a275947cdffbc928ea375b136afcaa1daf;hpb=4a5d740e2ee4e700e76b2eac6f079e39f0134c94;p=openldap diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 509ed6a275..3412fec5e4 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -5,65 +5,44 @@ * Added locking of new_conn_mutex when traversing the c[] array. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef _AIX -#include -#endif -#include "slap.h" #include "portable.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + #include "ldapconfig.h" -#ifdef NEED_FILIO +#include "slap.h" + +#ifdef HAVE_SYS_FILIO_H #include -#else /* NEED_FILIO */ +#elif HAVE_SYS_IOCTL_H #include -#endif /* NEED_FILIO */ -#ifdef USE_SYSCONF -#include -#endif /* USE_SYSCONF */ +#endif -#ifdef TCP_WRAPPERS +#ifdef HAVE_TCPD #include int allow_severity = LOG_INFO; int deny_severity = LOG_NOTICE; -#endif /* TCP_WRAPPERS */ - -extern Operation *op_add(); - -#ifndef SYSERRLIST_IN_STDIO -extern int sys_nerr; -extern char *sys_errlist[]; -#endif -extern time_t currenttime; -extern pthread_mutex_t currenttime_mutex; -extern int active_threads; -extern pthread_mutex_t active_threads_mutex; -extern pthread_mutex_t new_conn_mutex; -extern int slapd_shutdown; -extern pthread_t listener_tid; -extern int num_conns; -extern pthread_mutex_t ops_mutex; -extern int g_argc; -extern char **g_argv; +#endif /* TCP Wrappers */ int dtblsize; Connection *c; -static void set_shutdown(); -static void do_nothing(); +static volatile sig_atomic_t slapd_shutdown = 0; +static void set_shutdown(int sig); +static void do_nothing (int sig); -void +void * slapd_daemon( - int port + void *port ) { Operation *o; @@ -77,14 +56,14 @@ slapd_daemon( FILE *fp; int on = 1; -#ifdef USE_SYSCONF +#ifdef HAVE_SYSCONF dtblsize = sysconf( _SC_OPEN_MAX ); -#else /* USE_SYSCONF */ +#elif HAVE_GETDTABLESIZE dtblsize = getdtablesize(); -#endif /* USE_SYSCONF */ - /* - * Add greg@greg.rim.or.jp - */ +#else + dtblsize = FD_SETSIZE +#endif + #ifdef FD_SETSIZE if(dtblsize > FD_SETSIZE) { dtblsize = FD_SETSIZE; @@ -133,7 +112,7 @@ slapd_daemon( (void) memset( (void *) &addr, '\0', sizeof(addr) ); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; - addr.sin_port = htons( port ); + addr.sin_port = htons( (int)port ); if ( bind( tcps, (struct sockaddr *) &addr, sizeof(addr) ) == -1 ) { Debug( LDAP_DEBUG_ANY, "bind() failed errno %d (%s)\n", errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] : @@ -149,25 +128,16 @@ slapd_daemon( } (void) SIGNAL( SIGPIPE, SIG_IGN ); -#ifdef linux - /* - * LinuxThreads are implemented using SIGUSR1/USR2, - * so we'll use SIGSTKFLT and SIGUNUSED - */ - (void) SIGNAL( SIGSTKFLT, (void *) do_nothing ); - (void) SIGNAL( SIGUNUSED, (void *) set_shutdown ); -#else /* !linux */ - (void) SIGNAL( SIGUSR1, (void *) do_nothing ); - (void) SIGNAL( SIGUSR2, (void *) set_shutdown ); -#endif /* !linux */ - (void) SIGNAL( SIGTERM, (void *) set_shutdown ); - (void) SIGNAL( SIGINT, (void *) set_shutdown ); - (void) SIGNAL( SIGHUP, (void *) set_shutdown ); + (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); + (void) SIGNAL( LDAP_SIGUSR2, set_shutdown ); + (void) SIGNAL( SIGTERM, set_shutdown ); + (void) SIGNAL( SIGINT, set_shutdown ); + (void) SIGNAL( SIGHUP, set_shutdown ); Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 ); #ifdef SLAPD_PIDFILE if ( (fp = fopen( SLAPD_PIDFILE, "w" )) != NULL ) { - fprintf( fp, "%d\n", getpid() ); + fprintf( fp, "%d\n", (int) getpid() ); fclose( fp ); } #endif @@ -220,7 +190,7 @@ slapd_daemon( Debug( LDAP_DEBUG_CONNS, "before select active_threads %d\n", active_threads, 0, 0 ); -#if defined(PTHREAD_PREEMPTIVE) || defined(NO_THREADS) +#if defined( HAVE_YIELDING_SELECT ) || defined( NO_THREADS ) tvp = NULL; #else tvp = active_threads ? &zero : NULL; @@ -282,7 +252,7 @@ slapd_daemon( char *s; client_addr = inet_ntoa( from.sin_addr ); -#if defined(REVERSE_LOOKUP) || defined(TCP_WRAPPERS) +#if defined(SLAPD_RLOOKUPS) || defined(HAVE_TCPD) hp = gethostbyaddr( (char *) &(from.sin_addr.s_addr), sizeof(from.sin_addr.s_addr), AF_INET ); @@ -307,7 +277,7 @@ slapd_daemon( client_addr = NULL; } -#ifdef TCP_WRAPPERS +#ifdef HAVE_TCPD if(!hosts_ctl("slapd", client_name, client_addr, STRING_UNKNOWN)) { @@ -323,7 +293,7 @@ slapd_daemon( pthread_mutex_unlock( &new_conn_mutex ); continue; } -#endif /* TCP_WRAPPERS */ +#endif /* HAVE_TCPD */ Statslog( LDAP_DEBUG_STATS, "conn=%d fd=%d connection from %s (%s) accepted.\n", @@ -335,13 +305,13 @@ slapd_daemon( if ( c[ns].c_addr != NULL ) { free( c[ns].c_addr ); } - c[ns].c_addr = strdup( client_addr ); + c[ns].c_addr = ch_strdup( client_addr ); if ( c[ns].c_domain != NULL ) { free( c[ns].c_domain ); } - c[ns].c_domain = strdup( client_name == NULL + c[ns].c_domain = ch_strdup( client_name == NULL ? "" : client_name ); pthread_mutex_lock( &c[ns].c_dnmutex ); @@ -415,40 +385,24 @@ slapd_daemon( 0 ); be_close(); Debug( LDAP_DEBUG_ANY, "slapd stopping\n", 0, 0, 0 ); + return NULL; } static void -set_shutdown() +set_shutdown( int sig ) { - Debug( LDAP_DEBUG_ANY, "slapd got shutdown signal\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_ANY, "slapd got shutdown signal %d\n", sig, 0, 0 ); slapd_shutdown = 1; -#ifdef linux - /* - * LinuxThreads are implemented using SIGUSR1/USR2, - * so we'll use SIGSTKFLT and SIGUNUSED - */ - pthread_kill( listener_tid, SIGSTKFLT ); - (void) SIGNAL( SIGUNUSED, (void *) set_shutdown ); -#else /* !linux */ - pthread_kill( listener_tid, SIGUSR1 ); - (void) SIGNAL( SIGUSR2, (void *) set_shutdown ); -#endif /* !linux */ - (void) SIGNAL( SIGTERM, (void *) set_shutdown ); - (void) SIGNAL( SIGINT, (void *) set_shutdown ); - (void) SIGNAL( SIGHUP, (void *) set_shutdown ); + pthread_kill( listener_tid, LDAP_SIGUSR1 ); + (void) SIGNAL( LDAP_SIGUSR2, set_shutdown ); + (void) SIGNAL( SIGTERM, set_shutdown ); + (void) SIGNAL( SIGINT, set_shutdown ); + (void) SIGNAL( SIGHUP, set_shutdown ); } static void -do_nothing() +do_nothing( int sig ) { - Debug( LDAP_DEBUG_TRACE, "slapd got do_nothing signal\n", 0, 0, 0 ); -#ifdef linux - /* - * LinuxThreads are implemented using SIGUSR1/USR2, - * so we'll use SIGSTKFLT and SIGUNUSED - */ - (void) SIGNAL( SIGSTKFLT, (void *) do_nothing ); -#else /* !linux */ - (void) SIGNAL( SIGUSR1, (void *) do_nothing ); -#endif /* !linux */ + Debug( LDAP_DEBUG_TRACE, "slapd got do_nothing signal %d\n", sig, 0, 0 ); + (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); }