32 # include <sys/eventfd.h>
35 #include "asterisk/alertpipe.h"
42 int fd = eventfd(0, EFD_NONBLOCK | EFD_SEMAPHORE);
44 alert_pipe[0] = alert_pipe[1] = fd;
48 ast_log(LOG_WARNING,
"Failed to create alert pipe with eventfd(), falling back to pipe(): %s\n",
50 ast_alertpipe_clear(alert_pipe);
56 if (pipe2(alert_pipe, O_NONBLOCK)) {
57 ast_log(LOG_WARNING,
"Failed to create alert pipe: %s\n", strerror(errno));
63 if (pipe(alert_pipe)) {
64 ast_log(LOG_WARNING,
"Failed to create alert pipe: %s\n", strerror(errno));
83 if (alert_pipe[0] == alert_pipe[1]) {
84 if (alert_pipe[0] > -1) {
86 ast_alertpipe_clear(alert_pipe);
93 if (alert_pipe[0] > -1) {
96 if (alert_pipe[1] > -1) {
99 ast_alertpipe_clear(alert_pipe);
106 if (!ast_alertpipe_readable(alert_pipe)) {
107 return AST_ALERT_NOT_READABLE;
110 if (read(alert_pipe[0], &tmp,
sizeof(tmp)) < 0) {
111 if (errno != EINTR && errno != EAGAIN) {
112 ast_log(LOG_WARNING,
"read() failed: %s\n", strerror(errno));
113 return AST_ALERT_READ_FAIL;
117 return AST_ALERT_READ_SUCCESS;
124 if (!ast_alertpipe_writable(alert_pipe)) {
131 return write(alert_pipe[1], &tmp,
sizeof(tmp)) !=
sizeof(tmp);
139 if (!ast_alertpipe_readable(alert_pipe)) {
140 return AST_ALERT_NOT_READABLE;
145 bytes_read = read(alert_pipe[0], tmp,
sizeof(tmp));
146 if (bytes_read < 0) {
147 if (errno == EINTR) {
150 if (errno == EAGAIN || errno == EWOULDBLOCK) {
157 ast_log(LOG_WARNING,
"read() failed flushing alertpipe: %s\n",
159 return AST_ALERT_READ_FAIL;
167 return AST_ALERT_READ_SUCCESS;
Asterisk main include file. File version handling, generic pbx functions.
void ast_alertpipe_close(int alert_pipe[2])
Close an alert pipe.
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
ast_alert_status_t ast_alertpipe_read(int alert_pipe[2])
Read an event from an alert pipe.
int ast_alertpipe_init(int alert_pipe[2])
Initialize an alert pipe.
Support for logging to various files, console and syslog Configuration in file logger.conf.
ast_alert_status_t ast_alertpipe_flush(int alert_pipe[2])
Consume all alerts written to the alert pipe.
ssize_t ast_alertpipe_write(int alert_pipe[2])
Write an event to an alert pipe.