summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/util/samba_util.h4
-rw-r--r--lib/util/server_id.c22
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)) {