mdscli: correct handling of in-progress searches
authorRalph Boehme <slow@samba.org>
Thu, 20 Apr 2023 13:12:49 +0000 (15:12 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 24 Jul 2023 16:15:16 +0000 (16:15 +0000)
If a query is still being processed on the server and there no results yet,
macOS returns 0x23.

For now just implements this as dumb polling once a second in mdsearch and the
Python bindings.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Noel Power <noel.power@suse.com>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Mon Jul 24 16:15:16 UTC 2023 on atb-devel-224

source3/rpc_client/cli_mdssvc.c
source3/rpc_client/py_mdscli.c
source3/utils/mdsearch.c

index b749dca45f137e06a1275ce0d20e34a28f8985e7..839cd62ce8681361f6a4e05718c23632c3a0c5ed 100644 (file)
@@ -608,6 +608,7 @@ static void mdscli_get_results_cmd_done(struct tevent_req *subreq)
        size_t oldsize, newsize;
        DALLOC_CTX *d = NULL;
        uint64_t *uint64p = NULL;
+       bool search_in_progress = false;
        sl_cnids_t *cnids = NULL;
        size_t ncnids;
        size_t i;
@@ -696,9 +697,8 @@ static void mdscli_get_results_cmd_done(struct tevent_req *subreq)
        }
 
        if (*uint64p == 35) {
-               DBG_DEBUG("search done: %s", dalloc_dump(d, 0));
-               tevent_req_done(req);
-               return;
+               DBG_DEBUG("Search in progress\n");
+               search_in_progress = true;
        }
 
        cnids = dalloc_get(d, "DALLOC_CTX", 0, "sl_cnids_t", 1);
@@ -709,7 +709,7 @@ static void mdscli_get_results_cmd_done(struct tevent_req *subreq)
        }
 
        ncnids = dalloc_size(cnids->ca_cnids);
-       if (ncnids == 0) {
+       if (ncnids == 0 && !search_in_progress) {
                tevent_req_nterror(req, NT_STATUS_NO_MORE_MATCHES);
                return;
        }
index 290be3f86d9c5c7c12bab54e42e23cf14a5c265a..2594200ecfefb2966c3cf3b0f93235f1c2454107 100644 (file)
@@ -88,6 +88,7 @@ static PyObject *search_get_results(PyObject *self,
         *   py_dcerpc_interface_init_helper()
         *   -> dcerpc_pipe_connect()
         */
+again:
        req = mdscli_get_results_send(frame,
                                      pipe->ev,
                                      search);
@@ -102,13 +103,17 @@ static PyObject *search_get_results(PyObject *self,
        }
 
        status = mdscli_get_results_recv(req, frame, &cnids);
+       TALLOC_FREE(req);
+       if (NT_STATUS_EQUAL(status, NT_STATUS_PENDING)) {
+               sleep(1);
+               goto again;
+       }
        if (!NT_STATUS_IS_OK(status) &&
            !NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_MATCHES))
        {
                PyErr_SetNTSTATUS(status);
                goto out;
        }
-       TALLOC_FREE(req);
 
        result = Py_BuildValue("[]");
 
index eddb83874cb587389b2c3582c18ce44328afec91..1472b5cfa3271614377fd682b0e7305a4b09f7b1 100644 (file)
@@ -197,12 +197,20 @@ int main(int argc, char **argv)
                        }
                        break;
                }
+
+               ncnids = talloc_array_length(cnids);
+
+               if (NT_STATUS_EQUAL(status, NT_STATUS_PENDING) &&
+                   ncnids == 0)
+               {
+                       sleep(1);
+                       continue;
+               }
                if (!NT_STATUS_IS_OK(status)) {
                        printf("mdscli_get_results failed\n");
                        goto fail_free_messaging;
                }
 
-               ncnids = talloc_array_length(cnids);
                if (ncnids == 0) {
                        break;
                }