s3:mdssvc: move debug macro to header file
[bbaumbach/samba-autobuild/.git] / source3 / rpc_server / mdssvc / mdssvc.c
index 693675fff6ff64dddaeedb028bfdb0d7a682fddc..85da89d4ef0711d1e39c00837647a81e28848cbe 100644 (file)
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
 
-#define SLQ_DEBUG(lvl, _slq, state) do { if (CHECK_DEBUGLVL(lvl)) {    \
-       const struct sl_query *__slq = _slq;                            \
-       struct timeval_buf start_buf;                                   \
-       const char *start;                                              \
-       struct timeval_buf last_used_buf;                               \
-       const char *last_used;                                          \
-       struct timeval_buf expire_buf;                                  \
-       const char *expire;                                             \
-       start = timeval_str_buf(&__slq->start_time, false,              \
-                               true, &start_buf);                      \
-       last_used = timeval_str_buf(&__slq->last_used, false,           \
-                                   true, &last_used_buf);              \
-       expire = timeval_str_buf(&__slq->expire_time, false,            \
-                                true, &expire_buf);                    \
-       DEBUG(lvl,("%s slq[0x%jx,0x%jx], start: %s, last_used: %s, "    \
-                  "expires: %s, query: '%s'\n", state,                 \
-                  (uintmax_t)__slq->ctx1, (uintmax_t)__slq->ctx2,      \
-                  start, last_used, expire, __slq->query_string));     \
-}} while(0)
-
 struct slrpc_cmd {
        const char *name;
        bool (*function)(struct mds_ctx *mds_ctx,
@@ -820,12 +800,13 @@ static void tracker_cursor_cb(GObject *object,
         * not as the user.
         */
        if (!become_authenticated_pipe_user(slq->mds_ctx->pipe_session_info)) {
-               DBG_ERR("can't become authenticated user: %d\n", slq->mds_ctx->uid);
+               DBG_ERR("can't become authenticated user: %d\n",
+                       slq->mds_ctx->uid);
                smb_panic("can't become authenticated user");
        }
 
        if (geteuid() != slq->mds_ctx->uid) {
-               DEBUG(0, ("uid mismatch: %d/%d\n", geteuid(), slq->mds_ctx->uid));
+               DBG_ERR("uid mismatch: %d/%d\n", geteuid(), slq->mds_ctx->uid);
                smb_panic("uid mismatch");
        }
 
@@ -854,8 +835,11 @@ static void tracker_cursor_cb(GObject *object,
                 * set of IDs. Note that we're faking CNIDs by using
                 * filesystem inode numbers here
                 */
-               ok = bsearch(&ino64, slq->cnids, slq->cnids_num,
-                            sizeof(uint64_t), cnid_comp_fn);
+               ok = bsearch(&ino64,
+                            slq->cnids,
+                            slq->cnids_num,
+                            sizeof(uint64_t),
+                            cnid_comp_fn);
                if (!ok) {
                        goto done;
                }
@@ -866,16 +850,19 @@ static void tracker_cursor_cb(GObject *object,
         * we return as part of the result set of a query
         */
        result = dalloc_add_copy(slq->query_results->cnids->ca_cnids,
-                                &ino64, uint64_t);
+                                &ino64,
+                                uint64_t);
        if (result != 0) {
-               DEBUG(1, ("dalloc error\n"));
+               DBG_ERR("dalloc error\n");
                slq->state = SLQ_STATE_ERROR;
                return;
        }
-       ok = add_filemeta(slq->reqinfo, slq->query_results->fm_array,
-                         path, &sb);
+       ok = add_filemeta(slq->reqinfo,
+                         slq->query_results->fm_array,
+                         path,
+                         &sb);
        if (!ok) {
-               DEBUG(1, ("add_filemeta error\n"));
+               DBG_ERR("add_filemeta error\n");
                slq->state = SLQ_STATE_ERROR;
                return;
        }
@@ -1251,7 +1238,6 @@ static bool slrpc_open_query(struct mds_ctx *mds_ctx,
                goto error;
        }
 
-
        reqinfo = dalloc_value_for_key(query, "DALLOC_CTX", 0,
                                       "DALLOC_CTX", 1, "kMDAttributeArray");
        if (reqinfo == NULL) {
@@ -1837,6 +1823,9 @@ static struct mdssvc_ctx *mdssvc_init(struct tevent_context *ev)
 
 /**
  * Init callbacks at startup
+ *
+ * This gets typically called in the main parent smbd which means we can't
+ * initialize our global state here.
  **/
 bool mds_init(struct messaging_context *msg_ctx)
 {
@@ -1860,6 +1849,36 @@ bool mds_shutdown(void)
        return true;
 }
 
+/**
+ * Tear down connections and free all resources
+ **/
+static int mds_ctx_destructor_cb(struct mds_ctx *mds_ctx)
+{
+       /*
+        * We need to free query_list before ino_path_map
+        */
+       while (mds_ctx->query_list != NULL) {
+               /*
+                * slq destructor removes element from list.
+                * Don't use TALLOC_FREE()!
+                */
+               talloc_free(mds_ctx->query_list);
+       }
+       TALLOC_FREE(mds_ctx->ino_path_map);
+
+       if (mds_ctx->tracker_con != NULL) {
+               g_object_unref(mds_ctx->tracker_con);
+       }
+       if (mds_ctx->gcancellable != NULL) {
+               g_cancellable_cancel(mds_ctx->gcancellable);
+               g_object_unref(mds_ctx->gcancellable);
+       }
+
+       ZERO_STRUCTP(mds_ctx);
+
+       return 0;
+}
+
 /**
  * Initialise a context per RPC bind
  *
@@ -1919,36 +1938,6 @@ error:
        return NULL;
 }
 
-/**
- * Tear down connections and free all resources
- **/
-int mds_ctx_destructor_cb(struct mds_ctx *mds_ctx)
-{
-       /*
-        * We need to free query_list before ino_path_map
-        */
-       while (mds_ctx->query_list != NULL) {
-               /*
-                * slq destructor removes element from list.
-                * Don't use TALLOC_FREE()!
-                */
-               talloc_free(mds_ctx->query_list);
-       }
-       TALLOC_FREE(mds_ctx->ino_path_map);
-
-       if (mds_ctx->tracker_con != NULL) {
-               g_object_unref(mds_ctx->tracker_con);
-       }
-       if (mds_ctx->gcancellable != NULL) {
-               g_cancellable_cancel(mds_ctx->gcancellable);
-               g_object_unref(mds_ctx->gcancellable);
-       }
-
-       ZERO_STRUCTP(mds_ctx);
-
-       return 0;
-}
-
 /**
  * Dispatch a Spotlight RPC command
  **/