Index: main/manager.c =================================================================== --- main/manager.c (revision 173354) +++ main/manager.c (working copy) @@ -173,6 +173,9 @@ 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 */ + /* http-specific variables */ + ast_cond_t file_condition; + unsigned int file_ready:1; AST_LIST_ENTRY(mansession) list; }; @@ -3551,6 +3554,8 @@ AST_LIST_INSERT_HEAD(&sessions, s, list); ast_atomic_fetchadd_int(&num_sessions, 1); AST_LIST_UNLOCK(&sessions); + ast_cond_init(&s->file_condition, NULL); + s->file_ready = 1; } ast_mutex_unlock(&s->__lock); @@ -3560,9 +3565,15 @@ goto generic_callback_out; } + ast_mutex_lock(&s->__lock); + if (!s->file_ready) { + ast_cond_wait(&s->file_condition, &s->__lock); + } s->fd = mkstemp(template); /* create a temporary file for command output */ unlink(template); s->f = fdopen(s->fd, "w+"); + s->file_ready = 0; + ast_mutex_unlock(&s->__lock); for (x = 0, v = params; v && (x < AST_MAX_MANHEADERS); x++, v = v->next) { hdrlen = strlen(v->name) + strlen(v->value) + 3; @@ -3608,6 +3619,7 @@ ast_str_append(&out, 0, ROW_FMT, TEST_STRING); } + /* I should expect that this should never be NULL */ if (s->f != NULL) { /* have temporary output */ char *buf; size_t l = ftell(s->f); @@ -3623,9 +3635,13 @@ } else if (format == FORMAT_XML || format == FORMAT_HTML) { xml_translate(&out, "", params, format); } + ast_mutex_lock(&s->__lock); fclose(s->f); s->f = NULL; s->fd = -1; + s->file_ready = 1; + ast_cond_signal(&s->file_condition); + ast_mutex_unlock(&s->__lock); } if (format == FORMAT_XML) {