Skip to content

Commit

Permalink
Avoid blocking read from iphb socket
Browse files Browse the repository at this point in the history
In theory there should be something to read unless it is possible
that glib can call io watch with null condition. Still there is
at least one crash report where dsme process watchdog has killed
mce that was stuck at iphb socket read.

Check validity of io watch id, add explicit test for G_IO_IN and
use nonblocking recv() instead of vanilla read().

[mce] Avoid blocking read from iphb socket. Fixes JB#28990
  • Loading branch information
spiiroin committed May 21, 2015
1 parent 2212b6e commit 9255045
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mce-hbtimer.c
Expand Up @@ -33,6 +33,9 @@
# include "libwakelock.h"
#endif

#include <sys/types.h>
#include <sys/socket.h>

#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
Expand Down Expand Up @@ -703,6 +706,9 @@ mht_iphb_wakeup_cb(GIOChannel *chn, GIOCondition cnd, gpointer data)

gboolean keep_going = FALSE;

if( !mht_iphb_wakeup_watch_id )
goto cleanup_nak;

int fd = g_io_channel_unix_get_fd(chn);

if( fd < 0 )
Expand All @@ -711,9 +717,12 @@ mht_iphb_wakeup_cb(GIOChannel *chn, GIOCondition cnd, gpointer data)
if( cnd & ~G_IO_IN )
goto cleanup_nak;

if( !(cnd & G_IO_IN) )
goto cleanup_ack;

char buf[256];

int rc = read(fd, buf, sizeof buf);
int rc = recv(fd, buf, sizeof buf, MSG_DONTWAIT);

if( rc == 0 ) {
if( !shutting_down )
Expand All @@ -722,7 +731,7 @@ mht_iphb_wakeup_cb(GIOChannel *chn, GIOCondition cnd, gpointer data)
}

if( rc == -1 ) {
if( errno == EINTR || errno == EAGAIN )
if( errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK )
goto cleanup_ack;

mce_log(LL_ERR, "read error: %m");
Expand Down

0 comments on commit 9255045

Please sign in to comment.