summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2003-05-06 17:52:11 +0000
committerJelmer Vernooij <jelmer@samba.org>2003-05-06 17:52:11 +0000
commit078e66c8d24f4ad92d523e75db72618f68ec7e24 (patch)
tree1ca23402cc81c5dc17e48f6b42089c572d9f553f /source3/lib
parente4719169747ef03bbd4e7835d099e7901b65c29d (diff)
downloadsamba-078e66c8d24f4ad92d523e75db72618f68ec7e24.tar.gz
samba-078e66c8d24f4ad92d523e75db72618f68ec7e24.tar.bz2
samba-078e66c8d24f4ad92d523e75db72618f68ec7e24.zip
Add metze's exit and idle event patch
(This used to be commit e599eba851db40816c684da2b7b1be4b978166e0)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/module.c107
1 files changed, 106 insertions, 1 deletions
diff --git a/source3/lib/module.c b/source3/lib/module.c
index 087c964d3c..221538fbec 100644
--- a/source3/lib/module.c
+++ b/source3/lib/module.c
@@ -2,7 +2,8 @@
Unix SMB/CIFS implementation.
module loading system
- Copyright (C) Jelmer Vernooij 2002
+ Copyright (C) Jelmer Vernooij 2002-2003
+ Copyright (C) Stefan (metze) Metzmacher 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -145,3 +146,107 @@ void module_path_get_name(const char *path, pstring name)
}
}
}
+
+
+/***************************************************************************
+ * This Function registers a idle event
+ *
+ * the registered funtions are run periodically
+ * and maybe shutdown idle connections (e.g. to an LDAP server)
+ ***************************************************************************/
+static smb_idle_event_struct *smb_idle_event_list = NULL;
+NTSTATUS smb_register_idle_event(smb_idle_event_struct *idle_event)
+{
+ if (!idle_event) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ idle_event->last_run = 0;
+
+ DLIST_ADD(smb_idle_event_list,idle_event);
+
+ return NT_STATUS_OK;
+}
+
+NTSTATUS smb_unregister_idle_event(smb_idle_event_struct *idle_event)
+{
+ if (!idle_event) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ DLIST_REMOVE(smb_idle_event_list,idle_event);
+
+ return NT_STATUS_OK;
+}
+
+void smb_run_idle_events(time_t now)
+{
+ smb_idle_event_struct *tmp_event = smb_idle_event_list;
+
+ while (tmp_event) {
+ time_t interval;
+
+ if (tmp_event->fn) {
+ if (tmp_event->interval >= SMB_IDLE_EVENT_MIN_INTERVAL) {
+ interval = tmp_event->interval;
+ } else {
+ interval = SMB_IDLE_EVENT_DEFAULT_INTERVAL;
+ }
+ if (now >(tmp_event->last_run+interval)) {
+ tmp_event->fn(&tmp_event,now);
+ tmp_event->last_run = now;
+ }
+ }
+
+ tmp_event = tmp_event->next;
+ }
+
+ return;
+}
+
+/***************************************************************************
+ * This Function registers a exit event
+ *
+ * the registered funtions are run on exit()
+ * and maybe shutdown idle connections (e.g. to an LDAP server)
+ ***************************************************************************/
+static smb_exit_event_struct *smb_exit_event_list = NULL;
+NTSTATUS smb_register_exit_event(smb_exit_event_struct *exit_event)
+{
+ if (!exit_event) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ DLIST_ADD(smb_exit_event_list,exit_event);
+
+ return NT_STATUS_OK;
+}
+
+NTSTATUS smb_unregister_exit_event(smb_exit_event_struct *exit_event)
+{
+ if (!exit_event) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ DLIST_REMOVE(smb_exit_event_list,exit_event);
+
+ return NT_STATUS_OK;
+}
+
+void smb_run_exit_events(void)
+{
+ smb_exit_event_struct *tmp_event = smb_exit_event_list;
+
+ while (tmp_event) {
+ if (tmp_event->fn) {
+ tmp_event->fn(&tmp_event);
+ }
+ tmp_event = tmp_event->next;
+ }
+
+ /* run exit_events only once */
+ smb_exit_event_list = NULL;
+
+ return;
+}
+