From 70b41fb212ed45044f405a7afa0793a77a17b80f Mon Sep 17 00:00:00 2001 From: Jones Syue Date: Thu, 12 Jan 2023 15:47:20 +0800 Subject: [PATCH] s3:utils:mdsearch go to cmdline_messaging_context_free mdsearch utility would exit earlier with failure in several cases like: a. samba server is not running yet, [~] # mdsearch -Uuser%password1 ${server} Public '*=="Samba"' main: Cannot connect to server: NT_STATUS_CONNECTION_REFUSED b. spotlight backend service is not ready yet, [~] # mdsearch -Uuser%password1 ${server} Public '*=="Samba"' Failed to connect mdssvc c. mdsearch utility paramters is not as expecred, [~] # mdsearch -Uuser%password1 ${server} share_not_exist '*=="Samba"' mdscli_search failed And in the mean while once mdsearch utility exit earlier with failure, the lock files are left behind in the directory 'msg.sock' and 'msg.lock'. If a script to run mdsearch utility in a loop, this might result in used space slowly growing-up on underlying filesystem. Supposed to add a new label 'fail_free_messaging', make it go through the cmdline_messaging_context_free() which deletes the lock files in the directory msg.sock and msg.lock before mdsearch utility is exiting with failure. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15284 Signed-off-by: Jones Syue Reviewed-by: Ralph Boehme Reviewed-by: Volker Lendecke Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Thu Jan 12 11:40:19 UTC 2023 on sn-devel-184 (cherry picked from commit 98d84192a03a4f1135eaf1590fb62b16d8bc49c8) --- source3/utils/mdsearch.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/source3/utils/mdsearch.c b/source3/utils/mdsearch.c index ab48e36..eddb838 100644 --- a/source3/utils/mdsearch.c +++ b/source3/utils/mdsearch.c @@ -144,12 +144,12 @@ int main(int argc, char **argv) flags); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("Cannot connect to server: %s\n", nt_errstr(status)); - goto fail; + goto fail_free_messaging; } status = cli_rpc_pipe_open_noauth(cli, &ndr_table_mdssvc, &rpccli); if (!NT_STATUS_IS_OK(status)) { - goto fail; + goto fail_free_messaging; } status = mdscli_connect(frame, @@ -159,7 +159,7 @@ int main(int argc, char **argv) &mdscli_ctx); if (!NT_STATUS_IS_OK(status)) { printf("Failed to connect mdssvc\n"); - goto fail; + goto fail_free_messaging; } if (opt_path == NULL) { @@ -168,7 +168,7 @@ int main(int argc, char **argv) basepath = talloc_strdup(frame, opt_path); } if (basepath == NULL) { - goto fail; + goto fail_free_messaging; } status = mdscli_search(frame, @@ -179,7 +179,7 @@ int main(int argc, char **argv) &search); if (!NT_STATUS_IS_OK(status)) { printf("mdscli_search failed\n"); - goto fail; + goto fail_free_messaging; } if (!opt_live) { @@ -199,7 +199,7 @@ int main(int argc, char **argv) } if (!NT_STATUS_IS_OK(status)) { printf("mdscli_get_results failed\n"); - goto fail; + goto fail_free_messaging; } ncnids = talloc_array_length(cnids); @@ -217,7 +217,7 @@ int main(int argc, char **argv) if (!NT_STATUS_IS_OK(status)) { printf("Get path for CNID 0x%"PRIx64" failed\n", cnids[i]); - goto fail; + goto fail_free_messaging; } printf("%s\n", path); TALLOC_FREE(path); @@ -227,13 +227,13 @@ int main(int argc, char **argv) status = mdscli_close_search(&search); if (!NT_STATUS_IS_OK(status)) { printf("mdscli_close_search failed\n"); - goto fail; + goto fail_free_messaging; } status = mdscli_disconnect(mdscli_ctx); if (!NT_STATUS_IS_OK(status)) { printf("mdscli_disconnect failed\n"); - goto fail; + goto fail_free_messaging; } cmdline_messaging_context_free(); @@ -241,6 +241,8 @@ int main(int argc, char **argv) poptFreeContext(pc); return 0; +fail_free_messaging: + cmdline_messaging_context_free(); fail: poptFreeContext(pc); TALLOC_FREE(frame); -- 2.1.4