[PATCH] add smb_register_*_events()

metze at metzemix.de metze at metzemix.de
Wed Apr 30 13:47:42 GMT 2003


Hi Jelmer,

here're the patches for the smb_register_*_events()

without versioning...

metze
-------------- next part --------------
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache 3_0/source/include/includes.h 3_0-events/source/include/includes.h
--- 3_0/source/include/includes.h	Tue Apr 29 08:39:47 2003
+++ 3_0-events/source/include/includes.h	Tue Apr 29 08:12:24 2003
@@ -802,6 +802,8 @@ extern int errno;
 
 #include "mangle.h"
 
+#include "module.h"
+
 #include "nsswitch/winbind_client.h"
 
 /*
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache 3_0/source/include/module.h 3_0-events/source/include/module.h
--- 3_0/source/include/module.h	Thu Jan  1 01:00:00 1970
+++ 3_0-events/source/include/module.h	Wed Apr 30 14:57:43 2003
@@ -0,0 +1,45 @@
+/*
+   Unix SMB/CIFS implementation.
+   Handling of idle/exit events 
+   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
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef _MODULE_H
+#define _MODULE_H
+
+/* Module support */
+typedef NTSTATUS (init_module_function) (void);
+
+
+#define SMB_IDLE_EVENT_DEFAULT_INTERVAL	180
+#define SMB_IDLE_EVENT_MIN_INTERVAL	30
+
+typedef struct smb_idle_event_struct {
+	struct smb_idle_event_struct *prev,*next;
+	time_t interval;
+	time_t last_run;
+	void *data;
+	void (*fn)(struct smb_idle_event_struct **event, time_t now);
+} smb_idle_event_struct;
+
+typedef struct smb_exit_event_struct {
+	struct smb_exit_event_struct *prev,*next;
+	void *data;
+	void (*fn)(struct smb_exit_event_struct **event);	
+} smb_exit_event_struct;
+
+#endif /* _MODULE_H */
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache 3_0/source/include/smb.h 3_0-events/source/include/smb.h
--- 3_0/source/include/smb.h	Tue Apr 29 08:01:00 2003
+++ 3_0-events/source/include/smb.h	Tue Apr 29 08:36:55 2003
@@ -1735,7 +1735,4 @@ typedef struct {
 
 #include "popt_common.h"
 
-/* Module support */
-typedef NTSTATUS (init_module_function) (void);
-
 #endif /* _SMB_H */
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache 3_0/source/lib/module.c 3_0-events/source/lib/module.c
--- 3_0/source/lib/module.c	Tue Apr 29 08:01:00 2003
+++ 3_0-events/source/lib/module.c	Wed Apr 30 14:55:49 2003
@@ -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,128 @@ void module_path_get_name(const char *pa
 		}
 	}
 }
+
+
+/***************************************************************************
+ * 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)
+{
+	smb_idle_event_struct *tmp_event = smb_idle_event_list;
+
+	if (!idle_event) {
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+	
+	while (tmp_event) {
+		if (tmp_event == idle_event) {
+			DEBUG(0,("idle event allready registerd.\n"));
+			return NT_STATUS_UNSUCCESSFUL;
+		}
+
+		tmp_event = tmp_event->next;
+	}
+
+	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)
+{
+	smb_exit_event_struct *tmp_event = smb_exit_event_list;
+
+	if (!exit_event) {
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+	
+	while (tmp_event) {
+		if (tmp_event == exit_event) {
+			DEBUG(0,("exit_event allready registerd.\n"));
+			return NT_STATUS_UNSUCCESSFUL;
+		}
+		tmp_event = tmp_event->next;
+	}
+
+	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;
+}
+
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache 3_0/source/smbd/process.c 3_0-events/source/smbd/process.c
--- 3_0/source/smbd/process.c	Tue Apr 22 06:46:32 2003
+++ 3_0-events/source/smbd/process.c	Sat Apr 26 14:29:19 2003
@@ -1114,6 +1114,9 @@ static BOOL timeout_processing(int deadt
   /* become root again if waiting */
   change_to_root_user();
 
+  /* run all registered idle events */
+  smb_run_idle_events(t);
+	
   /* check if we need to reload services */
   check_reload(t);
 
@@ -1276,6 +1279,10 @@ void smbd_process(void)
 		/* free up temporary memory */
 		lp_talloc_free();
 		main_loop_talloc_free();
