[PATCH] Add server_id_str_buf
Volker Lendecke
Volker.Lendecke at SerNet.DE
Mon Jun 16 03:36:11 MDT 2014
Hi!
Add a routine that makes it possible to avoid talloc_tos()
in DEBUG statments for server ids.
Review would be appreciated.
Thanks,
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From b6a294ded0cd8037847a226b92809499d2355ce9 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 30 May 2014 15:24:34 +0000
Subject: [PATCH 1/3] lib: Add server_id_str_buf
This is usable in a DEBUG statement without talloc_tos()
Signed-off-by: Volker Lendecke <vl at samba.org>
---
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 73cab66..251ddc2 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 a06891d..4a84433 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)) {
--
1.8.1.2
From 6e9dc31b16c71191464f9cb0abf81ba3fff90b80 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Jun 2014 13:04:56 +0000
Subject: [PATCH 2/3] lib: Use server_id_str_buf in server_id_str
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/util/server_id.c | 34 ++++++++++++----------------------
1 file changed, 12 insertions(+), 22 deletions(-)
diff --git a/lib/util/server_id.c b/lib/util/server_id.c
index 4a84433..e0a05a7 100644
--- a/lib/util/server_id.c
+++ b/lib/util/server_id.c
@@ -65,29 +65,19 @@ char *server_id_str_buf(struct server_id id, struct server_id_buf *dst)
char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id)
{
- if (server_id_is_disconnected(id)) {
- return talloc_strdup(mem_ctx, "disconnected");
- } else if (id->vnn == NONCLUSTER_VNN && id->task_id == 0) {
- return talloc_asprintf(mem_ctx,
- "%llu",
- (unsigned long long)id->pid);
- } else if (id->vnn == NONCLUSTER_VNN) {
- return talloc_asprintf(mem_ctx,
- "%llu.%u",
- (unsigned long long)id->pid,
- (unsigned)id->task_id);
- } else if (id->task_id == 0) {
- return talloc_asprintf(mem_ctx,
- "%u:%llu",
- (unsigned)id->vnn,
- (unsigned long long)id->pid);
- } else {
- return talloc_asprintf(mem_ctx,
- "%u:%llu.%u",
- (unsigned)id->vnn,
- (unsigned long long)id->pid,
- (unsigned)id->task_id);
+ struct server_id_buf tmp;
+ char *result;
+
+ result = talloc_strdup(mem_ctx, server_id_str_buf(*id, &tmp));
+ if (result == NULL) {
+ return NULL;
}
+
+ /*
+ * beautify the talloc_report output
+ */
+ talloc_set_name_const(result, result);
+ return result;
}
struct server_id server_id_from_string(uint32_t local_vnn,
--
1.8.1.2
From 5fcf17cba94232d15c6e34d75304752c8c6c150a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Jun 2014 13:11:05 +0000
Subject: [PATCH 3/3] messaging3: Use server_id_str_buf
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages_dgm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index ba13fc9..c3ab0d1 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -301,6 +301,7 @@ static NTSTATUS messaging_dgm_send(struct server_id src,
struct messaging_dgm_hdr hdr;
struct iovec iov2[iovlen + 1];
ssize_t pathlen;
+ struct server_id_buf idbuf;
int ret;
fstr_sprintf(pid_str, "msg/%u", (unsigned)pid.pid);
@@ -318,7 +319,7 @@ static NTSTATUS messaging_dgm_send(struct server_id src,
DEBUG(10, ("%s: Sending message 0x%x to %s\n", __func__,
(unsigned)hdr.msg_type,
- server_id_str(talloc_tos(), &pid)));
+ server_id_str_buf(pid, &idbuf)));
iov2[0].iov_base = &hdr;
iov2[0].iov_len = sizeof(hdr);
@@ -344,6 +345,7 @@ static void messaging_dgm_recv(struct unix_msg_ctx *ctx,
private_data, struct messaging_dgm_context);
struct messaging_dgm_hdr *hdr;
struct messaging_rec rec;
+ struct server_id_buf idbuf;
if (msg_len < sizeof(*hdr)) {
DEBUG(1, ("message too short: %u\n", (unsigned)msg_len));
@@ -364,7 +366,7 @@ static void messaging_dgm_recv(struct unix_msg_ctx *ctx,
DEBUG(10, ("%s: Received message 0x%x len %u from %s\n", __func__,
(unsigned)hdr->msg_type, (unsigned)rec.buf.length,
- server_id_str(talloc_tos(), &rec.src)));
+ server_id_str_buf(rec.src, &idbuf)));
messaging_dispatch_rec(dgm_ctx->msg_ctx, &rec);
}
--
1.8.1.2
More information about the samba-technical
mailing list