[OpenWrt-Devel] [PATCH] [RFC] libubus.h: add ubus_auto_shutdown()

Ben Kelly ben at benjii.net
Tue Feb 2 08:02:59 EST 2016


From: Ben Kelly <ben at benjii.net>

Add ubus_auto_shutdown function, which ensures any pending uloop_timer is cancelled before calling ubus_shutdown on the context. 

This avoids a condition where ubus_shutdown() is called during ubus_auto_connect attempting a reconnection.

Signed-off-by: Ben Kelly <ben at benjii.net>
---
 libubus.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libubus.h b/libubus.h
index 54e7d48..1b219b7 100644
--- a/libubus.h
+++ b/libubus.h
@@ -240,6 +240,12 @@ void ubus_free(struct ubus_context *ctx);
 /* call this only for struct ubus_context pointers initialised by ubus_connect_ctx() */
 void ubus_shutdown(struct ubus_context *ctx);
 
+static inline void ubus_auto_shutdown(struct ubus_auto_conn *conn)
+{
+	uloop_timeout_cancel(&conn->timer);
+	ubus_shutdown(&conn->ctx);
+}
+
 const char *ubus_strerror(int error);
 
 static inline void ubus_add_uloop(struct ubus_context *ctx)
-- 
2.5.0
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list