Browse Source

* source/filter stats refactoring

master
Alex 'AdUser' Z 6 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
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);
}

4
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);
}

Loading…
Cancel
Save