Index: main/utils.c =================================================================== --- main/utils.c (revision 172437) +++ main/utils.c (working copy) @@ -950,11 +950,11 @@ } /* This was an acceptable error, go back into poll() */ continue; + } else if (errno != EPIPE) { + /* Fatal error, bail. */ + ast_log(LOG_ERROR, "poll returned error: %s\n", strerror(errno)); } - /* Fatal error, bail. */ - ast_log(LOG_ERROR, "poll returned error: %s\n", strerror(errno)); - return -1; } } Index: main/manager.c =================================================================== --- main/manager.c (revision 172437) +++ main/manager.c (working copy) @@ -181,6 +181,7 @@ struct eventqent *eventq; /* Timeout for ast_carefulwrite() */ int writetimeout; + int needclose; /*!< Boolean, indicating that the client has closed, but we still have things to write */ int pending_event; /*!< Pending events indicator in case when waiting_thread is NULL */ AST_LIST_ENTRY(mansession) list; }; @@ -2128,8 +2129,9 @@ if ((s->authenticated && (s->readperm & eqe->category) == eqe->category) && ((s->send_events & eqe->category) == eqe->category)) { if (s->fd > -1) { - if (!ret && ast_carefulwrite(s->fd, eqe->eventdata, strlen(eqe->eventdata), s->writetimeout) < 0) - ret = -1; + if (!ret && !s->needclose && ast_carefulwrite(s->fd, eqe->eventdata, strlen(eqe->eventdata), s->writetimeout) < 0) { + s->needclose = 1; + } } else if (!s->outputstr && !(s->outputstr = ast_calloc(1, sizeof(*s->outputstr)))) ret = -1; else @@ -2287,7 +2289,14 @@ s->waiting_thread = pthread_self(); ast_mutex_unlock(&s->__lock); - res = poll(fds, 1, -1); + /* If the pipe is closed, read only those events still queued */ + if (s->needclose) { + if ((res = poll(fds, 1, s->writetimeout)) == 0) { + res = -1; + } + } else { + res = poll(fds, 1, -1); + } ast_mutex_lock(&s->__lock); s->waiting_thread = AST_PTHREADT_NULL;