diff options
author | Volker Lendecke <vl@samba.org> | 2014-05-30 15:24:34 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-06-17 07:00:14 +0200 |
commit | 7a3bda54b01991ca45ba2157636f4e01dc425bcb (patch) | |
tree | 5c7105cd8f1e353fcdb22023ae8d9219a110a845 | |
parent | 0e9d4f68f94be4d187eb80429194267244861832 (diff) | |
download | samba-7a3bda54b01991ca45ba2157636f4e01dc425bcb.tar.gz samba-7a3bda54b01991ca45ba2157636f4e01dc425bcb.tar.xz samba-7a3bda54b01991ca45ba2157636f4e01dc425bcb.zip |
lib: Add server_id_str_buf
This is usable in a DEBUG statement without talloc_tos()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r-- | lib/util/samba_util.h | 4 | ||||
-rw-r--r-- | lib/util/server_id.c | 22 |
2 files changed, 26 insertions, 0 deletions
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)) { |