+
+		/* run all registered idle events */
+		smb_run_idle_events(time(NULL));
+	
 
 		/* Did someone ask for immediate checks on things like blocking locks ? */
 		if (select_timeout == 0) {
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache 3_0/source/smbd/server.c 3_0-events/source/smbd/server.c
--- 3_0/source/smbd/server.c	Thu Apr 24 07:01:02 2003
+++ 3_0-events/source/smbd/server.c	Thu Apr 24 22:39:53 2003
@@ -567,6 +567,9 @@ void exit_server(const char *reason)
 
 	print_notify_send_messages(3); /* 3 second timeout. */
 
+	/* run all registered exit events */
+	smb_run_exit_events();
+
 	/* delete our entry in the connections database. */
 	yield_connection(NULL,"");
 
-------------- next part --------------
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache HEAD/source/include/includes.h HEAD-events/source/include/includes.h
--- HEAD/source/include/includes.h	Mon Apr 14 16:28:25 2003
+++ HEAD-events/source/include/includes.h	Thu Apr 24 18:24:09 2003
@@ -808,6 +808,8 @@ extern int errno;
 
 #include "mangle.h"
 
+#include "module.h"
+
 #include "nsswitch/winbind_client.h"
 
 #include "genparser.h"
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache HEAD/source/include/module.h HEAD-events/source/include/module.h
--- HEAD/source/include/module.h	Thu Jan  1 01:00:00 1970
+++ HEAD-events/source/include/module.h	Wed Apr 30 14:58:26 2003
@@ -0,0 +1,45 @@
+/*
+   Unix SMB/CIFS implementation.
+   Handling of idle/exit events 
+   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
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef _MODULE_H
+#define _MODULE_H
+
+/* Module support */
+typedef NTSTATUS (init_module_function) (void);
+
+
+#define SMB_IDLE_EVENT_DEFAULT_INTERVAL	180
+#define SMB_IDLE_EVENT_MIN_INTERVAL	30
+
+typedef struct smb_idle_event_struct {
+	struct smb_idle_event_struct *prev,*next;
+	time_t interval;
+	time_t last_run;
+	void *data;
+	void (*fn)(struct smb_idle_event_struct **event, time_t now);
+} smb_idle_event_struct;
+
+typedef struct smb_exit_event_struct {
+	struct smb_exit_event_struct *prev,*next;
+	void *data;
+	void (*fn)(struct smb_exit_event_struct **event);	
+} smb_exit_event_struct;
+
+#endif /* _MODULE_H */
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache HEAD/source/include/smb.h HEAD-events/source/include/smb.h
--- HEAD/source/include/smb.h	Wed Apr 30 14:59:15 2003
+++ HEAD-events/source/include/smb.h	Wed Apr 30 14:29:10 2003
@@ -1727,7 +1727,4 @@ typedef struct {
 
 #include "popt_common.h"
 
-/* Module support */
-typedef NTSTATUS (init_module_function) (void);
-
 #endif /* _SMB_H */
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache HEAD/source/lib/module.c HEAD-events/source/lib/module.c
--- HEAD/source/lib/module.c	Tue Apr 29 08:01:21 2003
+++ HEAD-events/source/lib/module.c	Wed Apr 30 14:56:00 2003
@@ -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,128 @@ void module_path_get_name(const char *pa
 		}
 	}
 }
+
+
+/***************************************************************************
+ * 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)
+{
+	smb_idle_event_struct *tmp_event = smb_idle_event_list;
+
+	if (!idle_event) {
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+	
+	while (tmp_event) {
+		if (tmp_event == idle_event) {
+			DEBUG(0,("idle event allready registerd.\n"));
+			return NT_STATUS_UNSUCCESSFUL;
+		}
+
+		tmp_event = tmp_event->next;
+	}
+
+	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)
+{
+	smb_exit_event_struct *tmp_event = smb_exit_event_list;
+
+	if (!exit_event) {
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+	
+	while (tmp_event) {
+		if (tmp_event == exit_event) {
+			DEBUG(0,("exit_event allready registerd.\n"));
+			return NT_STATUS_UNSUCCESSFUL;
+		}
+		tmp_event = tmp_event->next;
+	}
+
+	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;
+}
+
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache HEAD/source/smbd/process.c HEAD-events/source/smbd/process.c
--- HEAD/source/smbd/process.c	Wed Apr 16 15:02:40 2003
+++ HEAD-events/source/smbd/process.c	Sat Apr 26 14:31:22 2003
@@ -1114,6 +1114,9 @@ static BOOL timeout_processing(int deadt
   /* become root again if waiting */
   change_to_root_user();
 
+  /* run all registered idle events */
+  smb_run_idle_events(t);
+	
   /* check if we need to reload services */
   check_reload(t);
 
@@ -1276,6 +1279,10 @@ void smbd_process(void)
 		/* free up temporary memory */
 		lp_talloc_free();
 		main_loop_talloc_free();
+
+		/* run all registered idle events */
+		smb_run_idle_events(time(NULL));
+	
 
 		/* Did someone ask for immediate checks on things like blocking locks ? */
 		if (select_timeout == 0) {
diff -Npur --exclude=CVS --exclude=*.bak --exclude=*.o --exclude=*.po --exclude=*.so --exclude=.#* --exclude=Makefile --exclude=stamp-h --exclude=configure --exclude=findsmb --exclude=*proto*.h --exclude=build_env.h --exclude=tdbsam2_parse_info.h --exclude=config.* --exclude=bin --exclude=*.configure --exclude=autom4te.cache HEAD/source/smbd/server.c HEAD-events/source/smbd/server.c
--- HEAD/source/smbd/server.c	Mon Apr 28 07:55:28 2003
+++ HEAD-events/source/smbd/server.c	Mon Apr 28 07:59:22 2003
@@ -567,6 +567,9 @@ void exit_server(const char *reason)
 
 	print_notify_send_messages(3); /* 3 second timeout. */
 
+	/* run all registered exit events */
+	smb_run_exit_events();
+
 	/* delete our entry in the connections database. */
 	yield_connection(NULL,"");
 


More information about the samba-technical mailing list