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

ITS#8707 Add systemd service notification support

parent 45fd7f5b
......@@ -196,6 +196,7 @@ TLS_LIBS = @TLS_LIBS@
AUTH_LIBS = @AUTH_LIBS@
ARGON2_LIBS = @ARGON2_LIBS@
SECURITY_LIBS = $(SASL_LIBS) $(TLS_LIBS) $(AUTH_LIBS)
SYSTEMD_LIBS = @SYSTEMD_LIBS@
MODULES_CPPFLAGS = @SLAPD_MODULES_CPPFLAGS@
MODULES_LDFLAGS = @SLAPD_MODULES_LDFLAGS@
......@@ -206,7 +207,7 @@ SLAPD_SQL_LDFLAGS = @SLAPD_SQL_LDFLAGS@
SLAPD_SQL_INCLUDES = @SLAPD_SQL_INCLUDES@
SLAPD_SQL_LIBS = @SLAPD_SQL_LIBS@
SLAPD_LIBS = @SLAPD_LIBS@ @SLAPD_PERL_LDFLAGS@ @SLAPD_SQL_LDFLAGS@ @SLAPD_SQL_LIBS@ @SLAPD_SLP_LIBS@ @SLAPD_GMP_LIBS@
SLAPD_LIBS = @SLAPD_LIBS@ @SLAPD_PERL_LDFLAGS@ @SLAPD_SQL_LDFLAGS@ @SLAPD_SQL_LIBS@ @SLAPD_SLP_LIBS@ @SLAPD_GMP_LIBS@ $(SYSTEMD_LIBS)
LLOADD_LIBS = @BALANCER_LIBS@ $(LEVENT_LIBS)
# Our Defaults
......
......@@ -237,6 +237,8 @@ dnl ----------------------------------------------------------------
dnl General "with" options
OL_ARG_WITH(cyrus_sasl, [AS_HELP_STRING([--with-cyrus-sasl], [with Cyrus SASL support])],
auto, [auto yes no] )
OL_ARG_WITH(systemd, [AS_HELP_STRING([--with-systemd], [with systemd service notification support])],
auto, [auto yes no] )
OL_ARG_WITH(fetch, [AS_HELP_STRING([--with-fetch], [with fetch(3) URL support])],
auto, [auto yes no] )
OL_ARG_WITH(threads,
......@@ -638,6 +640,7 @@ MODULES_LIBS=
SLAPI_LIBS=
LIBSLAPI=
AUTH_LIBS=
SYSTEMD_LIBS=
SLAPD_SLP_LIBS=
SLAPD_GMP_LIBS=
......@@ -2083,6 +2086,40 @@ else
fi
fi
dnl ----------------------------------------------------------------
dnl
dnl Check for systemd (only if we have a server)
dnl
WITH_SYSTEMD=no
ol_link_systemd=no
if test $ol_enable_slapd == no && test $ol_enable_balancer != yes ; then
if test $ol_with_systemd != no ; then
AC_MSG_WARN([servers disabled, ignoring --with-systemd=$ol_with_systemd argument])
ol_with_systemd=no
fi
fi
if test $ol_with_systemd != no ; then
AC_CHECK_HEADERS(systemd/sd-daemon.h)
if test $ac_cv_header_systemd_sd_daemon_h = yes; then
AC_CHECK_LIB(systemd, sd_notify,
[ol_link_systemd="-lsystemd"])
fi
if test $ol_link_systemd = no ; then
if test $ol_with_systemd != auto ; then
AC_MSG_ERROR([Could not locate systemd])
else
AC_MSG_WARN([Could not locate systemd])
AC_MSG_WARN([systemd service notification not supported!])
fi
else
AC_DEFINE(HAVE_SYSTEMD,1,[define if you have systemd])
SYSTEMD_LIBS="$ol_link_systemd"
WITH_SYSTEMD=yes
fi
fi
dnl ----------------------------------------------------------------
dnl Check for entropy sources
if test $cross_compiling != yes && test "$ac_cv_mingw32" != yes ; then
......@@ -3126,6 +3163,7 @@ AC_SUBST(WITH_SASL)
AC_SUBST(WITH_TLS)
AC_SUBST(WITH_MODULES_ENABLED)
AC_SUBST(WITH_ACI_ENABLED)
AC_SUBST(WITH_SYSTEMD)
AC_SUBST(BUILD_THREAD)
AC_SUBST(BUILD_LIBS_DYNAMIC)
AC_SUBST(OL_VERSIONED_SYMBOLS)
......@@ -3213,6 +3251,7 @@ AC_SUBST(SLAPI_LIBS)
AC_SUBST(LIBSLAPI)
AC_SUBST(AUTH_LIBS)
AC_SUBST(ARGON2_LIBS)
AC_SUBST(SYSTEMD_LIBS)
AC_SUBST(SLAPD_SLP_LIBS)
AC_SUBST(SLAPD_GMP_LIBS)
......
......@@ -41,6 +41,10 @@
#include "ldap_rq.h"
#ifdef HAVE_SYSTEMD_SD_DAEMON_H
#include <systemd/sd-daemon.h>
#endif
#ifdef HAVE_POLL
#include <poll.h>
#endif
......@@ -111,6 +115,10 @@ static volatile int waking;
} \
} while (0)
ldap_pvt_thread_mutex_t slapd_init_mutex;
ldap_pvt_thread_cond_t slapd_init_cond;
int slapd_ready = 0;
volatile sig_atomic_t slapd_shutdown = 0;
volatile sig_atomic_t slapd_gentle_shutdown = 0;
volatile sig_atomic_t slapd_abrupt_shutdown = 0;
......@@ -2589,6 +2597,10 @@ slapd_daemon_task(
"daemon: listen(%s, 5) failed errno=%d (%s)\n",
slap_listeners[l]->sl_url.bv_val, err,
sock_errstr(err, ebuf, sizeof(ebuf)) );
ldap_pvt_thread_mutex_lock( &slapd_init_mutex );
slapd_shutdown = 2;
ldap_pvt_thread_cond_signal( &slapd_init_cond );
ldap_pvt_thread_mutex_unlock( &slapd_init_mutex );
return (void*)-1;
}
......@@ -2596,13 +2608,21 @@ slapd_daemon_task(
if ( ber_pvt_socket_set_nonblock( SLAP_FD2SOCK( slap_listeners[l]->sl_sd ), 1 ) < 0 ) {
Debug( LDAP_DEBUG_ANY, "slapd_daemon_task: "
"set nonblocking on a listening socket failed\n" );
ldap_pvt_thread_mutex_lock( &slapd_init_mutex );
slapd_shutdown = 2;
ldap_pvt_thread_cond_signal( &slapd_init_cond );
ldap_pvt_thread_mutex_unlock( &slapd_init_mutex );
return (void*)-1;
}
slapd_add( slap_listeners[l]->sl_sd, 0, slap_listeners[l], -1 );
}
ldap_pvt_thread_mutex_lock( &slapd_init_mutex );
slapd_ready = 1;
ldap_pvt_thread_cond_signal( &slapd_init_cond );
ldap_pvt_thread_mutex_unlock( &slapd_init_mutex );
#ifdef HAVE_NT_SERVICE_MANAGER
if ( started_event != NULL ) {
ldap_pvt_thread_cond_signal( &started_event );
......@@ -3313,6 +3333,26 @@ slapd_daemon( void )
}
}
ldap_pvt_thread_mutex_lock( &slapd_init_mutex );
while ( !slapd_ready && !slapd_shutdown ) {
ldap_pvt_thread_cond_wait( &slapd_init_cond, &slapd_init_mutex );
}
ldap_pvt_thread_mutex_unlock( &slapd_init_mutex );
if ( slapd_shutdown ) {
Debug( LDAP_DEBUG_ANY,
"listener initialization failed\n" );
return 1;
}
#ifdef HAVE_SYSTEMD
rc = sd_notify( 1, "READY=1" );
if ( rc < 0 ) {
Debug( LDAP_DEBUG_ANY,
"systemd sd_notify failed (%d)\n", rc );
}
#endif /* HAVE_SYSTEMD */
/* wait for the listener threads to complete */
for ( i=0; i<slapd_daemon_threads; i++ )
ldap_pvt_thread_join( slap_daemon[i].sd_tid, (void *)NULL );
......
......@@ -89,6 +89,9 @@ slap_init( int mode, const char *name )
slap_op_init();
ldap_pvt_thread_mutex_init( &slapd_init_cond );
ldap_pvt_thread_cond_init( &slapd_init_cond );
#ifdef SLAPD_MODULES
if ( module_init() != 0 ) {
slap_debug |= LDAP_DEBUG_NONE;
......@@ -276,6 +279,9 @@ int slap_destroy(void)
}
ldap_pvt_thread_mutex_destroy( &slapd_init_cond );
ldap_pvt_thread_cond_destroy( &slapd_init_cond );
slap_op_destroy();
ldap_pvt_thread_destroy();
......
......@@ -928,6 +928,9 @@ LDAP_SLAPD_V (SOCKET *) slapd_ws_sockets;
#define SLAP_SOCKNEW(s) s
#endif
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) slapd_init_mutex;
LDAP_SLAPD_V (ldap_pvt_thread_cond_t) slapd_init_cond;
/*
* dn.c
*/
......
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