Commit bb9515f4 authored by spiiroin's avatar spiiroin

Merge pull request #62 from spiiroin/iowatch

Add error handling to glib io watches
parents fdb153c2 f89a3931
......@@ -106,7 +106,8 @@ int dsmesock_listen(dsmesock_callback* read_and_queue)
if (!(as_chan = g_io_channel_unix_new(fd))) {
goto close_and_fail;
}
if (!g_io_add_watch(as_chan, G_IO_IN, accept_client, as_chan)) {
if (!g_io_add_watch(as_chan, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
accept_client, as_chan)) {
goto close_channel_and_fail;
}
......@@ -135,6 +136,11 @@ static gboolean accept_client(GIOChannel* source,
int newfd;
dsmesock_connection_t* newconn = 0;
if( condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) ) {
dsme_log(LOG_CRIT, "disabling client connect watcher");
return FALSE;
}
newfd = accept(g_io_channel_unix_get_fd(source), 0, 0);
if(newfd == -1) return TRUE;
......@@ -162,7 +168,7 @@ static gboolean accept_client(GIOChannel* source,
if (!(newconn->channel = g_io_channel_unix_new(newfd)) ||
!g_io_add_watch(newconn->channel,
(G_IO_IN | G_IO_ERR | G_IO_HUP),
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
handle_client,
newconn))
{
......@@ -188,7 +194,7 @@ static gboolean handle_client(GIOChannel* source,
keep_connection = false;
}
}
if (condition & (G_IO_ERR | G_IO_HUP)) {
if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
keep_connection = false;
}
......
......@@ -74,7 +74,8 @@ static bool set_up_signal_pipe(void)
if (!(chan = g_io_channel_unix_new(signal_pipe[0]))) {
goto close_and_fail;
}
watch = g_io_add_watch(chan, G_IO_IN, handle_signal, 0);
watch = g_io_add_watch(chan, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
handle_signal, 0);
g_io_channel_unref(chan);
if (!watch) {
goto close_and_fail;
......
......@@ -42,9 +42,9 @@ static gboolean emit_heartbeat_message(GIOChannel* source,
gpointer data)
{
// handle errors
if (condition & (G_IO_ERR | G_IO_HUP)) {
if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
// the wd process has probably died; remove the watch & quit
dsme_log(LOG_DEBUG, "heartbeat: I/O error or HUP");
dsme_log(LOG_CRIT, "heartbeat: I/O error or HUP, terminating");
dsme_main_loop_quit(EXIT_FAILURE);
return false;
}
......@@ -89,7 +89,7 @@ static bool start_heartbeat(void)
goto fail;
}
if (!(watch = g_io_add_watch(chan,
(G_IO_IN | G_IO_ERR | G_IO_HUP),
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
emit_heartbeat_message,
0)))
{
......
......@@ -2406,6 +2406,14 @@ static gboolean epollfd_iowatch_cb(GIOChannel* source,
struct epoll_event events[DSME_MAX_EPOLL_EVENTS];
int nfds;
/* Abandon watch if we get abnorman conditions from glib */
if (condition & ~(G_IO_IN | G_IO_PRI))
{
dsme_log(LOG_ERR, PFIX"epoll waiting I/O error reported");
dsme_log(LOG_CRIT, PFIX"epoll waiting disabled");
return FALSE;
}
dsme_log(LOG_DEBUG, PFIX"epollfd readable");
nfds = epoll_wait(epollfd, events, DSME_MAX_EPOLL_EVENTS, 0);
......@@ -2491,7 +2499,9 @@ static bool epollfd_init(void)
goto cleanup;
}
if( !(epoll_watch = g_io_add_watch(chan, G_IO_IN, epollfd_iowatch_cb, 0)) ) {
if( !(epoll_watch = g_io_add_watch(chan,
G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
epollfd_iowatch_cb, 0)) ) {
goto cleanup;
}
......
......@@ -420,7 +420,9 @@ probe_evdev_device(const char *path)
}
g_io_channel_set_buffered(chan, false);
if( !(watch = g_io_add_watch(chan, G_IO_IN, process_kbevent, 0)) )
if( !(watch = g_io_add_watch(chan,
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
process_kbevent, 0)) )
{
dsme_log(LOG_ERR, PFIX"%s: unable to add io channel watch", path);
goto EXIT;
......
......@@ -181,7 +181,7 @@ static void connect_bme()
if (!(chan = g_io_channel_unix_new(request_fd)) ||
!g_io_add_watch(chan,
(G_IO_IN | G_IO_ERR | G_IO_HUP),
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
handle_battery_temperature_response,
0))
{
......@@ -252,7 +252,7 @@ static gboolean handle_battery_temperature_response(GIOChannel* source,
got_status = false;
}
}
if (condition & (G_IO_ERR | G_IO_HUP)) {
if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
dsme_log(LOG_DEBUG, "bme connection ERR or HUP");
keep_connection = false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment