Commit 72caa56a authored by Ondřej Kuzník's avatar Ondřej Kuzník Committed by Quanah Gibson-Mount
Browse files

ITS#8707 systemd notifications from lloadd

parent 0786f6d5
Pipeline #2571 passed with stage
in 44 minutes and 41 seconds
......@@ -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
......
......@@ -45,6 +45,10 @@
#include "ldap_rq.h"
#ifdef HAVE_SYSTEMD_SD_DAEMON_H
#include <systemd/sd-daemon.h>
#endif
#ifdef LDAP_PF_LOCAL
#include <sys/stat.h>
/* this should go in <ldap.h> 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;
}
......
......@@ -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 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment