svn commit: samba r17177 - in branches/SAMBA_3_0/source: include locking rpc_server utils web

vlendec at samba.org vlendec at samba.org
Fri Jul 21 14:13:30 GMT 2006


Author: vlendec
Date: 2006-07-21 14:13:30 +0000 (Fri, 21 Jul 2006)
New Revision: 17177

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17177

Log:
Get rid of a global variable by adding a private data pointer to
share_mode_forall().

Volker

Modified:
   branches/SAMBA_3_0/source/include/locking.h
   branches/SAMBA_3_0/source/locking/locking.c
   branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c
   branches/SAMBA_3_0/source/utils/status.c
   branches/SAMBA_3_0/source/web/statuspage.c


Changeset:
Modified: branches/SAMBA_3_0/source/include/locking.h
===================================================================
--- branches/SAMBA_3_0/source/include/locking.h	2006-07-21 10:34:10 UTC (rev 17176)
+++ branches/SAMBA_3_0/source/include/locking.h	2006-07-21 14:13:30 UTC (rev 17177)
@@ -67,12 +67,6 @@
 				 enum brl_flavour lock_flav, \
 				 br_off start, br_off size)
 
-#define LOCKING_FN_CAST() \
-	void (*)(struct share_mode_entry *, const char *, const char *)
-
-#define LOCKING_FN(fn) \
-	void (*fn)(struct share_mode_entry *, const char *, const char *)
-
 /* Internal structure in brlock.tdb. 
    The data in brlock records is an unsorted linear array of these
    records.  It is unnecessary to store the count as tdb provides the

Modified: branches/SAMBA_3_0/source/locking/locking.c
===================================================================
--- branches/SAMBA_3_0/source/locking/locking.c	2006-07-21 10:34:10 UTC (rev 17176)
+++ branches/SAMBA_3_0/source/locking/locking.c	2006-07-21 14:13:30 UTC (rev 17177)
@@ -1249,15 +1249,23 @@
 	return True;
 }
 
+struct forall_state {
+	void (*fn)(const struct share_mode_entry *entry,
+		   const char *sharepath,
+		   const char *fname,
+		   void *private_data);
+	void *private_data;
+};
+
 static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, 
-                       void *state)
+                       void *_state)
 {
+	struct forall_state *state = (struct forall_state *)_state;
 	struct locking_data *data;
 	struct share_mode_entry *shares;
 	const char *sharepath;
 	const char *fname;
 	int i;
-	LOCKING_FN(traverse_callback) = (LOCKING_FN_CAST())state;
 
 	/* Ensure this is a locking_key record. */
 	if (kbuf.dsize != sizeof(struct locking_key))
@@ -1274,7 +1282,8 @@
 		strlen(sharepath) + 1;
 
 	for (i=0;i<data->u.s.num_share_mode_entries;i++) {
-		traverse_callback(&shares[i], sharepath, fname);
+		state->fn(&shares[i], sharepath, fname,
+			  state->private_data);
 	}
 	return 0;
 }
@@ -1284,9 +1293,17 @@
  share mode system.
 ********************************************************************/
 
-int share_mode_forall(void (*fn)(const struct share_mode_entry *, const char *, const char *))
+int share_mode_forall(void (*fn)(const struct share_mode_entry *, const char *,
+				 const char *, void *),
+		      void *private_data)
 {
+	struct forall_state state;
+
 	if (tdb == NULL)
 		return 0;
-	return tdb_traverse(tdb, traverse_fn, (void *)fn);
+
+	state.fn = fn;
+	state.private_data = private_data;
+
+	return tdb_traverse(tdb, traverse_fn, (void *)&state);
 }

Modified: branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c
===================================================================
--- branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c	2006-07-21 10:34:10 UTC (rev 17176)
+++ branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c	2006-07-21 14:13:30 UTC (rev 17177)
@@ -123,7 +123,8 @@
 static struct file_enum_count f_enum_cnt;
 
 static void enum_file_fn( const struct share_mode_entry *e, 
-                          const char *sharepath, const char *fname )
+                          const char *sharepath, const char *fname,
+			  void *dummy )
 {
 	struct file_enum_count *fenum = &f_enum_cnt;
  
@@ -191,7 +192,7 @@
 	f_enum_cnt.count = *count;
 	f_enum_cnt.info = *info;
 	
-	share_mode_forall( enum_file_fn );
+	share_mode_forall( enum_file_fn, NULL );
 	
 	*info  = f_enum_cnt.info;
 	*count = f_enum_cnt.count;
@@ -802,13 +803,11 @@
 /*******************************************************************
 ********************************************************************/
 
-/* global needed to make use of the share_mode_forall() callback */
-static struct sess_file_count s_file_cnt;
-
 static void sess_file_fn( const struct share_mode_entry *e, 
-                          const char *sharepath, const char *fname )
+                          const char *sharepath, const char *fname,
+			  void *private_data )
 {
-	struct sess_file_count *sess = &s_file_cnt;
+	struct sess_file_count *sess = (struct sess_file_count *)private_data;
  
 	if ( (procid_to_pid(&e->pid) == sess->pid) && (sess->uid == e->uid) ) {
 		sess->count++;
@@ -822,11 +821,13 @@
 
 static int net_count_files( uid_t uid, pid_t pid )
 {
+	struct sess_file_count s_file_cnt;
+
 	s_file_cnt.count = 0;
 	s_file_cnt.uid = uid;
 	s_file_cnt.pid = pid;
 	
-	share_mode_forall( sess_file_fn );
+	share_mode_forall( sess_file_fn, (void *)&s_file_cnt );
 	
 	return s_file_cnt.count;
 }

Modified: branches/SAMBA_3_0/source/utils/status.c
===================================================================
--- branches/SAMBA_3_0/source/utils/status.c	2006-07-21 10:34:10 UTC (rev 17176)
+++ branches/SAMBA_3_0/source/utils/status.c	2006-07-21 14:13:30 UTC (rev 17177)
@@ -101,7 +101,10 @@
 	return True;
 }
 
-static void print_share_mode(const struct share_mode_entry *e, const char *sharepath, const char *fname)
+static void print_share_mode(const struct share_mode_entry *e,
+			     const char *sharepath,
+			     const char *fname,
+			     void *dummy)
 {
 	static int count;
 
@@ -369,7 +372,7 @@
 			exit(1);
 		}
 		
-		ret = share_mode_forall(print_share_mode);
+		ret = share_mode_forall(print_share_mode, NULL);
 
 		if (ret == 0) {
 			d_printf("No locked files\n");

Modified: branches/SAMBA_3_0/source/web/statuspage.c
===================================================================
--- branches/SAMBA_3_0/source/web/statuspage.c	2006-07-21 10:34:10 UTC (rev 17176)
+++ branches/SAMBA_3_0/source/web/statuspage.c	2006-07-21 14:13:30 UTC (rev 17177)
@@ -106,7 +106,10 @@
 	return buf;
 }
 
-static void print_share_mode(const struct share_mode_entry *e, const char *sharepath, const char *fname)
+static void print_share_mode(const struct share_mode_entry *e,
+			     const char *sharepath,
+			     const char *fname,
+			     void *dummy)
 {
 	char           *utf8_fname;
 	int deny_mode;
@@ -434,7 +437,7 @@
 	printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", _("PID"), _("Sharing"), _("R/W"), _("Oplock"), _("File"), _("Date"));
 
 	locking_init(1);
-	share_mode_forall(print_share_mode);
+	share_mode_forall(print_share_mode, NULL);
 	locking_end();
 	printf("</table>\n");
 



More information about the samba-cvs mailing list