Skip to content
Snippets Groups Projects
Commit 4d13d407 authored by Gary Williams's avatar Gary Williams
Browse files

add code to support slapd as NT service

parent 2ffc4b19
No related branches found
No related tags found
No related merge requests found
#include "portable.h" #include "portable.h"
//#include "portable_err.h"
#include <stdio.h> #include <stdio.h>
...@@ -22,18 +23,22 @@ int deny_severity = LOG_NOTICE; ...@@ -22,18 +23,22 @@ int deny_severity = LOG_NOTICE;
/* globals */ /* globals */
int dtblsize; int dtblsize;
static int tcps;
#ifdef HAVE_WINSOCK2 #ifdef HAVE_WINSOCK2
// in nt_main.c
extern ldap_pvt_thread_cond_t started_event;
/* forward reference */ /* forward reference */
void hit_socket(); void hit_socket();
/* In wsa_err.c */ /* In wsa_err.c */
char *WSAGetLastErrorString(); char *WSAGetLastErrorString();
static ldap_pvt_thread_t hit_tid;
#define WAKE_LISTENER(w) \ #define WAKE_LISTENER(w) \
do {\ do {\
if( w ) {\ if( w ) {\
ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );\ ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );\
hit_socket();\ hit_socket(); \
}\ }\
} while(0) } while(0)
#else #else
...@@ -45,9 +50,13 @@ do {\ ...@@ -45,9 +50,13 @@ do {\
} while(0) } while(0)
#endif #endif
#ifndef HAVE_WINSOCK
static
#endif
volatile sig_atomic_t slapd_shutdown = 0;
static int daemon_initialized = 0; static int daemon_initialized = 0;
static ldap_pvt_thread_t listener_tid; static ldap_pvt_thread_t listener_tid;
static volatile sig_atomic_t slapd_shutdown = 0;
static volatile sig_atomic_t slapd_listener = 0; static volatile sig_atomic_t slapd_listener = 0;
void sockinit(); void sockinit();
...@@ -119,17 +128,24 @@ void slapd_clr_write(int s, int wake) { ...@@ -119,17 +128,24 @@ void slapd_clr_write(int s, int wake) {
FD_CLR( (unsigned) s, &slap_daemon.sd_writers ); FD_CLR( (unsigned) s, &slap_daemon.sd_writers );
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
if( wake ) {
ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );
}
} }
void slapd_set_write(int s, int wake) { void slapd_set_write(int s, int wake) {
ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
WAKE_LISTENER(wake); WAKE_LISTENER(wake);
assert( FD_ISSET( s, &slap_daemon.sd_actives) ); assert( FD_ISSET( s, &slap_daemon.sd_actives) );
FD_SET( (unsigned) s, &slap_daemon.sd_writers ); FD_SET( (unsigned) s, &slap_daemon.sd_writers );
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
if( wake ) {
ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );
}
} }
void slapd_clr_read(int s, int wake) { void slapd_clr_read(int s, int wake) {
...@@ -141,6 +157,9 @@ void slapd_clr_read(int s, int wake) { ...@@ -141,6 +157,9 @@ void slapd_clr_read(int s, int wake) {
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
if( wake ) {
ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );
}
} }
void slapd_set_read(int s, int wake) { void slapd_set_read(int s, int wake) {
...@@ -151,6 +170,10 @@ void slapd_set_read(int s, int wake) { ...@@ -151,6 +170,10 @@ void slapd_set_read(int s, int wake) {
FD_SET( (unsigned) s, &slap_daemon.sd_readers ); FD_SET( (unsigned) s, &slap_daemon.sd_readers );
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
if( wake ) {
ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );
}
} }
static void slapd_close(int s) { static void slapd_close(int s) {
...@@ -158,6 +181,8 @@ static void slapd_close(int s) { ...@@ -158,6 +181,8 @@ static void slapd_close(int s) {
tcp_close(s); tcp_close(s);
} }
int int
set_socket( struct sockaddr_in *addr ) set_socket( struct sockaddr_in *addr )
{ {
...@@ -252,10 +277,12 @@ slapd_daemon_task( ...@@ -252,10 +277,12 @@ slapd_daemon_task(
void *ptr void *ptr
) )
{ {
int inetd = ((int *)ptr) [0]; struct sockaddr_in *slapd_addr = (struct sockaddr_in*)((int *)ptr)[0];
int tcps = ((int *)ptr) [1]; int inetd;
tcps = ((int *)ptr) [1];
free( ptr ); free( ptr );
inetd = ( slapd_addr == NULL);
if ( !daemon_initialized ) sockinit(); if ( !daemon_initialized ) sockinit();
slapd_listener=1; slapd_listener=1;
...@@ -289,6 +316,11 @@ slapd_daemon_task( ...@@ -289,6 +316,11 @@ slapd_daemon_task(
slapd_add( 0 ); slapd_add( 0 );
} }
#ifdef HAVE_WINSOCK
if ( started_event != NULL )
ldap_pvt_thread_cond_signal( &started_event );
#endif
// initialization complete. Here comes the loop.
while ( !slapd_shutdown ) { while ( !slapd_shutdown ) {
unsigned int i; unsigned int i;
int ns, nfds; int ns, nfds;
...@@ -302,7 +334,7 @@ slapd_daemon_task( ...@@ -302,7 +334,7 @@ slapd_daemon_task(
#if defined(SLAPD_RLOOKUPS) || defined(HAVE_TCPD) #if defined(SLAPD_RLOOKUPS) || defined(HAVE_TCPD)
struct hostent *hp; struct hostent *hp;
#endif #endif
struct timeval zero; struct timeval zero;
struct timeval *tvp; struct timeval *tvp;
char *client_name; char *client_name;
...@@ -357,7 +389,11 @@ slapd_daemon_task( ...@@ -357,7 +389,11 @@ slapd_daemon_task(
switch(ns = select( nfds, &readfds, &writefds, 0, tvp )) { switch(ns = select( nfds, &readfds, &writefds, 0, tvp )) {
case -1: { /* failure - try again */ case -1: { /* failure - try again */
#ifdef HAVE_WINSOCK
int err = WSAGetLastError();
#else
int err = errno; int err = errno;
#endif
if( err == EBADF && ++ebadf < SLAPD_EBADF_LIMIT) { if( err == EBADF && ++ebadf < SLAPD_EBADF_LIMIT) {
continue; continue;
...@@ -371,7 +407,8 @@ slapd_daemon_task( ...@@ -371,7 +407,8 @@ slapd_daemon_task(
? sys_errlist[err] : "unknown", ? sys_errlist[err] : "unknown",
0 ); 0 );
slapd_shutdown = -1;
slapd_shutdown = -1;
} }
} }
continue; continue;
...@@ -481,7 +518,6 @@ slapd_daemon_task( ...@@ -481,7 +518,6 @@ slapd_daemon_task(
} }
#endif /* HAVE_TCPD */ #endif /* HAVE_TCPD */
if( (id = connection_init(s, client_name, client_addr)) < 0 ) { if( (id = connection_init(s, client_name, client_addr)) < 0 ) {
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"daemon: connection_init(%d, %s, %s) failed.\n", "daemon: connection_init(%d, %s, %s) failed.\n",
...@@ -534,7 +570,7 @@ slapd_daemon_task( ...@@ -534,7 +570,7 @@ slapd_daemon_task(
for ( i = 0; i < nfds; i++ ) for ( i = 0; i < nfds; i++ )
#endif #endif
{ {
int wd, active; int wd;
#ifdef HAVE_WINSOCK #ifdef HAVE_WINSOCK
wd = writefds.fd_array[i]; wd = writefds.fd_array[i];
...@@ -548,7 +584,6 @@ slapd_daemon_task( ...@@ -548,7 +584,6 @@ slapd_daemon_task(
if ( wd == tcps ) { if ( wd == tcps ) {
continue; continue;
} }
Debug( LDAP_DEBUG_CONNS, Debug( LDAP_DEBUG_CONNS,
"daemon: write active on %d\n", "daemon: write active on %d\n",
wd, 0, 0 ); wd, 0, 0 );
...@@ -572,7 +607,7 @@ slapd_daemon_task( ...@@ -572,7 +607,7 @@ slapd_daemon_task(
for ( i = 0; i < nfds; i++ ) for ( i = 0; i < nfds; i++ )
#endif #endif
{ {
int rd, active; int rd;
#ifdef HAVE_WINSOCK #ifdef HAVE_WINSOCK
rd = readfds.fd_array[i]; rd = readfds.fd_array[i];
...@@ -590,7 +625,6 @@ slapd_daemon_task( ...@@ -590,7 +625,6 @@ slapd_daemon_task(
Debug ( LDAP_DEBUG_CONNS, Debug ( LDAP_DEBUG_CONNS,
"daemon: read activity on %d\n", rd, 0, 0 ); "daemon: read activity on %d\n", rd, 0, 0 );
/* /*
* NOTE: it is possible that the connection was closed * NOTE: it is possible that the connection was closed
* and that the stream is now inactive. * and that the stream is now inactive.
...@@ -607,13 +641,13 @@ slapd_daemon_task( ...@@ -607,13 +641,13 @@ slapd_daemon_task(
if( slapd_shutdown > 0 ) { if( slapd_shutdown > 0 ) {
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_TRACE,
"daemon: shutdown requested (%d) and initiated.\n", "daemon: shutdown requested and initiated.\n",
(int) slapd_shutdown, 0, 0 ); 0, 0, 0 );
} else if ( slapd_shutdown < 0 ) { } else if ( slapd_shutdown < 0 ) {
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_TRACE,
"daemon: abnormal condition (%d), shutdown initiated.\n", "daemon: abnormal condition, shutdown initiated.\n",
(int) slapd_shutdown, 0, 0 ); 0, 0, 0 );
} else { } else {
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_TRACE,
"daemon: no active streams, shutdown initiated.\n", "daemon: no active streams, shutdown initiated.\n",
...@@ -624,9 +658,6 @@ slapd_daemon_task( ...@@ -624,9 +658,6 @@ slapd_daemon_task(
slapd_close( tcps ); slapd_close( tcps );
} }
/* we only implement "quick" shutdown */
connections_shutdown();
ldap_pvt_thread_mutex_lock( &active_threads_mutex ); ldap_pvt_thread_mutex_lock( &active_threads_mutex );
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"slapd shutdown: waiting for %d threads to terminate\n", "slapd shutdown: waiting for %d threads to terminate\n",
...@@ -636,10 +667,10 @@ slapd_daemon_task( ...@@ -636,10 +667,10 @@ slapd_daemon_task(
} }
ldap_pvt_thread_mutex_unlock( &active_threads_mutex ); ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
slapd_listener = 0;
return NULL; return NULL;
} }
int slapd_daemon( int inetd, int tcps ) int slapd_daemon( int inetd, int tcps )
{ {
int rc; int rc;
...@@ -717,25 +748,27 @@ void sockinit() ...@@ -717,25 +748,27 @@ void sockinit()
daemon_initialized = 1; daemon_initialized = 1;
} /* The WinSock DLL is acceptable. Proceed. */ } /* The WinSock DLL is acceptable. Proceed. */
void hit_socket( void ) void hit_socket()
{ {
int s, on = 1; int s, on = 1;
extern struct sockaddr_in bind_addr; extern struct sockaddr_in bind_addr;
/* throw something at the socket to terminate the select() in the daemon thread. */ /* throw something at the socket to terminate the select() in the daemon thread. */
if (( s = socket( AF_INET, SOCK_STREAM, 0 )) == INVALID_SOCKET ) if (( s = socket( AF_INET, SOCK_STREAM, 0 )) == INVALID_SOCKET )
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_ANY,
"slap_set_shutdown: socket failed\n\tWSAGetLastError=%d (%s)\n", "slap_set_shutdown: socket failed\n\tWSAGetLastError=%d (%s)\n",
WSAGetLastError(), WSAGetLastErrorString(), 0 ); WSAGetLastError(), WSAGetLastErrorString(), 0 );
if ( ioctlsocket( s, FIONBIO, &on ) == -1 ) if ( ioctlsocket( s, FIONBIO, &on ) == -1 )
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_ANY,
"slap_set_shutdown:FIONBIO ioctl on %d faled\n\tWSAGetLastError=%d (%s)\n", "slap_set_shutdown:FIONBIO ioctl on %d faled\n\tWSAGetLastError=%d (%s)\n",
s, WSAGetLastError(), WSAGetLastError() ); s, WSAGetLastError(), WSAGetLastError() );
bind_addr.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); bind_addr.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
if ( connect( s, (struct sockaddr *)&bind_addr, sizeof( struct sockaddr_in )) == SOCKET_ERROR ) { if ( connect( s, (struct sockaddr *)&bind_addr, sizeof( struct sockaddr_in )) == SOCKET_ERROR ) {
Debug( LDAP_DEBUG_ANY,
"hit_socket: error on connect: %d\n", WSAGetLastError(), 0 );
/* we can probably expect some error to occur here, mostly WSAEWOULDBLOCK */ /* we can probably expect some error to occur here, mostly WSAEWOULDBLOCK */
} }
...@@ -767,7 +800,11 @@ slap_set_shutdown( int sig ) ...@@ -767,7 +800,11 @@ slap_set_shutdown( int sig )
ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 ); ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );
} }
#else #else
hit_socket(); Debug( LDAP_DEBUG_TRACE, "Shutdown %d ordered", sig, 0 );
// trying to "hit" the socket seems to always get a
// EWOULDBLOCK error, so just close the listen socket to
// break out of the select since we're shutting down anyway
tcp_close( tcps );
#endif #endif
/* reinstall self */ /* reinstall self */
(void) SIGNAL( sig, slap_set_shutdown ); (void) SIGNAL( sig, slap_set_shutdown );
......
...@@ -13,12 +13,44 @@ ...@@ -13,12 +13,44 @@
#include "ldapconfig.h" #include "ldapconfig.h"
#include "slap.h" #include "slap.h"
#ifndef HAVE_WINSOCK
#include "lutil.h" /* Get lutil_detach() */ #include "lutil.h" /* Get lutil_detach() */
#endif
#ifdef LDAP_SIGCHLD #ifdef LDAP_SIGCHLD
static RETSIGTYPE wait4child( int sig ); static RETSIGTYPE wait4child( int sig );
#endif #endif
#ifdef HAVE_WINSOCK
#define SERVICE_NAME "OpenLDAP"
struct sockaddr_in bind_addr;
// in nt_main.c
extern SERVICE_STATUS SLAPDServiceStatus;
extern SERVICE_STATUS_HANDLE hSLAPDServiceStatus;
extern ldap_pvt_thread_cond_t started_event, stopped_event;
extern int is_NT_Service;
void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, short port, int udp );
void LogSlapdStoppedEvent( char *svc );
void CommenceStartupProcessing( LPCTSTR serviceName,
void(*stopper)(int));
void ReportSlapdShutdownComplete( void );
void *getRegParam( char *svc, char *value );
#define SERVICE_EXIT( e, n ) \
if ( is_NT_Service ) \
{ \
SLAPDServiceStatus.dwWin32ExitCode = e; \
SLAPDServiceStatus.dwServiceSpecificExitCode = n; \
}
#else
#define SERVICE_EXIT( e, n )
#endif
short port = LDAP_PORT;
/* /*
* when more than one slapd is running on one machine, each one might have * when more than one slapd is running on one machine, each one might have
* it's own LOCAL for syslogging and must have its own pid/args files * it's own LOCAL for syslogging and must have its own pid/args files
...@@ -62,7 +94,7 @@ static void ...@@ -62,7 +94,7 @@ static void
usage( char *name ) usage( char *name )
{ {
fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]", name ); fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]", name );
fprintf( stderr, "\n [-a bind-address] [-i]" ); fprintf( stderr, "\n [-a bind-address] [-i] [-u]" );
#if LDAP_CONNECTIONLESS #if LDAP_CONNECTIONLESS
fprintf( stderr, " [-c]" ); fprintf( stderr, " [-c]" );
#endif #endif
...@@ -80,39 +112,73 @@ usage( char *name ) ...@@ -80,39 +112,73 @@ usage( char *name )
time_t starttime; time_t starttime;
struct sockaddr_in bind_addr; struct sockaddr_in bind_addr;
int tcps;
int #ifdef HAVE_WINSOCK
main( int argc, char **argv ) void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
{ {
#else
void main( int argc, char **argv )
{
#endif
int i; int i;
int inetd = 0; int inetd = 0;
int rc; int rc;
int tcps; struct sockaddr_in *slapd_addr;
#ifdef LDAP_CONNECTIONLESS
int udp; int udp;
#endif
#ifdef LOG_LOCAL4 #ifdef LOG_LOCAL4
int syslogUser = DEFAULT_SYSLOG_USER; int syslogUser = DEFAULT_SYSLOG_USER;
#endif #endif
#if defined(HAVE_SETUID) && defined(HAVE_SETGID) #ifdef HAVE_WINSOCK
char *username = NULL, *groupname = NULL; char *configfile = ".\\slapd.conf";
#else
char *configfile = SLAPD_DEFAULT_CONFIGFILE;
#endif #endif
char *configfile;
char *serverName; char *serverName;
int serverMode = SLAP_SERVER_MODE; int serverMode = SLAP_SERVER_MODE;
configfile = SLAPD_DEFAULT_CONFIGFILE;
(void) memset( (void*) &bind_addr, '\0', sizeof(bind_addr)); (void) memset( (void*) &bind_addr, '\0', sizeof(bind_addr));
bind_addr.sin_family = AF_INET; bind_addr.sin_family = AF_INET;
bind_addr.sin_addr.s_addr = htonl(INADDR_ANY); bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
bind_addr.sin_port = htons(LDAP_PORT); bind_addr.sin_port = htons(port);
g_argc = argc; g_argc = argc;
g_argv = argv; g_argv = argv;
#ifdef HAVE_WINSOCK
//if ( is_NT_Service )
{
int *newPort;
int *newDebugLevel;
char *newConfigFile;
ldap_debug = 0xffff;
if ( is_NT_Service ) CommenceStartupProcessing( SERVICE_NAME, slap_set_shutdown );
newPort = (int*)getRegParam( NULL, "Port" );
if ( newPort != NULL )
{
port = *newPort;
bind_addr.sin_port = htons(port);
Debug ( LDAP_DEBUG_ANY, "new port from registry is: %d\n", port, 0, 0 );
}
newDebugLevel = (int*)getRegParam( NULL, "DebugLevel" );
if ( newDebugLevel != NULL )
{
slap_debug = *newDebugLevel;
Debug( LDAP_DEBUG_ANY, "new debug level from registry is: %d\n", slap_debug, 0, 0 );
}
newConfigFile = (char*)getRegParam( NULL, "ConfigFile" );
if ( newConfigFile != NULL )
{
configfile = newConfigFile;
Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
}
}
#endif
while ( (i = getopt( argc, argv, while ( (i = getopt( argc, argv,
"d:f:ia:p:s:" "d:f:ia:p:s:u"
#ifdef LOG_LOCAL4 #ifdef LOG_LOCAL4
"l:" "l:"
#endif #endif
...@@ -189,7 +255,7 @@ main( int argc, char **argv ) ...@@ -189,7 +255,7 @@ main( int argc, char **argv )
break; break;
case 'p': { /* port on which to listen */ case 'p': { /* port on which to listen */
short port = (short)atoi( optarg ); port = (short)atoi( optarg );
if(! port ) { if(! port ) {
fprintf(stderr, "-p %s must be numeric\n", optarg); fprintf(stderr, "-p %s must be numeric\n", optarg);
} else { } else {
...@@ -234,7 +300,9 @@ main( int argc, char **argv ) ...@@ -234,7 +300,9 @@ main( int argc, char **argv )
default: default:
usage( argv[0] ); usage( argv[0] );
exit( 1 ); rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
goto stop;
} }
} }
...@@ -256,8 +324,6 @@ main( int argc, char **argv ) ...@@ -256,8 +324,6 @@ main( int argc, char **argv )
openlog( serverName, OPENLOG_OPTIONS ); openlog( serverName, OPENLOG_OPTIONS );
#endif #endif
tcps = set_socket( inetd ? NULL : &bind_addr );
#if defined(HAVE_SETUID) && defined(HAVE_SETGID) #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
if ( username != NULL || groupname != NULL ) if ( username != NULL || groupname != NULL )
slap_init_user( username, groupname ); slap_init_user( username, groupname );
...@@ -265,14 +331,19 @@ main( int argc, char **argv ) ...@@ -265,14 +331,19 @@ main( int argc, char **argv )
if ( slap_init( serverMode, serverName ) != 0 ) { if ( slap_init( serverMode, serverName ) != 0 ) {
rc = 1; rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
goto destroy; goto destroy;
} }
if ( read_config( configfile ) != 0 ) { if ( read_config( configfile ) != 0 ) {
rc = 1; rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
goto destroy; goto destroy;
} }
tcps = set_socket( inetd ? NULL : &bind_addr );
(void) SIGNAL( LDAP_SIGUSR1, slap_do_nothing ); (void) SIGNAL( LDAP_SIGUSR1, slap_do_nothing );
(void) SIGNAL( LDAP_SIGUSR2, slap_set_shutdown ); (void) SIGNAL( LDAP_SIGUSR2, slap_set_shutdown );
#ifdef SIGPIPE #ifdef SIGPIPE
...@@ -286,8 +357,12 @@ main( int argc, char **argv ) ...@@ -286,8 +357,12 @@ main( int argc, char **argv )
#ifdef LDAP_SIGCHLD #ifdef LDAP_SIGCHLD
(void) SIGNAL( LDAP_SIGCHLD, wait4child ); (void) SIGNAL( LDAP_SIGCHLD, wait4child );
#endif #endif
#ifdef HAVE_WINSOCK
// SIGBREAK is generated when Ctrl-Break is pressed.
(void) SIGNAL( SIGBREAK, slap_set_shutdown );
#endif
#ifndef WIN32 #ifndef HAVE_WINSOCK
if(!inetd) { if(!inetd) {
#ifdef LDAP_DEBUG #ifdef LDAP_DEBUG
lutil_detach( ldap_debug, 0 ); lutil_detach( ldap_debug, 0 );
...@@ -295,16 +370,19 @@ main( int argc, char **argv ) ...@@ -295,16 +370,19 @@ main( int argc, char **argv )
lutil_detach( 0, 0 ); lutil_detach( 0, 0 );
#endif #endif
} }
#endif /* WIN32 */ #endif /* HAVE_WINSOC */
if ( slap_startup(-1) != 0 ) { if ( slap_startup(-1) != 0 ) {
rc = 1; rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
goto shutdown; goto shutdown;
} }
if(!inetd) { if(!inetd) {
FILE *fp; FILE *fp;
slapd_addr = &bind_addr;
Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 ); Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
if (( slapd_pid_file != NULL ) && if (( slapd_pid_file != NULL ) &&
...@@ -323,11 +401,23 @@ main( int argc, char **argv ) ...@@ -323,11 +401,23 @@ main( int argc, char **argv )
fprintf( fp, "\n" ); fprintf( fp, "\n" );
fclose( fp ); fclose( fp );
} }
} else {
slapd_addr = NULL;
} }
time( &starttime ); time( &starttime );
#ifdef HAVE_WINSOCK
LogSlapdStartedEvent( SERVICE_NAME, slap_debug, configfile, port, udp );
#endif
rc = slapd_daemon( slapd_addr, tcps );
#ifdef HAVE_WINSOCK
// Throw away the event that we used during the startup process.
if ( is_NT_Service )
ldap_pvt_thread_cond_destroy( &started_event );
#endif
rc = slapd_daemon( inetd, tcps );
shutdown: shutdown:
/* remember an error during shutdown */ /* remember an error during shutdown */
...@@ -336,11 +426,18 @@ destroy: ...@@ -336,11 +426,18 @@ destroy:
/* remember an error during destroy */ /* remember an error during destroy */
rc |= slap_destroy(); rc |= slap_destroy();
stop:
#ifdef HAVE_WINSOCK
LogSlapdStoppedEvent( SERVICE_NAME );
#endif
Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 ); Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
#ifdef HAVE_WINSOCK
ReportSlapdShutdownComplete();
#endif
closelog(); closelog();
return rc; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment