diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-06-11 19:34:50 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2009-06-11 19:34:50 +0200 |
commit | 5e696e022d8383bc7abe6e6ba37c2664679fe81f (patch) | |
tree | 34ab3159dda9efbdf352236a60a1b1236eb17525 /src/process.c | |
parent | 0121fd74b805a6490f005c835b3994fa06487395 (diff) | |
download | conntrack-tools-5e696e022d8383bc7abe6e6ba37c2664679fe81f.tar.gz conntrack-tools-5e696e022d8383bc7abe6e6ba37c2664679fe81f.zip |
conntrackd: allow to limit the number of simultaneous child processes
This patch allows to limit the number of simultaneous child processes.
This is required by the next patch that replaces disposable handlers
to commit and flush with permanent handlers.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/process.c')
-rw-r--r-- | src/process.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/process.c b/src/process.c index 31e6e6f..c378f7a 100644 --- a/src/process.c +++ b/src/process.c @@ -22,20 +22,32 @@ static LIST_HEAD(process_list); -int fork_process_new(void (*cb)(void *data), void *data) +int fork_process_new(int type, int flags, void (*cb)(void *data), void *data) { - struct child_process *c; + struct child_process *c, *this; int pid; /* block SIGCHLD to avoid the access of the list concurrently */ sigprocmask(SIG_BLOCK, &STATE(block), NULL); + /* We only want one process of this type at the same time. This is + * useful if you want to prevent two child processes from accessing + * a shared descriptor at the same time. */ + if (flags & CTD_PROC_F_EXCL) { + list_for_each_entry(this, &process_list, head) { + if (this->type == type) { + sigprocmask(SIG_UNBLOCK, &STATE(block), NULL); + return -1; + } + } + } c = calloc(sizeof(struct child_process), 1); if (c == NULL) { sigprocmask(SIG_UNBLOCK, &STATE(block), NULL); return -1; } + c->type = type; c->cb = cb; c->data = data; c->pid = pid = fork(); |