[PATCH v2 1/3] syslogd: Use a local to track whether a message has a timestamp.
Grant Erickson
gerickson at nuovations.com
Wed Apr 2 14:43:51 UTC 2025
This improves self-documentation and readability of the code.
Signed-off-by: Grant Erickson <gerickson at nuovations.com>
---
sysklogd/syslogd.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 73c681827d86..fb097bc7e596 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)
{
+ /* Jan 18 00:11:22 msg... */
+ /* 01234567890123456 */
+ 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
More information about the busybox
mailing list