s3:utils:mdsearch go to cmdline_messaging_context_free
authorJones Syue <jonessyue@qnap.com>
Thu, 12 Jan 2023 07:47:20 +0000 (15:47 +0800)
committerVolker Lendecke <vl@samba.org>
Thu, 12 Jan 2023 11:40:19 +0000 (11:40 +0000)
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 <jonessyue@qnap.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Jan 12 11:40:19 UTC 2023 on sn-devel-184

source3/utils/mdsearch.c

index ab48e366a0a5c1bca11d211a7c173c2a1bfbaca0..eddb83874cb587389b2c3582c18ce44328afec91 100644 (file)
@@ -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);