From: Ondřej Kuzník Date: Wed, 7 Apr 2021 14:49:19 +0000 (+0100) Subject: ITS#8707 systemd notifications from lloadd X-Git-Tag: OPENLDAP_REL_ENG_2_5_4~7^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72caa56a8ce804bc5983c1cd1435f046e04241f4;p=thirdparty%2Fopenldap.git ITS#8707 systemd notifications from lloadd --- diff --git a/servers/lloadd/Makefile_server.in b/servers/lloadd/Makefile_server.in index 2e01aa512e..f942916244 100644 --- a/servers/lloadd/Makefile_server.in +++ b/servers/lloadd/Makefile_server.in @@ -33,7 +33,7 @@ all-local-srv: $(PROGRAMS) all-cffiles # $(LTHREAD_LIBS) must be last! XLIBS = $(LLOADD_L) -XXLIBS = $(LLOADD_LIBS) $(SECURITY_LIBS) $(LUTIL_LIBS) +XXLIBS = $(LLOADD_LIBS) $(SECURITY_LIBS) $(LUTIL_LIBS) $(SYSTEMD_LIBS) XXXLIBS = $(LTHREAD_LIBS) NT_DEPENDS = slapd.exp diff --git a/servers/lloadd/daemon.c b/servers/lloadd/daemon.c index 20993b0637..3ddee5dee4 100644 --- a/servers/lloadd/daemon.c +++ b/servers/lloadd/daemon.c @@ -45,6 +45,10 @@ #include "ldap_rq.h" +#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#include +#endif + #ifdef LDAP_PF_LOCAL #include /* this should go in as soon as it is accepted */ @@ -1303,7 +1307,18 @@ lloadd_daemon( struct event_base *daemon_base ) event_add( event, lload_timeout_api ); } + checked_lock( &lload_wait_mutex ); lloadd_inited = 1; + ldap_pvt_thread_cond_signal( &lload_wait_cond ); + checked_unlock( &lload_wait_mutex ); +#if !defined(BALANCER_MODULE) && defined(HAVE_SYSTEMD) + rc = sd_notify( 1, "READY=1" ); + if ( rc < 0 ) { + Debug( LDAP_DEBUG_ANY, "lloadd startup: " + "systemd sd_notify failed (%d)\n", rc ); + } +#endif /* !BALANCER_MODULE && HAVE_SYSTEMD */ + rc = event_base_dispatch( daemon_base ); Debug( LDAP_DEBUG_ANY, "lloadd shutdown: " "Main event loop finished: rc=%d\n", @@ -1361,7 +1376,9 @@ lloadd_daemon( struct event_base *daemon_base ) /* If we're a slapd module, let the thread that initiated the shut down * know we've finished */ + checked_lock( &lload_wait_mutex ); ldap_pvt_thread_cond_signal( &lload_wait_cond ); + checked_unlock( &lload_wait_mutex ); return 0; } diff --git a/servers/lloadd/module_init.c b/servers/lloadd/module_init.c index 0a30d18827..61b1b351ee 100644 --- a/servers/lloadd/module_init.c +++ b/servers/lloadd/module_init.c @@ -53,10 +53,17 @@ lload_start_daemon( void *arg ) Debug( LDAP_DEBUG_ANY, "lload_start_daemon: " "main event base allocation failed\n" ); rc = 1; - return (void *)(uintptr_t)rc; + goto done; } rc = lloadd_daemon( daemon_base ); +done: + if ( rc != LDAP_SUCCESS ) { + assert( lloadd_inited == 0 ); + checked_lock( &lload_wait_mutex ); + ldap_pvt_thread_cond_signal( &lload_wait_cond ); + checked_unlock( &lload_wait_mutex ); + } return (void *)(uintptr_t)rc; } @@ -81,6 +88,8 @@ lload_unpause_cb( BackendInfo *bi ) int lload_back_open( BackendInfo *bi ) { + int rc = 0; + if ( slapMode & SLAP_TOOL_MODE ) { return 0; } @@ -99,8 +108,18 @@ lload_back_open( BackendInfo *bi ) assert( lloadd_get_listeners() ); - return ldap_pvt_thread_create( - &lloadd_main_thread, 0, lload_start_daemon, NULL ); + checked_lock( &lload_wait_mutex ); + rc = ldap_pvt_thread_create( &lloadd_main_thread, + 0, lload_start_daemon, NULL ); + if ( !rc ) { + ldap_pvt_thread_cond_wait( &lload_wait_cond, &lload_wait_mutex ); + if ( lloadd_inited != 1 ) { + ldap_pvt_thread_join( lloadd_main_thread, (void *)NULL ); + rc = -1; + } + } + checked_unlock( &lload_wait_mutex ); + return rc; } int @@ -110,6 +129,8 @@ lload_back_close( BackendInfo *bi ) return 0; } + assert( lloadd_inited == 1 ); + checked_lock( &lload_wait_mutex ); event_base_loopexit( daemon_base, NULL ); ldap_pvt_thread_cond_wait( &lload_wait_cond, &lload_wait_mutex );