mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
r17177: Get rid of a global variable by adding a private data pointer to
share_mode_forall().
Volker
(This used to be commit f97f6cedff
)
This commit is contained in:
parent
2cc356a525
commit
e0c68d0a1d
@ -67,12 +67,6 @@ struct byte_range_lock {
|
||||
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
|
||||
|
@ -1249,15 +1249,23 @@ BOOL set_delete_on_close(files_struct *fsp, BOOL delete_on_close, UNIX_USER_TOKE
|
||||
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 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf,
|
||||
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 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf,
|
||||
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);
|
||||
}
|
||||
|
@ -123,7 +123,8 @@ static WERROR net_enum_pipes( TALLOC_CTX *ctx, FILE_INFO_3 **info,
|
||||
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 @@ static WERROR net_enum_files( TALLOC_CTX *ctx, FILE_INFO_3 **info,
|
||||
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 @@ static void init_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *sto
|
||||
/*******************************************************************
|
||||
********************************************************************/
|
||||
|
||||
/* 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 void sess_file_fn( const struct share_mode_entry *e,
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -101,7 +101,10 @@ static BOOL Ucrit_addPid( pid_t pid )
|
||||
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 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo
|
||||
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");
|
||||
|
@ -106,7 +106,10 @@ static char *tstring(time_t t)
|
||||
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 @@ void status_page(void)
|
||||
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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user