Skip to content

Commit 70ca876

Browse files
make the timestamp more clear for dnsmasaq log
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
1 parent 5a525c1 commit 70ca876

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/log.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,22 @@ const char *debugstr(const enum debug_flag flag)
337337
// Write a dnsmasq log line to pihole.log in dnsmasq's exact on-disk format.
338338
// The message is the bare body (no timestamp, no prefix) as handed to
339339
// FTL_dnsmasq_log() from my_syslog(). We reproduce dnsmasq's format:
340-
// "Mon Jan 1 12:00:00 2024 dnsmasq-dhcp[12345]: <message>\n"
340+
// "Jan 1 12:00:00 dnsmasq-dhcp[12345]: <message>\n"
341341
// where the func suffix (e.g. "-dhcp", "-tftp") comes from the priority
342342
// bits extracted in my_syslog().
343343
void FTL_write_dnsmasq_log(const char *message, const char *func)
344344
{
345345
if(dnsmasq_log.fd == -1)
346346
return;
347347

348+
struct tm tm;
348349
time_t now = time(NULL);
349-
char *ts = ctime(&now);
350+
localtime_r(&now, &tm);
351+
char ts_buf[16];
352+
strftime(ts_buf, sizeof(ts_buf), "%b %e %H:%M:%S", &tm);
350353

351354
char line[2048];
352-
int off = snprintf(line, sizeof(line), "%.20s dnsmasq%s[%d]: ", ts + 4, func ? func : "", getpid());
355+
int off = snprintf(line, sizeof(line), "%s dnsmasq%s[%d]: ", ts_buf, func ? func : "", getpid());
353356

354357
const char *msg = message ? message : "";
355358
off += snprintf(line + off, sizeof(line) - off, "%s", msg);

0 commit comments

Comments
 (0)