smbclient: cancel pending notify on SIGINT
Subsystems (2)
[email protected]
reviewerv2 cover smbclient: cancel pending notify on SIGINT
From: ChenXiaoSong <[email protected]>
I also created a merge request on GitLab: https://gitlab.com/samba-team/samba/-/merge_requests/4530
v1->v2: sig_state.cancelled is checked before cli_notify_send(), because changes needs to be freed.
v1: https://lore.kernel.org/linux-cifs/[email protected]/
ChenXiaoSong (1):
smbclient: cancel pending notify on SIGINT
source3/client/client.c | 53 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-)
Signature · 1 line
2.54.0
[email protected]
reviewerPATCH v2 1/1 smbclient: cancel pending notify on SIGINT
From: ChenXiaoSong <[email protected]>
When client stops querying a directory for change notifications, it should send a cancel request to the server.
After cancel notify succeeds, status returned by both tevent_req_poll_ntstatus() and cli_notify_recv() is NT_STATUS_OK rather than NT_STATUS_CANCELLED, so we can only check sig_state.cancelled.
--- source3/client/client.c | 53 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-)
source3/client/client.c +50 -3
@@ -45,6 +45,7 @@#include "lib/cmdline/cmdline.h" #include "libcli/smb/reparse.h" #include "lib/param/param.h" +#include "lib/util/tevent_ntstatus.h" #ifndef REGISTER #define REGISTER 0
@@ -4653,12 +4654,39 @@ static int cmd_newer(TALLOC_CTX *mem_ctx)Watch directory changes ****************************************************************************/ +struct notify_state { +struct tevent_req *notify_req; +bool cancelled; +}; + +static void +notify_sig_int_handler ( +struct tevent_context *ev, +struct tevent_signal *se, +int signum, +int count, +void *siginfo, +void *private_data) +{ +struct notify_state *state = (struct notify_state *)private_data; + +if (state->notify_req) + state->cancelled =tevent_req_cancel (state->notify_req); +} +static int cmd_notify (TALLOC_CTX *mem_ctx) {TALLOC_CTX *frame =talloc_stackframe ();char *name, *buf;NTSTATUS status;uint16_t fnum; +struct tevent_req *req; +struct tevent_context *ev; +struct tevent_signal *se; +struct notify_state sig_state = { + .notify_req =NULL , + .cancelled = false, + }; name =talloc_strdup (talloc_tos (),client_get_cur_dir ());if (name ==NULL ) {
@@ -4684,14 +4712,33 @@ static int cmd_notify(TALLOC_CTX *mem_ctx) goto fail; } + ev =samba_tevent_context_init (frame); +if (!ev) + goto fail; + + se =tevent_add_signal (ev, frame,SIGINT ,0 , notify_sig_int_handler, &sig_state); +if (!se) + goto fail; +while (1 ) {uint32_t i;uint32_t num_changes =0 ;struct notify_change *changes =NULL ; - status =cli_notify (cli, fnum,1000 ,FILE_NOTIFY_CHANGE_ALL , - true, -talloc_tos (), &num_changes, &changes); +if (sig_state.cancelled) { +printf ("notify cancelled\n" ); + goto fail; + } + + req =cli_notify_send (frame, ev, cli, fnum,1000 ,FILE_NOTIFY_CHANGE_ALL , true); +if (!req) + goto fail; + sig_state.notify_req = req; + +if (!tevent_req_poll_ntstatus (req, ev, &status)) + goto fail; + + status =cli_notify_recv (req,talloc_tos (), &num_changes, &changes);if (NT_STATUS_EQUAL (status,NT_STATUS_NOTIFY_ENUM_DIR )) {printf ("NOTIFY_ENUM_DIR\n" ); status =NT_STATUS_OK ;
Signature · 1 line
2.54.0