aboutsummaryrefslogtreecommitdiffstats
path: root/main/manager.c
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-02 17:37:52 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-02 17:37:52 +0000
commit61548327a02d4b8f58c827b32ef8415b67b9285c (patch)
tree76f0a77b6696dfe8b1204af0375d5ae2be1e764d /main/manager.c
parentc486146d44832fca22892f36aed51f2cfea53d55 (diff)
Merged revisions 112469 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r112469 | mmichelson | 2008-04-02 12:36:49 -0500 (Wed, 02 Apr 2008) | 21 lines Merged revisions 112468 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r112468 | mmichelson | 2008-04-02 12:36:04 -0500 (Wed, 02 Apr 2008) | 13 lines Fix a race condition in the manager. It is possible that a new manager event could be appended during a brief time when the manager is not waiting for input. If an event comes during this period, we need to set an indicator that there is an event pending so that the manager doesn't attempt to wait forever for an event that already happened. (closes issue #12354) Reported by: bamby Patches: manager_race_condition.diff uploaded by bamby (license 430) (comments added by me) ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@112470 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/manager.c')
-rw-r--r--main/manager.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/main/manager.c b/main/manager.c
index 4ef298ddb..5be4cec1c 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -167,6 +167,7 @@ struct mansession {
int send_events; /*!< XXX what ? */
struct eventqent *last_ev; /*!< last event processed. */
int writetimeout; /*!< Timeout for ast_carefulwrite() */
+ int pending_event; /*!< Pending events indicator in case when waiting_thread is NULL */
AST_LIST_ENTRY(mansession) list;
};
@@ -2753,6 +2754,11 @@ static int get_input(struct mansession *s, char *output)
while (res == 0) {
/* XXX do we really need this locking ? */
ast_mutex_lock(&s->__lock);
+ if (s->pending_event) {
+ s->pending_event = 0;
+ ast_mutex_unlock(&s->__lock);
+ return 0;
+ }
s->waiting_thread = pthread_self();
ast_mutex_unlock(&s->__lock);
@@ -2993,6 +2999,13 @@ int __manager_event(int category, const char *event,
ast_mutex_lock(&s->__lock);
if (s->waiting_thread != AST_PTHREADT_NULL)
pthread_kill(s->waiting_thread, SIGURG);
+ else
+ /* We have an event to process, but the mansession is
+ * not waiting for it. We still need to indicate that there
+ * is an event waiting so that get_input processes the pending
+ * event instead of polling.
+ */
+ s->pending_event = 1;
ast_mutex_unlock(&s->__lock);
}
AST_LIST_UNLOCK(&sessions);