1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

r19645: don't pass NULL as mem_ctx...

metze
(This used to be commit 643a38bc30)
This commit is contained in:
Stefan Metzmacher 2006-11-09 01:11:45 +00:00 committed by Gerald (Jerry) Carter
parent ed77e4e57b
commit fe2a5a8abf
6 changed files with 38 additions and 33 deletions

View File

@ -28,15 +28,16 @@
/*
broadcast name resolution method - async send
*/
struct composite_context *resolve_name_bcast_send(struct nbt_name *name,
struct event_context *event_ctx)
struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx,
struct event_context *event_ctx,
struct nbt_name *name)
{
int num_interfaces = iface_count();
const char **address_list;
struct composite_context *c;
int i, count=0;
address_list = talloc_array(NULL, const char *, num_interfaces+1);
address_list = talloc_array(mem_ctx, const char *, num_interfaces+1);
if (address_list == NULL) return NULL;
for (i=0;i<num_interfaces;i++) {
@ -51,7 +52,7 @@ struct composite_context *resolve_name_bcast_send(struct nbt_name *name,
}
address_list[count] = NULL;
c = resolve_name_nbtlist_send(name, event_ctx, address_list, True, False);
c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, True, False);
talloc_free(address_list);
return c;
@ -73,7 +74,7 @@ NTSTATUS resolve_name_bcast(struct nbt_name *name,
TALLOC_CTX *mem_ctx,
const char **reply_addr)
{
struct composite_context *c = resolve_name_bcast_send(name, NULL);
struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, name);
return resolve_name_bcast_recv(c, mem_ctx, reply_addr);
}

View File

@ -77,6 +77,7 @@ static void run_child(struct composite_context *c, int fd)
if (address != NULL) {
write(fd, address, strlen(address)+1);
}
close(fd);
}
/*
@ -121,15 +122,16 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde,
/*
gethostbyname name resolution method - async send
*/
struct composite_context *resolve_name_host_send(struct nbt_name *name,
struct event_context *event_ctx)
struct composite_context *resolve_name_host_send(TALLOC_CTX *mem_ctx,
struct event_context *event_ctx,
struct nbt_name *name)
{
struct composite_context *c;
struct host_state *state;
int fd[2] = { -1, -1 };
int ret;
c = composite_create(event_ctx, event_ctx);
c = composite_create(mem_ctx, event_ctx);
if (c == NULL) return NULL;
c->event_ctx = talloc_reference(c, event_ctx);
@ -172,6 +174,7 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name,
return c;
}
if (state->child == 0) {
close(fd[0]);
run_child(c, fd[1]);
@ -189,7 +192,7 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name,
gethostbyname name resolution method - recv side
*/
NTSTATUS resolve_name_host_recv(struct composite_context *c,
TALLOC_CTX *mem_ctx, const char **reply_addr)
TALLOC_CTX *mem_ctx, const char **reply_addr)
{
NTSTATUS status;
@ -211,7 +214,7 @@ NTSTATUS resolve_name_host(struct nbt_name *name,
TALLOC_CTX *mem_ctx,
const char **reply_addr)
{
struct composite_context *c = resolve_name_host_send(name, NULL);
struct composite_context *c = resolve_name_host_send(mem_ctx, NULL, name);
return resolve_name_host_recv(c, mem_ctx, reply_addr);
}

View File

@ -95,11 +95,12 @@ static void nbtlist_handler(struct nbt_name_request *req)
/*
nbtlist name resolution method - async send
*/
struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name,
struct event_context *event_ctx,
const char **address_list,
BOOL broadcast,
BOOL wins_lookup)
struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx,
struct event_context *event_ctx,
struct nbt_name *name,
const char **address_list,
BOOL broadcast,
BOOL wins_lookup)
{
struct composite_context *c;
struct nbtlist_state *state;
@ -186,8 +187,8 @@ NTSTATUS resolve_name_nbtlist(struct nbt_name *name,
BOOL broadcast, BOOL wins_lookup,
const char **reply_addr)
{
struct composite_context *c = resolve_name_nbtlist_send(name, NULL, address_list,
broadcast, wins_lookup);
struct composite_context *c = resolve_name_nbtlist_send(mem_ctx, NULL, name, address_list,
broadcast, wins_lookup);
return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr);
}

