chiark / gitweb /
sd-rtnl: don't fail event handler when callback fails
authorTom Gundersen <teg@jklm.no>
Thu, 29 Jan 2015 06:26:58 +0000 (07:26 +0100)
committerTom Gundersen <teg@jklm.no>
Sat, 31 Jan 2015 14:26:08 +0000 (15:26 +0100)
As in sd-bus, simply log at debug level when a callback fails, but don't fail the event handler.
Otherwise any error returned by any callback will disable the rtnl event handler. We should
only do that on serious internal errors in sd-rtnl that we know cannot be recovered from.

src/libsystemd/sd-rtnl/sd-rtnl.c

index 5778ea5..7f1ec30 100644 (file)
@@ -379,9 +379,12 @@ static int process_timeout(sd_rtnl *rtnl) {
         hashmap_remove(rtnl->reply_callbacks, &c->serial);
 
         r = c->callback(rtnl, m, c->userdata);
+        if (r < 0)
+                log_debug_errno(r, "sd-rtnl: timedout callback failed: %m");
+
         free(c);
 
-        return r < 0 ? r : 1;
+        return 1;
 }
 
 static int process_reply(sd_rtnl *rtnl, sd_rtnl_message *m) {
@@ -404,9 +407,12 @@ static int process_reply(sd_rtnl *rtnl, sd_rtnl_message *m) {
                 prioq_remove(rtnl->reply_callbacks_prioq, c, &c->prioq_idx);
 
         r = c->callback(rtnl, m, c->userdata);
+        if (r < 0)
+                log_debug_errno(r, "sd-rtnl: callback failed: %m");
+
         free(c);
 
-        return r;
+        return 1;
 }
 
 static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) {
@@ -424,12 +430,16 @@ static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) {
         LIST_FOREACH(match_callbacks, c, rtnl->match_callbacks) {
                 if (type == c->type) {
                         r = c->callback(rtnl, m, c->userdata);
-                        if (r != 0)
-                                return r;
+                        if (r != 0) {
+                                if (r < 0)
+                                        log_debug_errno(r, "sd-rtnl: match callback failed: %m");
+
+                                break;
+                        }
                 }
         }
 
-        return 0;
+        return 1;
 }
 
 static int process_running(sd_rtnl *rtnl, sd_rtnl_message **ret) {