From 7a3bda54b01991ca45ba2157636f4e01dc425bcb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 30 May 2014 15:24:34 +0000 Subject: lib: Add server_id_str_buf This is usable in a DEBUG statement without talloc_tos() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- lib/util/samba_util.h | 4 ++++ lib/util/server_id.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h index 73cab66c351..251ddc26ced 100644 --- a/lib/util/samba_util.h +++ b/lib/util/samba_util.h @@ -984,6 +984,10 @@ char *data_path(TALLOC_CTX *mem_ctx, const char *name); const char *shlib_ext(void); struct server_id; + +struct server_id_buf { char buf[48]; }; /* probably a bit too large ... */ +char *server_id_str_buf(struct server_id id, struct server_id_buf *dst); + bool server_id_equal(const struct server_id *p1, const struct server_id *p2); char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id); struct server_id server_id_from_string(uint32_t local_vnn, diff --git a/lib/util/server_id.c b/lib/util/server_id.c index a06891d80cc..4a844330ef3 100644 --- a/lib/util/server_id.c +++ b/lib/util/server_id.c @@ -41,6 +41,28 @@ bool server_id_equal(const struct server_id *p1, const struct server_id *p2) return true; } +char *server_id_str_buf(struct server_id id, struct server_id_buf *dst) +{ + if (server_id_is_disconnected(&id)) { + strlcpy(dst->buf, "disconnected", sizeof(dst->buf)); + } else if ((id.vnn == NONCLUSTER_VNN) && (id.task_id == 0)) { + snprintf(dst->buf, sizeof(dst->buf), "%llu", + (unsigned long long)id.pid); + } else if (id.vnn == NONCLUSTER_VNN) { + snprintf(dst->buf, sizeof(dst->buf), "%llu.%u", + (unsigned long long)id.pid, (unsigned)id.task_id); + } else if (id.task_id == 0) { + snprintf(dst->buf, sizeof(dst->buf), "%u:%llu", + (unsigned)id.vnn, (unsigned long long)id.pid); + } else { + snprintf(dst->buf, sizeof(dst->buf), "%u:%llu.%u", + (unsigned)id.vnn, + (unsigned long long)id.pid, + (unsigned)id.task_id); + } + return dst->buf; +} + char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id) { if (server_id_is_disconnected(id)) { -- cgit