diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-06-11 20:33:14 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-06-11 20:33:14 +0200 |
commit | 8fc9066ee62d17cdb76bc064c945da3bb0d2e2a3 (patch) | |
tree | bfde54b1611023e42a918bbd1911b874a6d0bff2 | |
parent | 9163f4673d919658c94f9de4ca32a2e9dacce2fd (diff) | |
download | conntrack-tools-8fc9066ee62d17cdb76bc064c945da3bb0d2e2a3.tar.gz conntrack-tools-8fc9066ee62d17cdb76bc064c945da3bb0d2e2a3.zip |
conntrackd: add support to display statistics on existing child processes
This patch adds the ability to dump the list of existing child
processes. In general, it would be hard to display one since
child processes are generally forked for very specific tasks,
like commit and flush operations, and they have very limited
lifetime. However, this can be handy for debugging problems.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | conntrackd.8 | 3 | ||||
-rw-r--r-- | include/conntrackd.h | 1 | ||||
-rw-r--r-- | include/process.h | 2 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/process.c | 25 | ||||
-rw-r--r-- | src/run.c | 3 |
6 files changed, 37 insertions, 1 deletions
diff --git a/conntrackd.8 b/conntrackd.8 index cf15044..1342c22 100644 --- a/conntrackd.8 +++ b/conntrackd.8 @@ -44,11 +44,12 @@ option will not flush your internal and external cache). .BI "-k " Kill the daemon .TP -.BI "-s " "[|network|cache|runtime|link|queue]" +.BI "-s " "[|network|cache|runtime|link|queue|process]" Dump statistics. If no parameter is passed, it displays the general statistics. If "network" is passed as parameter it displays the networking statistics. If "cache" is passed as parameter, it shows the extended cache statistics. If "runtime" is passed as parameter, it shows the run-time statistics. +If "process" is passed as parameter, it shows existing child processes (if any). .TP .BI "-R " Force a resync against the kernel connection tracking table diff --git a/include/conntrackd.h b/include/conntrackd.h index 7a63f97..04dc611 100644 --- a/include/conntrackd.h +++ b/include/conntrackd.h @@ -34,6 +34,7 @@ #define STATS_QUEUE 32 /* queue stats */ #define FLUSH_INT_CACHE 33 /* flush internal cache */ #define FLUSH_EXT_CACHE 34 /* flush external cache */ +#define STATS_PROCESS 35 /* child process stats */ #define DEFAULT_CONFIGFILE "/etc/conntrackd/conntrackd.conf" #define DEFAULT_LOCKFILE "/var/lock/conntrackd.lock" diff --git a/include/process.h b/include/process.h index 9d29f22..41c7c10 100644 --- a/include/process.h +++ b/include/process.h @@ -5,6 +5,7 @@ enum process_type { CTD_PROC_ANY, /* any type */ CTD_PROC_FLUSH, /* flush process */ CTD_PROC_COMMIT, /* commit process */ + CTD_PROC_MAX }; #define CTD_PROC_F_EXCL (1 << 0) /* only one process at a time */ @@ -19,5 +20,6 @@ struct child_process { int fork_process_new(int type, int flags, void (*cb)(void *data), void *data); int fork_process_delete(int pid); +void fork_process_dump(int fd); #endif @@ -214,6 +214,10 @@ int main(int argc, char *argv[]) strlen(argv[i+1])) == 0) { action = STATS_QUEUE; i++; + } else if (strncmp(argv[i+1], "process", + strlen(argv[i+1])) == 0) { + action = STATS_PROCESS; + i++; } else { fprintf(stderr, "ERROR: unknown " "parameter `%s' for " diff --git a/src/process.c b/src/process.c index c378f7a..9b9734c 100644 --- a/src/process.c +++ b/src/process.c @@ -76,3 +76,28 @@ int fork_process_delete(int pid) } return 0; } + +static const char *process_type_to_name[CTD_PROC_MAX] = { + [CTD_PROC_ANY] = "any", + [CTD_PROC_FLUSH] = "flush", + [CTD_PROC_COMMIT] = "commit", +}; + +void fork_process_dump(int fd) +{ + struct child_process *this; + char buf[4096]; + int size = 0; + + sigprocmask(SIG_BLOCK, &STATE(block), NULL); + list_for_each_entry(this, &process_list, head) { + size += snprintf(buf+size, sizeof(buf), + "PID=%u type=%s\n", + this->pid, + this->type < CTD_PROC_MAX ? + process_type_to_name[this->type] : "unknown"); + } + sigprocmask(SIG_UNBLOCK, &STATE(block), NULL); + + send(fd, buf, size, 0); +} @@ -216,6 +216,9 @@ void local_handler(int fd, void *data) case STATS_RUNTIME: dump_stats_runtime(fd); return; + case STATS_PROCESS: + fork_process_dump(fd); + return; } if (!STATE(mode)->local(fd, type, data)) |