View File

@ -38,7 +38,7 @@ static struct composite_context *setup_next_method(struct composite_context *c);
/* pointers to the resolver backends */
static const struct resolve_method {
const char *name;
struct composite_context *(*send_fn)(struct nbt_name *, struct event_context *);
struct composite_context *(*send_fn)(TALLOC_CTX *mem_ctx, struct event_context *, struct nbt_name *);
NTSTATUS (*recv_fn)(struct composite_context *, TALLOC_CTX *, const char **);
} resolve_methods[] = {
@ -101,7 +101,7 @@ static struct composite_context *setup_next_method(struct composite_context *c)
do {
const struct resolve_method *method = find_method(state->methods[0]);
if (method) {
creq = method->send_fn(&state->name, c->event_ctx);
creq = method->send_fn(c, c->event_ctx, &state->name);
}
if (creq == NULL && state->methods[0]) state->methods++;

View File

@ -27,19 +27,20 @@
/*
wins name resolution method - async send
*/
struct composite_context *resolve_name_wins_send(struct nbt_name *name,
struct event_context *event_ctx)
struct composite_context *resolve_name_wins_send(TALLOC_CTX *mem_ctx,
struct event_context *event_ctx,
struct nbt_name *name)
{
const char **address_list = lp_wins_server_list();
if (address_list == NULL) return NULL;
return resolve_name_nbtlist_send(name, event_ctx, address_list, False, True);
return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, False, True);
}
/*
wins name resolution method - recv side
*/
NTSTATUS resolve_name_wins_recv(struct composite_context *c,
TALLOC_CTX *mem_ctx, const char **reply_addr)
TALLOC_CTX *mem_ctx, const char **reply_addr)
{
return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr);
}
@ -51,7 +52,7 @@ NTSTATUS resolve_name_wins(struct nbt_name *name,
TALLOC_CTX *mem_ctx,
const char **reply_addr)
{
struct composite_context *c = resolve_name_wins_send(name, NULL);
struct composite_context *c = resolve_name_wins_send(mem_ctx, NULL, name);
return resolve_name_wins_recv(c, mem_ctx, reply_addr);
}

View File

@ -40,11 +40,11 @@ static bool test_async_resolve(struct torture_context *tctx)
ZERO_STRUCT(n);
n.name = host;
torture_comment(tctx, "Testing async resolve of localhost for %d seconds\n",
timelimit);
torture_comment(tctx, "Testing async resolve of '%s' for %d seconds\n",
host, timelimit);
while (timeval_elapsed(&tv) < timelimit) {
const char *s;
struct composite_context *c = resolve_name_host_send(&n, ev);
struct composite_context *c = resolve_name_host_send(mem_ctx, ev, &n);
torture_assert(tctx, c != NULL, "resolve_name_host_send");
torture_assert_ntstatus_ok(tctx, resolve_name_host_recv(c, mem_ctx, &s),
"async resolve failed");
@ -52,7 +52,7 @@ static bool test_async_resolve(struct torture_context *tctx)
}
torture_comment(tctx, "async rate of %.1f resolves/sec\n",
count/timeval_elapsed(&tv));
count/timeval_elapsed(&tv));
return true;
}
@ -66,23 +66,22 @@ static bool test_sync_resolve(struct torture_context *tctx)
int count = 0;
const char *host = torture_setting_string(tctx, "host", NULL);
torture_comment(tctx, "Testing sync resolve of localhost for %d seconds\n",
timelimit);
torture_comment(tctx, "Testing sync resolve of '%s' for %d seconds\n",
host, timelimit);
while (timeval_elapsed(&tv) < timelimit) {
sys_inet_ntoa(interpret_addr2(host));
count++;
}
torture_comment(tctx, "sync rate of %.1f resolves/sec\n",
count/timeval_elapsed(&tv));
count/timeval_elapsed(&tv));
return true;
}
struct torture_suite *torture_local_resolve(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx,
"RESOLVE");
struct torture_suite *suite = torture_suite_create(mem_ctx, "RESOLVE");
torture_suite_add_simple_test(suite, "async", test_async_resolve);
torture_suite_add_simple_test(suite, "sync", test_sync_resolve);