source: vendor/current/source3/smbd/notifyd/tests.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 2.9 KB
Line 
1/*
2 * Unix SMB/CIFS implementation.
3 *
4 * Copyright (C) Volker Lendecke 2014
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "replace.h"
21#include "notifyd.h"
22#include "messages.h"
23#include "lib/util/server_id_db.h"
24
25int main(int argc, const char *argv[])
26{
27 TALLOC_CTX *frame = talloc_stackframe();
28 struct tevent_context *ev;
29 struct messaging_context *msg_ctx;
30 struct server_id_db *names;
31 struct server_id notifyd;
32 struct tevent_req *req;
33 unsigned i;
34 bool ok;
35
36 if (argc != 2) {
37 fprintf(stderr, "Usage: %s <smb.conf-file>\n", argv[0]);
38 exit(1);
39 }
40
41 setup_logging(argv[0], DEBUG_STDOUT);
42 lp_load_global(argv[1]);
43
44 ev = tevent_context_init(NULL);
45 if (ev == NULL) {
46 fprintf(stderr, "tevent_context_init failed\n");
47 exit(1);
48 }
49
50 msg_ctx = messaging_init(ev, ev);
51 if (msg_ctx == NULL) {
52 fprintf(stderr, "messaging_init failed\n");
53 exit(1);
54 }
55
56 names = messaging_names_db(msg_ctx);
57
58 ok = server_id_db_lookup_one(names, "notify-daemon", &notifyd);
59 if (!ok) {
60 fprintf(stderr, "no notifyd\n");
61 exit(1);
62 }
63
64 for (i=0; i<50000; i++) {
65 struct notify_rec_change_msg msg = {
66 .instance.filter = UINT32_MAX,
67 .instance.subdir_filter = UINT32_MAX
68 };
69 char path[64];
70 size_t len;
71 struct iovec iov[2];
72 NTSTATUS status;
73
74 len = snprintf(path, sizeof(path), "/tmp%u", i);
75
76 iov[0].iov_base = &msg;
77 iov[0].iov_len = offsetof(struct notify_rec_change_msg, path);
78 iov[1].iov_base = path;
79 iov[1].iov_len = len+1;
80
81 status = messaging_send_iov(
82 msg_ctx, notifyd, MSG_SMB_NOTIFY_REC_CHANGE,
83 iov, ARRAY_SIZE(iov), NULL, 0);
84 if (!NT_STATUS_IS_OK(status)) {
85 fprintf(stderr, "messaging_send_iov returned %s\n",
86 nt_errstr(status));
87 exit(1);
88 }
89
90 msg.instance.filter = 0;
91 msg.instance.subdir_filter = 0;
92
93 status = messaging_send_iov(
94 msg_ctx, notifyd, MSG_SMB_NOTIFY_REC_CHANGE,
95 iov, ARRAY_SIZE(iov), NULL, 0);
96 if (!NT_STATUS_IS_OK(status)) {
97 fprintf(stderr, "messaging_send_iov returned %s\n",
98 nt_errstr(status));
99 exit(1);
100 }
101 }
102
103 req = messaging_read_send(ev, ev, msg_ctx, MSG_PONG);
104 if (req == NULL) {
105 fprintf(stderr, "messaging_read_send failed\n");
106 exit(1);
107 }
108 messaging_send_buf(msg_ctx, notifyd, MSG_PING, NULL, 0);
109
110 ok = tevent_req_poll(req, ev);
111 if (!ok) {
112 fprintf(stderr, "tevent_req_poll failed\n");
113 exit(1);
114 }
115
116 TALLOC_FREE(frame);
117 return 0;
118}
Note: See TracBrowser for help on using the repository browser.