From c8fd4a203bc16a7cdc18aefc0cfd53b17eb84ae2 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 8 Nov 2004 11:33:53 +0000 Subject: [PATCH] allow creation of subsystems whatever order the databases appear --- servers/slapd/back-monitor/back-monitor.h | 17 +++++++----- servers/slapd/back-monitor/init.c | 33 ++++++++++++++++++++--- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/servers/slapd/back-monitor/back-monitor.h b/servers/slapd/back-monitor/back-monitor.h index 40224c7c57..1554de07c0 100644 --- a/servers/slapd/back-monitor/back-monitor.h +++ b/servers/slapd/back-monitor/back-monitor.h @@ -46,16 +46,18 @@ struct monitorentrypriv { Entry *mp_children; /* pointer to first child */ struct monitorsubsys *mp_info; /* subsystem info */ #define mp_type mp_info->mss_type - int mp_flags; /* flags */ + unsigned long mp_flags; /* flags */ -#define MONITOR_F_NONE 0x00 -#define MONITOR_F_SUB 0x01 /* subentry of subsystem */ -#define MONITOR_F_PERSISTENT 0x10 /* persistent entry */ -#define MONITOR_F_PERSISTENT_CH 0x20 /* subsystem generates +#define MONITOR_F_NONE 0x00U +#define MONITOR_F_SUB 0x01U /* subentry of subsystem */ +#define MONITOR_F_PERSISTENT 0x10U /* persistent entry */ +#define MONITOR_F_PERSISTENT_CH 0x20U /* subsystem generates persistent entries */ -#define MONITOR_F_VOLATILE 0x40 /* volatile entry */ -#define MONITOR_F_VOLATILE_CH 0x80 /* subsystem generates +#define MONITOR_F_VOLATILE 0x40U /* volatile entry */ +#define MONITOR_F_VOLATILE_CH 0x80U /* subsystem generates volatile entries */ +/* NOTE: flags with 0xF0000000U mask are reserved for subsystem internals */ + int (*mp_update)( Operation *op, Entry *e ); /* update callback for user-defined entries */ @@ -221,6 +223,7 @@ typedef struct monitorsubsys { struct berval mss_dn; struct berval mss_ndn; int mss_flags; +#define MONITOR_F_OPENED 0x10000000U #define MONITOR_HAS_VOLATILE_CH( mp ) \ ( ( mp )->mp_flags & MONITOR_F_VOLATILE_CH ) diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index a745898682..dc542090e0 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -36,8 +36,17 @@ */ BackendDB *be_monitor = NULL; +static struct monitorsubsys **monitor_subsys = NULL; +static int monitor_subsys_opened = 0; + /* * subsystem data + * + * the known subsystems are added to the subsystems + * array at backend initialization; other subsystems + * may be added by calling monitor_back_register_subsys() + * before the database is opened (e.g. by other backends + * or by overlays or modules). */ static struct monitorsubsys known_monitor_subsys[] = { { @@ -163,8 +172,6 @@ init_module( int argc, char *argv[] ) #endif /* SLAPD_MONITOR */ -static struct monitorsubsys **monitor_subsys = NULL; - int monitor_back_register_subsys( monitorsubsys *ms ) { @@ -185,6 +192,22 @@ monitor_back_register_subsys( monitorsubsys *ms ) monitor_subsys[ i ] = ms; monitor_subsys[ i + 1 ] = NULL; + /* if a subsystem is registered __AFTER__ subsystem + * initialization (depending on the sequence the databases + * are listed in slapd.conf), init it */ + if ( monitor_subsys_opened ) { + + /* FIXME: this should only be possible + * if be_monitor is already initialized */ + assert( be_monitor ); + + if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) { + return -1; + } + + ms->mss_flags |= MONITOR_F_OPENED; + } + return 0; } @@ -679,7 +702,8 @@ monitor_back_db_open( Entry *e, **ep; struct monitorentrypriv *mp; int i; - char buf[ BACKMONITOR_BUFSIZE ], *end_of_line; + char buf[ BACKMONITOR_BUFSIZE ], + *end_of_line; struct berval bv; struct tm *tms; #ifdef HAVE_GMTIME_R @@ -893,8 +917,11 @@ monitor_back_db_open( { return( -1 ); } + ms[ 0 ]->mss_flags |= MONITOR_F_OPENED; } + monitor_subsys_opened = 1; + return( 0 ); } -- 2.39.5