[PATCH 1/3] syslogd: Use a local to track whether a message has a timestamp.

Grant Erickson gerickson at nuovations.com
Wed Apr 2 03:16:52 UTC 2025


This improves self-documentation and readability of the code.

Signed-off-by: Grant Erickson <gerickson at nuovations.com>
---
sysklogd/syslogd.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 73c681827d86..a188370b4a0a 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -857,14 +857,16 @@ static char *timestamp_from_time(const time_t *time)
 * that there is no timestamp, short-circuiting the test. */
static void timestamp_and_log(int pri, char *msg, int len)
{
+	const bool msg_has_timestamp = (len >= 16 &&
+		msg[ 3] == ' ' && msg[ 6] == ' ' &&
+		msg[ 9] == ':' && msg[12] == ':' &&
+		msg[15] == ' ');
	char *timestamp = NULL;
	time_t now;

	/* Jan 18 00:11:22 msg... */
	/* 01234567890123456 */
-	if (len >= 16 && msg[3] == ' ' && msg[6] == ' '
-	 && msg[9] == ':' && msg[12] == ':' && msg[15] == ' '
-	) {
+	if (msg_has_timestamp) {
		if (!(option_mask32 & OPT_timestamp)) {
			/* use message timestamp */
#if ENABLE_FEATURE_SYSLOGD_UTC
-- 
2.45.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-syslogd-Use-a-local-to-track-whether-a-message-has-a.patch
Type: application/octet-stream
Size: 1513 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20250401/09e5ea40/attachment.obj>


More information about the busybox mailing list