projects
/
project
/
ubus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
change socket permission to allow !root users to connect
[project/ubus.git]
/
libubus.c
diff --git
a/libubus.c
b/libubus.c
index 18267bbe0148665f4399b7e5a3c6c98ceb6d8570..ccaa0690d840b26d106d3fcbb8d847b76bbf1ffa 100644
(file)
--- a/
libubus.c
+++ b/
libubus.c
@@
-271,8
+271,10
@@
static void ubus_default_connection_lost(struct ubus_context *ctx)
uloop_end();
}
uloop_end();
}
-
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;
@@
-316,7
+318,7
@@
static void ubus_auto_connect_cb(struct uloop_timeout *timeout)
{
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;
@@
-341,7
+343,7
@@
struct ubus_context *ubus_connect(const char *path)
if (!ctx)
return NULL;
if (!ctx)
return NULL;
- if (
_ubus_connect
(ctx, path)) {
+ if (
ubus_connect_ctx
(ctx, path)) {
free(ctx);
ctx = NULL;
}
free(ctx);
ctx = NULL;
}
@@
-349,10
+351,15
@@
struct ubus_context *ubus_connect(const char *path)
return ctx;
}
return ctx;
}
-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);
free(ctx);
}
free(ctx);
}