OSDN Git Service

core: Fix handling mgmt socket write failures
authorJohan Hedberg <johan.hedberg@intel.com>
Tue, 15 Jan 2013 17:46:04 +0000 (19:46 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 15 Jan 2013 17:46:09 +0000 (19:46 +0200)
If a write to the socket fails we should properly notify the command
callback and remove the command from the queue.

src/shared/mgmt.c

index c41454b..f96897d 100644 (file)
@@ -27,6 +27,8 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#include <string.h>
+#include <errno.h>
 
 #include <glib.h>
 
@@ -155,8 +157,13 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond,
 
        bytes_written = write(mgmt->fd, request->buf, request->len);
        if (bytes_written < 0) {
-               g_queue_push_head(mgmt->request_queue, request);
-               return FALSE;
+               util_debug(mgmt->debug_callback, mgmt->debug_data,
+                               "write failed: %s", strerror(errno));
+               if (request->callback)
+                       request->callback(MGMT_STATUS_FAILED, 0, NULL,
+                                                       request->user_data);
+               destroy_request(request, NULL);
+               return TRUE;
        }
 
        util_debug(mgmt->debug_callback, mgmt->debug_data,