From: Douglas Bagnall Date: Wed, 10 Jul 2024 04:04:27 +0000 (+1200) Subject: tdb: allow tracing of internal tdb X-Git-Tag: tdb-1.4.11~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=351636efa7f1a35c2fe554237869b2f4e502915f;p=thirdparty%2Fsamba.git tdb: allow tracing of internal tdb 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 Reviewed-by: Stefan Metzmacher --- diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c index 3fa7ce1389d..87312f7dc09 100644 --- a/lib/tdb/common/open.c +++ b/lib/tdb/common/open.c @@ -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; }