summaryrefslogtreecommitdiff
path: root/src/process.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2009-05-23 12:09:06 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2009-05-23 12:09:06 +0200
commit0374398fd14bf587d80d9d31e361e266e69387c8 (patch)
tree2984629205760d10660fa43c237073e555ce03c8 /src/process.c
parent91bf01ee31b754bb17f612ee13685ef0ffe9baa8 (diff)
downloadconntrack-tools-0374398fd14bf587d80d9d31e361e266e69387c8.tar.gz
conntrack-tools-0374398fd14bf587d80d9d31e361e266e69387c8.zip
conntrackd: add child process infrastructure
This patch adds a simple infrastructure that allows to account the child processes that have been forked. This also includes a callback handler that can be registered that is called once the child process finishes. We can extended this later to include an alarm to limit the maximum lifetime of a forked child process. This is good to ensure that child processes behave timely. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/process.c b/src/process.c
new file mode 100644
index 0000000..a89f388
--- /dev/null
+++ b/src/process.c
@@ -0,0 +1,55 @@
+/*
+ * (C) 2009 by Pablo Neira Ayuso <pablo@netfilter.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "conntrackd.h"
+#include "process.h"
+
+static LIST_HEAD(process_list);
+
+int fork_process_new(void (*cb)(void *data), void *data)
+{
+ struct child_process *c;
+
+ c = calloc(sizeof(struct child_process), 1);
+ if (c == NULL)
+ return -1;
+
+ c->cb = cb;
+ c->data = data;
+
+ list_add(&c->head, &process_list);
+
+ return fork();
+}
+
+int fork_process_delete(int pid)
+{
+ struct child_process *this, *tmp;
+
+ list_for_each_entry_safe(this, tmp, &process_list, head) {
+ if (this->pid == pid) {
+ list_del(&this->head);
+ if (this->cb) {
+ this->cb(this->data);
+ }
+ free(this);
+ return 1;
+ }
+ }
+ return 0;
+}