summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2009-06-11 20:33:14 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2009-06-11 20:33:14 +0200
commit8fc9066ee62d17cdb76bc064c945da3bb0d2e2a3 (patch)
treebfde54b1611023e42a918bbd1911b874a6d0bff2 /src
parent9163f4673d919658c94f9de4ca32a2e9dacce2fd (diff)
downloadconntrack-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>
Diffstat (limited to 'src')
-rw-r--r--src/main.c4
-rw-r--r--src/process.c25
-rw-r--r--src/run.c3
3 files changed, 32 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 7507ae5..6b320d1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
+}
diff --git a/src/run.c b/src/run.c
index fe81d54..95d51a2 100644
--- a/src/run.c
+++ b/src/run.c
@@ -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))