From nobody Mon Mar 2 08:31:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55A4C366DBE; Fri, 20 Feb 2026 18:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771613658; cv=none; b=ZC6FzCi5gw2lSVscav9+qJIP9DNfWKGE0VLMo7jc66ggmlyzRnG5eUlAp7eoQ3KQUpAN/Nfals4671++Pwv5rxfsLKrtMsi0HN3I+yd3A9joBEc4i+bPqZHgFxmf13AI/EvrpmYIPH+JqmivbubKfw16/dsir3IaaLVNRM1TZv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771613658; c=relaxed/simple; bh=9ND4Te+vCD8kxlRnTEnyhPCkkUOH5B3APGIVy4z0UiM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p3z1Zsygwc8TWjiWtVvB/xYiMApDFk4mQjDbCiXwcOKvNf7Je7n82MTuoncVsiX6JrIKhC82MFSW15sMQaQNIHMl5qvGjDRKhs1+Nn+9V4zxg29Jobf1WnrTviqGL3LkBLODeOf5UXE7m1mFmmRTZsyQ/GJnrYWFxYFPaRpiDXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ElPgYIf0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ElPgYIf0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DD7BC116C6; Fri, 20 Feb 2026 18:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771613658; bh=9ND4Te+vCD8kxlRnTEnyhPCkkUOH5B3APGIVy4z0UiM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ElPgYIf0zwKggKMPLF1/mu25RlHvSTsWcDMXFFnTL8YRyZqmWMeIaF4tf7NC4lWNc r9oC88bK6dZVmF/ewy28ZcRk+gX61l5k1spX9q9nG3+rKRoeBDxNc31z9mF41pBKJa 2P7M8WBb69DjPV2S0DpHZM7QT8i4L+IAQvrxJ6PQyAkW1NiIV4idu3K7Pxjds6KvhQ QqpzWav3z0jpjGmeQdncd3afQDU61yAY8ITlAgzounPaipdvAQFdJeAH1YEqs7UsR/ 5V532GYpdFjwYiNgLMQxCqdUl3wRj4Pg0JXrB3g0+e4GBH2WpxzhZAM/XEid/ZZqGY EHJNukc71nRfw== From: "Matthieu Baerts (NGI0)" Date: Fri, 20 Feb 2026 19:54:02 +0100 Subject: [PATCH iproute2-next 2/3] utils: timestamp: add JSON support Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260220-ipr-monitor-json-v1-2-eb4b0d5f7820@kernel.org> References: <20260220-ipr-monitor-json-v1-0-eb4b0d5f7820@kernel.org> In-Reply-To: <20260220-ipr-monitor-json-v1-0-eb4b0d5f7820@kernel.org> To: Stephen Hemminger , David Ahern Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1618; i=matttbe@kernel.org; h=from:subject:message-id; bh=9ND4Te+vCD8kxlRnTEnyhPCkkUOH5B3APGIVy4z0UiM=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJnrL1aNlHkRPy2eSs4bksaaYXnFU+1v3Nr8rz01G2ez /bHPGGu7ihlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZjIu2MMv1m8zDyu71ketrdN zGb/hleXpi6dWb9A8tWz9uwf5rM4WkMYfrMzNpgvj/KqFH7I/v7C/KIJNUsz9JJW7wxysQ8Lexe zkB8A X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Only if the output stream is 'stdout', because all JSON helpers like print_string() only write on 'stdout'. Supporting JSON is easy with the helpers. The biggest modification is to extract the end value. No behavioural changes intended for the moment, this is a preparation for a future usage of print_timestamp() within a JSON context. Signed-off-by: Matthieu Baerts (NGI0) --- lib/utils.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index 13e8c098..d7581709 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1277,21 +1277,30 @@ int print_timestamp(FILE *fp) { struct timeval tv; struct tm *tm; + char ts[40]; =20 gettimeofday(&tv, NULL); tm =3D localtime(&tv.tv_sec); =20 if (timestamp_short) { - char tshort[40]; + size_t len; =20 - strftime(tshort, sizeof(tshort), "%Y-%m-%dT%H:%M:%S", tm); - fprintf(fp, "[%s.%06ld] ", tshort, tv.tv_usec); + len =3D strftime(ts, sizeof(ts), "%Y-%m-%dT%H:%M:%S", tm); + snprintf(ts + len, sizeof(ts) - len, ".%06ld", tv.tv_usec); + if (fp =3D=3D stdout) + print_string(PRINT_ANY, "timestamp_short", "[%s] ", ts); + else + fprintf(fp, "[%s] ", ts); } else { char *tstr =3D asctime(tm); =20 tstr[strlen(tstr)-1] =3D 0; - fprintf(fp, "Timestamp: %s %ld usec\n", - tstr, tv.tv_usec); + snprintf(ts, sizeof(ts), "%s %ld usec", tstr, tv.tv_usec); + if (fp =3D=3D stdout) + print_string(PRINT_ANY, "timestamp", + "Timestamp: %s\n", ts); + else + fprintf(fp, "Timestamp: %s\n", ts); } =20 return 0; --=20 2.51.0