]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tdb: allow tracing of internal tdb
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 10 Jul 2024 04:04:27 +0000 (16:04 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Sat, 27 Jul 2024 22:47:39 +0000 (22:47 +0000)
This will trace internal databases to files like this:

tdb_0x5da896b51870.trace.267290

We avoid strlen(name) because name could be NULL in this case (which
works fine with glibc but feels bad).

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/tdb/common/open.c

index 3fa7ce1389d690a43cd8605be0e3263b7da43d82..87312f7dc09f784e7008124513a7d29a10b645be 100644 (file)
@@ -721,12 +721,21 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
                goto fail;
        }
 
+ internal:
+       /* Internal (memory-only) databases skip all the code above to
+        * do with disk files, and resume here by releasing their
+        * open lock and hooking into the active list. */
+
 #ifdef TDB_TRACE
        {
-               char tracefile[strlen(name) + 32];
-
-               snprintf(tracefile, sizeof(tracefile),
-                        "%s.trace.%li", name, (long)getpid());
+               char tracefile[64];
+               if (tdb->flags & TDB_INTERNAL) {
+                       snprintf(tracefile, sizeof(tracefile),
+                                "tdb_%p.trace.%li", tdb, (long)getpid());
+               } else {
+                       snprintf(tracefile, sizeof(tracefile),
+                                "%s.trace.%li", name, (long)getpid());
+               }
                tdb->tracefd = open(tracefile, O_WRONLY|O_CREAT|O_EXCL, 0600);
                if (tdb->tracefd >= 0) {
                        tdb_enable_seqnum(tdb);
@@ -737,10 +746,6 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
        }
 #endif
 
- internal:
-       /* Internal (memory-only) databases skip all the code above to
-        * do with disk files, and resume here by releasing their
-        * open lock and hooking into the active list. */
        if (tdb_nest_unlock(tdb, OPEN_LOCK, F_WRLCK, false) == -1) {
                goto fail;
        }