script/autobuild.py: add support git worktree
[Samba.git] / source3 / lib / tallocmsg.c
blobbc0fa132e327d82226d2ab417c9c9945107e5eb8
1 /*
2 samba -- Unix SMB/CIFS implementation.
3 Copyright (C) 2001, 2002 by Martin Pool
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "includes.h"
20 #include "messages.h"
21 #include "lib/util/talloc_report_printf.h"
22 #ifdef HAVE_MALLINFO
23 #include <malloc.h>
24 #endif /* HAVE_MALLINFO */
26 static bool pool_usage_filter(struct messaging_rec *rec, void *private_data)
28 FILE *f = NULL;
29 int fd;
31 if (rec->msg_type != MSG_REQ_POOL_USAGE) {
32 return false;
35 DBG_DEBUG("Got MSG_REQ_POOL_USAGE\n");
37 if (rec->num_fds != 1) {
38 DBG_DEBUG("Got %"PRIu8" fds, expected one\n", rec->num_fds);
39 return false;
42 fd = dup(rec->fds[0]);
43 if (fd == -1) {
44 DBG_DEBUG("dup(%"PRIi64") failed: %s\n",
45 rec->fds[0],
46 strerror(errno));
47 return false;
50 f = fdopen(fd, "w");
51 if (f == NULL) {
52 DBG_DEBUG("fdopen failed: %s\n", strerror(errno));
53 close(fd);
54 return false;
57 talloc_full_report_printf(NULL, f);
59 fclose(f);
61 * Returning false, means messaging_dispatch_waiters()
62 * won't call messaging_filtered_read_done() and
63 * our messaging_filtered_read_send() stays alive
64 * and will get messages.
66 return false;
69 /**
70 * Register handler for MSG_REQ_POOL_USAGE
71 **/
72 void register_msg_pool_usage(
73 TALLOC_CTX *mem_ctx, struct messaging_context *msg_ctx)
75 struct tevent_req *req = NULL;
77 req = messaging_filtered_read_send(
78 mem_ctx,
79 messaging_tevent_context(msg_ctx),
80 msg_ctx,
81 pool_usage_filter,
82 NULL);
83 if (req == NULL) {
84 DBG_WARNING("messaging_filtered_read_send failed\n");
85 return;
87 DEBUG(2, ("Registered MSG_REQ_POOL_USAGE\n"));