From 2a655f276fc5ad19fca9530b734423c6f156538d Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 17 Jun 2024 14:33:54 +1000 Subject: [PATCH] * source/filter stats refactoring --- src/sources/files.c | 15 +++++---------- src/sources/portknock.c | 4 ++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/sources/files.c b/src/sources/files.c index 5d2b7de..df75974 100644 --- a/src/sources/files.c +++ b/src/sources/files.c @@ -229,14 +229,11 @@ next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { bool stats(cfg_t *cfg, char *buf, size_t bufsize) { - struct tm tm; char tmp[PATH_MAX + 512]; - char mtime[30]; + time_t mtime; const char *fmt = "- path: %s\n" - " mtime: %s\n" - " file: fd=%d inode=%d size=%ld pos=%ld tag=%08X\n" - " read: %lu lines\n"; + " info: fd=%d inode=%d size=%ld pos=%ld tag=%08X readl=%lu mtime=%lu\n"; int fd, ino; off_t sz; long pos; assert(cfg != NULL); assert(buf != NULL); @@ -248,13 +245,11 @@ stats(cfg_t *cfg, char *buf, size_t bufsize) { for (f2b_file_t *f = cfg->files; f != NULL; f = f->next) { if (f->fd) { fd = fileno(f->fd), ino = f->st.st_ino, sz = f->st.st_size, pos = ftell(f->fd); - localtime_r(&f->st.st_mtime, &tm); - strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", &tm); + mtime = f->st.st_mtime; } else { - fd = -1, ino = -1, sz = 0, pos = -1; - strlcpy(mtime, "-", sizeof(mtime)); + fd = -1, ino = -1, sz = 0, pos = -1, mtime = 0; } - snprintf(tmp, sizeof(tmp), fmt, f->path, mtime, fd, ino, sz, pos, f->stag, f->lines); + snprintf(tmp, sizeof(tmp), fmt, f->path, fd, ino, sz, pos, f->stag, f->lines, mtime); strlcat(buf, tmp, bufsize); } diff --git a/src/sources/portknock.c b/src/sources/portknock.c index 06d01f0..39ff13f 100644 --- a/src/sources/portknock.c +++ b/src/sources/portknock.c @@ -208,14 +208,14 @@ stats(cfg_t *cfg, char *buf, size_t bufsize) { char tmp[256]; const char *fmt = "- listen: %s:%s\n" - " accepts: %u\n"; + " info: tag=%08X sock=%ld accepts=%u\n"; assert(cfg != NULL); if (buf == NULL || bufsize == 0) return false; for (f2b_port_t *p = cfg->ports; p != NULL; p = p->next) { - snprintf(tmp, sizeof(tmp), fmt, p->host, p->port, p->accepts); + snprintf(tmp, sizeof(tmp), fmt, p->host, p->port, p->stag, p->sock, p->accepts); strlcat(buf, tmp, bufsize); }