summaryrefslogtreecommitdiffstats
path: root/src/verify.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-06-14 03:30:17 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-06-14 03:30:17 +0200
commit781538295ff7c056ffb5c19c283cfbacd91b243d (patch)
treeb5fc6f3be42c3839163638e513d315a64ffce550 /src/verify.c
parent7915533147ddaaf5480e52b7d817e11b36348e4a (diff)
downloadfastd-781538295ff7c056ffb5c19c283cfbacd91b243d.tar
fastd-781538295ff7c056ffb5c19c283cfbacd91b243d.zip
Limit the number of concurrent on-verify runs
Diffstat (limited to 'src/verify.c')
-rw-r--r--src/verify.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/verify.c b/src/verify.c
index d875a34..f0dbe55 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -80,6 +80,9 @@ static void * do_verify_thread(void *p) {
free(arg);
+ if (sem_post(&ctx.verify_limit))
+ exit_errno("sem_post");
+
return NULL;
}
@@ -105,6 +108,11 @@ fastd_tristate_t fastd_verify_peer(fastd_peer_t *peer, fastd_socket_t *sock, con
return ret ? fastd_tristate_true : fastd_tristate_false;
}
else {
+ if (sem_trywait(&ctx.verify_limit)) {
+ pr_debug("maximum number of verification processes reached");
+ return fastd_tristate_false;
+ }
+
verify_arg_t *arg = calloc(1, sizeof(verify_arg_t) + data_len);
arg->env = env;
@@ -121,6 +129,9 @@ fastd_tristate_t fastd_verify_peer(fastd_peer_t *peer, fastd_socket_t *sock, con
if ((errno = pthread_create(&thread, &ctx.detached_thread, do_verify_thread, arg)) != 0) {
pr_error_errno("unable to create verify thread");
+ if (sem_post(&ctx.verify_limit))
+ exit_errno("sem_post");
+
fastd_shell_env_free(env);
free(arg);