From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH] batctl: event: don't print timestamp prefix for skipped events
Date: Sat, 04 Jul 2026 15:06:35 +0200 [thread overview]
Message-ID: <20260704-bugfixes-event-v1-1-554d51ea1b2d@narfation.org> (raw)
The timestamp is printed before the event is parsed. Each parse function
can still decide to skip the event without printing anything In these cases
a bare "1234.567890: " fragment without newline remains on the line and the
next event is appended to it, corrupting the output stream.
Format the timestamp into a prefix string instead and let the parse
functions print it together with their first line.
Fixes: 5d7850e3582e ("batctl: Add command to monitor for netlink events")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
event.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/event.c b/event.c
index e061c2c..4a1085d 100644
--- a/event.c
+++ b/event.c
@@ -114,7 +114,7 @@ static const int tp_meter_mandatory[] = {
BATADV_ATTR_TPMETER_RESULT,
};
-static void event_parse_tp_meter(struct nlattr **attrs)
+static void event_parse_tp_meter(struct nlattr **attrs, const char *prefix)
{
const char *result_str;
uint32_t cookie;
@@ -155,10 +155,10 @@ static void event_parse_tp_meter(struct nlattr **attrs)
break;
}
- printf("tp_meter 0x%08x: %s\n", cookie, result_str);
+ printf("%stp_meter 0x%08x: %s\n", prefix, cookie, result_str);
}
-static void event_parse_set_mesh(struct nlattr **attrs)
+static void event_parse_set_mesh(struct nlattr **attrs, const char *prefix)
{
static const int mesh_mandatory[] = {
BATADV_ATTR_MESH_IFINDEX,
@@ -183,7 +183,7 @@ static void event_parse_set_mesh(struct nlattr **attrs)
return;
}
- printf("%s: set mesh:\n", meshif_name);
+ printf("%s%s: set mesh:\n", prefix, meshif_name);
if (attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED])
printf("* aggregated_ogms %s\n",
@@ -287,7 +287,7 @@ static void event_parse_set_mesh(struct nlattr **attrs)
nla_get_u32(attrs[BATADV_ATTR_ORIG_INTERVAL]));
}
-static void event_parse_set_hardif(struct nlattr **attrs)
+static void event_parse_set_hardif(struct nlattr **attrs, const char *prefix)
{
static const int hardif_mandatory[] = {
BATADV_ATTR_MESH_IFINDEX,
@@ -325,7 +325,7 @@ static void event_parse_set_hardif(struct nlattr **attrs)
return;
}
- printf("%s (%s): set hardif:\n", meshif_name, hardif_name);
+ printf("%s%s (%s): set hardif:\n", prefix, meshif_name, hardif_name);
if (attrs[BATADV_ATTR_HOP_PENALTY])
printf("* hop_penalty %u\n",
@@ -344,7 +344,7 @@ static void event_parse_set_hardif(struct nlattr **attrs)
}
}
-static void event_parse_set_vlan(struct nlattr **attrs)
+static void event_parse_set_vlan(struct nlattr **attrs, const char *prefix)
{
static const int vlan_mandatory[] = {
BATADV_ATTR_MESH_IFINDEX,
@@ -372,7 +372,7 @@ static void event_parse_set_vlan(struct nlattr **attrs)
vid = nla_get_u16(attrs[BATADV_ATTR_VLANID]);
- printf("%s (vid %u): set vlan:\n", meshif_name, vid);
+ printf("%s%s (vid %u): set vlan:\n", prefix, meshif_name, vid);
if (attrs[BATADV_ATTR_AP_ISOLATION_ENABLED])
printf("* ap_isolation %s\n",
@@ -403,6 +403,7 @@ static int event_parse(struct nl_msg *msg, void *arg)
struct event_args *event_args = arg;
unsigned long long timestamp;
struct genlmsghdr *ghdr;
+ char prefix[32] = "";
if (!genlmsg_valid_hdr(nlh, 0))
return NL_OK;
@@ -417,24 +418,25 @@ static int event_parse(struct nl_msg *msg, void *arg)
if (event_args->mode != EVENT_TIME_NO) {
timestamp = get_timestamp(event_args);
- printf("%llu.%06llu: ", timestamp / 1000000, timestamp % 1000000);
+ snprintf(prefix, sizeof(prefix), "%llu.%06llu: ",
+ timestamp / 1000000, timestamp % 1000000);
}
switch (ghdr->cmd) {
case BATADV_CMD_TP_METER:
- event_parse_tp_meter(attrs);
+ event_parse_tp_meter(attrs, prefix);
break;
case BATADV_CMD_SET_MESH:
- event_parse_set_mesh(attrs);
+ event_parse_set_mesh(attrs, prefix);
break;
case BATADV_CMD_SET_HARDIF:
- event_parse_set_hardif(attrs);
+ event_parse_set_hardif(attrs, prefix);
break;
case BATADV_CMD_SET_VLAN:
- event_parse_set_vlan(attrs);
+ event_parse_set_vlan(attrs, prefix);
break;
default:
- printf("Received unknown event %u\n", ghdr->cmd);
+ printf("%sReceived unknown event %u\n", prefix, ghdr->cmd);
break;
}
---
base-commit: e93995999e80513db80eba200ea682b5b15556af
change-id: 20260704-bugfixes-event-cac8fef8b398
Best regards,
--
Sven Eckelmann <sven@narfation.org>
reply other threads:[~2026-07-04 13:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260704-bugfixes-event-v1-1-554d51ea1b2d@narfation.org \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox