lib: replace: Add strsep function (missing on Solaris).
[Samba.git] / source3 / smbd / notifyd / tests.c
blob6bcce6aa9fb14eb00bb73a394d116389bb9f2007
1 /*
2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Volker Lendecke 2014
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.
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.
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/>.
20 #include "replace.h"
21 #include "notifyd.h"
22 #include "messages.h"
23 #include "lib/util/server_id_db.h"
25 int main(int argc, const char *argv[])
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;
36 if (argc != 2) {
37 fprintf(stderr, "Usage: %s <smb.conf-file>\n", argv[0]);
38 exit(1);
41 setup_logging(argv[0], DEBUG_STDOUT);
42 lp_load_global(argv[1]);
44 ev = tevent_context_init(NULL);
45 if (ev == NULL) {
46 fprintf(stderr, "tevent_context_init failed\n");
47 exit(1);
50 msg_ctx = messaging_init(ev, ev);
51 if (msg_ctx == NULL) {
52 fprintf(stderr, "messaging_init failed\n");
53 exit(1);
56 names = messaging_names_db(msg_ctx);
58 ok = server_id_db_lookup_one(names, "notify-daemon", &notifyd);
59 if (!ok) {
60 fprintf(stderr, "no notifyd\n");
61 exit(1);
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
69 char path[64];
70 size_t len;
71 struct iovec iov[2];
72 NTSTATUS status;
74 len = snprintf(path, sizeof(path), "/tmp%u", i);
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;
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);
90 msg.instance.filter = 0;
91 msg.instance.subdir_filter = 0;
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);
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);
108 messaging_send_buf(msg_ctx, notifyd, MSG_PING, NULL, 0);
110 ok = tevent_req_poll(req, ev);
111 if (!ok) {
112 fprintf(stderr, "tevent_req_poll failed\n");
113 exit(1);
116 TALLOC_FREE(frame);
117 return 0;