Browse Source

* source/filter stats refactoring

master
Alex 'AdUser' Z 5 months ago
parent
commit
2a655f276f
  1. 15
      src/sources/files.c
  2. 4
      src/sources/portknock.c

15
src/sources/files.c

@ -229,14 +229,11 @@ next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) {
bool bool
stats(cfg_t *cfg, char *buf, size_t bufsize) { stats(cfg_t *cfg, char *buf, size_t bufsize) {
struct tm tm;
char tmp[PATH_MAX + 512]; char tmp[PATH_MAX + 512];
char mtime[30]; time_t mtime;
const char *fmt = const char *fmt =
"- path: %s\n" "- path: %s\n"
" mtime: %s\n" " info: fd=%d inode=%d size=%ld pos=%ld tag=%08X readl=%lu mtime=%lu\n";
" file: fd=%d inode=%d size=%ld pos=%ld tag=%08X\n"
" read: %lu lines\n";
int fd, ino; off_t sz; long pos; int fd, ino; off_t sz; long pos;
assert(cfg != NULL); assert(cfg != NULL);
assert(buf != 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) { for (f2b_file_t *f = cfg->files; f != NULL; f = f->next) {
if (f->fd) { if (f->fd) {
fd = fileno(f->fd), ino = f->st.st_ino, sz = f->st.st_size, pos = ftell(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); mtime = f->st.st_mtime;
strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", &tm);
} else { } else {
fd = -1, ino = -1, sz = 0, pos = -1; fd = -1, ino = -1, sz = 0, pos = -1, mtime = 0;
strlcpy(mtime, "-", sizeof(mtime));
} }
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); strlcat(buf, tmp, bufsize);
} }

4
src/sources/portknock.c

@ -208,14 +208,14 @@ stats(cfg_t *cfg, char *buf, size_t bufsize) {
char tmp[256]; char tmp[256];
const char *fmt = const char *fmt =
"- listen: %s:%s\n" "- listen: %s:%s\n"
" accepts: %u\n"; " info: tag=%08X sock=%ld accepts=%u\n";
assert(cfg != NULL); assert(cfg != NULL);
if (buf == NULL || bufsize == 0) if (buf == NULL || bufsize == 0)
return false; return false;
for (f2b_port_t *p = cfg->ports; p != NULL; p = p->next) { 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); strlcat(buf, tmp, bufsize);
} }

Loading…
Cancel
Save