ubus_connect_ctx() is equivalent to ubus_connect() but accepts a
pointer to a previously allocated ubus_context struct.
ubus_shutdown() is made available as an alternative to ubus_free()
to clean up contexts initialised by ubus_connect_ctx().
Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
-static int _ubus_connect(struct ubus_context *ctx, const char *path)
+int ubus_connect_ctx(struct ubus_context *ctx, const char *path)
+ memset(ctx, 0, sizeof(*ctx));
+
ctx->sock.fd = -1;
ctx->sock.cb = ubus_handle_data;
ctx->connection_lost = ubus_default_connection_lost;
ctx->sock.fd = -1;
ctx->sock.cb = ubus_handle_data;
ctx->connection_lost = ubus_default_connection_lost;
{
struct ubus_auto_conn *conn = container_of(timeout, struct ubus_auto_conn, timer);
{
struct ubus_auto_conn *conn = container_of(timeout, struct ubus_auto_conn, timer);
- if (_ubus_connect(&conn->ctx, conn->path)) {
+ if (ubus_connect_ctx(&conn->ctx, conn->path)) {
uloop_timeout_set(timeout, 1000);
fprintf(stderr, "failed to connect to ubus\n");
return;
uloop_timeout_set(timeout, 1000);
fprintf(stderr, "failed to connect to ubus\n");
return;
- if (_ubus_connect(ctx, path)) {
+ if (ubus_connect_ctx(ctx, path)) {
-void ubus_free(struct ubus_context *ctx)
+void ubus_shutdown(struct ubus_context *ctx)
{
blob_buf_free(&b);
close(ctx->sock.fd);
free(ctx->msgbuf.data);
{
blob_buf_free(&b);
close(ctx->sock.fd);
free(ctx->msgbuf.data);
+}
+
+void ubus_free(struct ubus_context *ctx)
+{
+ ubus_shutdown(ctx);
};
struct ubus_context *ubus_connect(const char *path);
};
struct ubus_context *ubus_connect(const char *path);
+int ubus_connect_ctx(struct ubus_context *ctx, const char *path);
void ubus_auto_connect(struct ubus_auto_conn *conn);
int ubus_reconnect(struct ubus_context *ctx, const char *path);
void ubus_auto_connect(struct ubus_auto_conn *conn);
int ubus_reconnect(struct ubus_context *ctx, const char *path);
+
+/* call this only for struct ubus_context pointers returned by ubus_connect() */
void ubus_free(struct ubus_context *ctx);
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);
+
const char *ubus_strerror(int error);
static inline void ubus_add_uloop(struct ubus_context *ctx)
const char *ubus_strerror(int error);
static inline void ubus_add_uloop(struct ubus_context *ctx)