+#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
+
+shutdown:
+ /* remember an error during shutdown */
+ rc |= slap_shutdown(-1);
+destroy:
+ /* remember an error during destroy */
+ rc |= slap_destroy();
+
+stop:
+#ifdef HAVE_WINSOCK
+ LogSlapdStoppedEvent( NTservice );
+#endif
+
+ Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
+
+#ifdef HAVE_WINSOCK
+ ReportSlapdShutdownComplete();
+#endif
+
+ closelog();
+ slapd_daemon_destroy();
+
+ MAIN_RETURN(rc);
+}
+
+
+#ifdef LDAP_SIGCHLD
+
+/*
+ * Catch and discard terminated child processes, to avoid zombies.
+ */
+
+static RETSIGTYPE
+wait4child( int sig )
+{
+ int save_errno = errno;
+
+#ifdef WNOHANG
+ errno = 0;
+#ifdef HAVE_WAITPID
+ while ( waitpid( (pid_t)-1, NULL, WNOHANG ) >= 0 || errno == EINTR )
+ ; /* NULL */
+#else
+ while ( wait3( NULL, WNOHANG, NULL ) >= 0 || errno == EINTR )
+ ; /* NULL */
+#endif
+#else
+ (void) wait( NULL );
+#endif
+ (void) SIGNAL( sig, wait4child );
+ errno = save_errno;
+}
+
+#endif /* SIGCHLD || SIGCLD */
+
+
+#ifdef LOG_LOCAL4
+
+/*
+ * Convert a string to an integer by means of a dispatcher table
+ * if the string is not in the table return the default
+ */
+
+static int
+cnvt_str2int( char *stringVal, STRDISP_P dispatcher, int defaultVal )
+{
+ int retVal = defaultVal;
+ STRDISP_P disp;
+
+ for (disp = dispatcher; disp->stringVal; disp++) {
+
+ if (!strncasecmp (stringVal, disp->stringVal, disp->abbr)) {
+
+ retVal = disp->intVal;
+ break;
+
+ }
+ }
+
+ return (retVal);