mirror of
https://github.com/samba-team/samba.git
synced 2025-08-26 01:49:31 +03:00
lib: Simplify register_msg_pool_usage()
We can do as much as we want in the filter. This gives us automatic retry, we don't have to do the messaging_filtered_read_send() over and over again Bug: https://bugzilla.samba.org/show_bug.cgi?id=14281 Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
committed by
Björn Baumbach
parent
4de1e3207b
commit
8a23031b7b
@ -25,6 +25,9 @@
|
|||||||
|
|
||||||
static bool pool_usage_filter(struct messaging_rec *rec, void *private_data)
|
static bool pool_usage_filter(struct messaging_rec *rec, void *private_data)
|
||||||
{
|
{
|
||||||
|
FILE *f = NULL;
|
||||||
|
int fd;
|
||||||
|
|
||||||
if (rec->msg_type != MSG_REQ_POOL_USAGE) {
|
if (rec->msg_type != MSG_REQ_POOL_USAGE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -36,52 +39,31 @@ static bool pool_usage_filter(struct messaging_rec *rec, void *private_data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
fd = dup(rec->fds[0]);
|
||||||
}
|
if (fd == -1) {
|
||||||
|
DBG_DEBUG("dup(%"PRIi64") failed: %s\n",
|
||||||
|
rec->fds[0],
|
||||||
static void msg_pool_usage_do(struct tevent_req *req)
|
strerror(errno));
|
||||||
{
|
return false;
|
||||||
struct messaging_context *msg_ctx = tevent_req_callback_data(
|
|
||||||
req, struct messaging_context);
|
|
||||||
struct messaging_rec *rec = NULL;
|
|
||||||
FILE *f = NULL;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = messaging_filtered_read_recv(req, talloc_tos(), &rec);
|
|
||||||
TALLOC_FREE(req);
|
|
||||||
if (ret != 0) {
|
|
||||||
DBG_DEBUG("messaging_filtered_read_recv returned %s\n",
|
|
||||||
strerror(ret));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f = fdopen(rec->fds[0], "w");
|
f = fdopen(fd, "w");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
close(rec->fds[0]);
|
|
||||||
TALLOC_FREE(rec);
|
|
||||||
DBG_DEBUG("fdopen failed: %s\n", strerror(errno));
|
DBG_DEBUG("fdopen failed: %s\n", strerror(errno));
|
||||||
return;
|
close(fd);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TALLOC_FREE(rec);
|
|
||||||
|
|
||||||
talloc_full_report_printf(NULL, f);
|
talloc_full_report_printf(NULL, f);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
f = NULL;
|
/*
|
||||||
|
* Returning false, means messaging_dispatch_waiters()
|
||||||
req = messaging_filtered_read_send(
|
* won't call messaging_filtered_read_done() and
|
||||||
msg_ctx,
|
* our messaging_filtered_read_send() stays alive
|
||||||
messaging_tevent_context(msg_ctx),
|
* and will get messages.
|
||||||
msg_ctx,
|
*/
|
||||||
pool_usage_filter,
|
return false;
|
||||||
NULL);
|
|
||||||
if (req == NULL) {
|
|
||||||
DBG_WARNING("messaging_filtered_read_send failed\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tevent_req_set_callback(req, msg_pool_usage_do, msg_ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,6 +83,5 @@ void register_msg_pool_usage(struct messaging_context *msg_ctx)
|
|||||||
DBG_WARNING("messaging_filtered_read_send failed\n");
|
DBG_WARNING("messaging_filtered_read_send failed\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tevent_req_set_callback(req, msg_pool_usage_do, msg_ctx);
|
|
||||||
DEBUG(2, ("Registered MSG_REQ_POOL_USAGE\n"));
|
DEBUG(2, ("Registered MSG_REQ_POOL_USAGE\n"));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user