diff options
| author | Sergey Matveychuk <sem@FreeBSD.org> | 2007-02-06 16:25:27 +0000 |
|---|---|---|
| committer | Sergey Matveychuk <sem@FreeBSD.org> | 2007-02-06 16:25:27 +0000 |
| commit | 14f229309b605af6427393b11fd28207f3aca5ce (patch) | |
| tree | 55553b618e24d755dda930ee37b1567834ad1759 /devel/libpdel/files/patch-util_paction.c | |
| parent | - Update to 0.9 (diff) | |
- Add two patches.
1) Fix a race condition. It prevents UDP sockets/descriptors leak when
active RADIUS authorization used.
2) FSM events processing optimization. System calls nubers reduced
almost twice. (It makes mpd4 faster)
Submitted by: Alexander Motin <mav_at_alkar.net>
Approved by: software developers
Notes
Notes:
svn path=/head/; revision=184379
Diffstat (limited to 'devel/libpdel/files/patch-util_paction.c')
| -rw-r--r-- | devel/libpdel/files/patch-util_paction.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/devel/libpdel/files/patch-util_paction.c b/devel/libpdel/files/patch-util_paction.c new file mode 100644 index 000000000000..d88c55a9ffc9 --- /dev/null +++ b/devel/libpdel/files/patch-util_paction.c @@ -0,0 +1,54 @@ +--- util/paction.c (revision 68) ++++ util/paction.c (working copy) +@@ -39,7 +39,7 @@ + #endif + paction_finish_t *finish; /* action finisher */ + void *arg; /* action argument */ +- u_char started; /* action thread started */ ++ u_char may_cancel; /* ok to cancel action thread */ + u_char canceled; /* action was canceled */ + }; + +@@ -118,10 +118,11 @@ + + /* + * Don't cancel the thread before paction_main() starts, because +- * then paction_cleanup() would never get invoked. Instead, use +- * the 'started' and 'canceled' flags to avoid this race condition. ++ * then paction_cleanup() would never get invoked. Also don't ++ * pthread_cancel() the thread after the handler has completed, ++ * because we might cancel in the middle of the cleanup. + */ +- if (action->started) ++ if (action->may_cancel) + pthread_cancel(action->tid); + + /* Unlock action */ +@@ -139,9 +140,9 @@ + /* Cleanup when thread exits */ + pthread_cleanup_push(paction_cleanup, action); + +- /* Mark thread as started */ +- assert(!action->started); +- action->started = 1; /* race condition ok */ ++ /* Begin allowing pthread_cancel()'s */ ++ assert(!action->may_cancel); ++ action->may_cancel = 1; + + /* Handle race between paction_cancel() and paction_main() */ + if (action->canceled) /* race condition ok */ +@@ -151,6 +152,14 @@ + (*action->handler)(action->arg); + + done:; ++ /* Stop allowing pthread_cancel()'s */ ++ MUTEX_LOCK(&action->mutex, action->mutex_count); ++ action->may_cancel = 0; ++ MUTEX_UNLOCK(&action->mutex, action->mutex_count); ++ ++ /* Consume any last-minute pthread_cancel() still pending */ ++ pthread_testcancel(); ++ + /* Done */ + pthread_cleanup_pop(1); + return (NULL); |
