Line data Source code
1 : /*
2 : samba -- Unix SMB/CIFS implementation.
3 : Copyright (C) 2001, 2002 by Martin Pool
4 :
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.
9 :
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.
14 :
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/>.
17 : */
18 :
19 : #include "includes.h"
20 : #include "messages.h"
21 : #include "lib/util/talloc_report_printf.h"
22 :
23 2941 : static bool pool_usage_filter(struct messaging_rec *rec, void *private_data)
24 : {
25 2941 : FILE *f = NULL;
26 : int fd;
27 :
28 2941 : if (rec->msg_type != MSG_REQ_POOL_USAGE) {
29 2941 : return false;
30 : }
31 :
32 0 : DBG_DEBUG("Got MSG_REQ_POOL_USAGE\n");
33 :
34 0 : if (rec->num_fds != 1) {
35 0 : DBG_DEBUG("Got %"PRIu8" fds, expected one\n", rec->num_fds);
36 0 : return false;
37 : }
38 :
39 0 : fd = dup(rec->fds[0]);
40 0 : if (fd == -1) {
41 0 : DBG_DEBUG("dup(%"PRIi64") failed: %s\n",
42 : rec->fds[0],
43 : strerror(errno));
44 0 : return false;
45 : }
46 :
47 0 : f = fdopen(fd, "w");
48 0 : if (f == NULL) {
49 0 : DBG_DEBUG("fdopen failed: %s\n", strerror(errno));
50 0 : close(fd);
51 0 : return false;
52 : }
53 :
54 0 : talloc_full_report_printf(NULL, f);
55 :
56 0 : fclose(f);
57 : /*
58 : * Returning false, means messaging_dispatch_waiters()
59 : * won't call messaging_filtered_read_done() and
60 : * our messaging_filtered_read_send() stays alive
61 : * and will get messages.
62 : */
63 0 : return false;
64 : }
65 :
66 : /**
67 : * Register handler for MSG_REQ_POOL_USAGE
68 : **/
69 6917 : void register_msg_pool_usage(
70 : TALLOC_CTX *mem_ctx, struct messaging_context *msg_ctx)
71 : {
72 6917 : struct tevent_req *req = NULL;
73 :
74 6917 : req = messaging_filtered_read_send(
75 : mem_ctx,
76 : messaging_tevent_context(msg_ctx),
77 : msg_ctx,
78 : pool_usage_filter,
79 : NULL);
80 6917 : if (req == NULL) {
81 0 : DBG_WARNING("messaging_filtered_read_send failed\n");
82 0 : return;
83 : }
84 6917 : DEBUG(2, ("Registered MSG_REQ_POOL_USAGE\n"));
85 : }
|