Skip to content
Snippets Groups Projects
Commit d23bf7f1 authored by Anjan Chanda's avatar Anjan Chanda
Browse files

create event thread after valid ubus context

parent 37559443
No related branches found
No related tags found
1 merge request!1Receive easysoc/notify netlink events
Pipeline #1606 passed with warnings
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#define NETLINK_FAMILY_NAME "easysoc" #define NETLINK_FAMILY_NAME "easysoc"
#define NETLINK_GROUP_NAME "notify" #define NETLINK_GROUP_NAME "notify"
#define MAX_MSG 128 #define MAX_MSG 512
/* nl attributes */ /* nl attributes */
enum { enum {
...@@ -52,12 +52,13 @@ static struct nlattr *attrs[__XDSL_NL_MAX]; ...@@ -52,12 +52,13 @@ static struct nlattr *attrs[__XDSL_NL_MAX];
static int dslmngr_ubus_event(struct ubus_context *ctx, char *message) static int dslmngr_ubus_event(struct ubus_context *ctx, char *message)
{ {
static struct blob_buf b; char data[MAX_MSG] = {0};
char event[32]; char event[32] = {0};
char data[128]; struct blob_buf b;
sscanf(message, "%s '%[^\n]s'", event, data); sscanf(message, "%s '%[^\n]s'", event, data);
memset(&b, 0, sizeof(b));
blob_buf_init(&b, 0); blob_buf_init(&b, 0);
if (!blobmsg_add_json_from_string(&b, data)) { if (!blobmsg_add_json_from_string(&b, data)) {
...@@ -65,17 +66,20 @@ static int dslmngr_ubus_event(struct ubus_context *ctx, char *message) ...@@ -65,17 +66,20 @@ static int dslmngr_ubus_event(struct ubus_context *ctx, char *message)
return -1; return -1;
} }
return ubus_send_event(ctx, event, b.head); ubus_send_event(ctx, event, b.head);
blob_buf_free(&b);
return 0;
} }
static int dslmngr_nl_to_ubus_event(struct nl_msg *msg, void *arg) static int dslmngr_nl_to_ubus_event(struct nl_msg *msg, void *arg)
{ {
struct nlmsghdr *nlh = nlmsg_hdr(msg); struct nlmsghdr *nlh = nlmsg_hdr(msg);
struct ubus_context *ctx = (struct ubus_context *)arg; struct ubus_context *ctx = (struct ubus_context *)arg;
char *message; char message[MAX_MSG] = {0};
int ret; int ret;
if (!genlmsg_valid_hdr(nlh, 0)){ if (!genlmsg_valid_hdr(nlh, 0)) {
fprintf(stderr, "received invalid message\n"); fprintf(stderr, "received invalid message\n");
return 0; return 0;
} }
...@@ -83,7 +87,9 @@ static int dslmngr_nl_to_ubus_event(struct nl_msg *msg, void *arg) ...@@ -83,7 +87,9 @@ static int dslmngr_nl_to_ubus_event(struct nl_msg *msg, void *arg)
ret = genlmsg_parse(nlh, 0, attrs, XDSL_NL_MSG, nl_notify_policy); ret = genlmsg_parse(nlh, 0, attrs, XDSL_NL_MSG, nl_notify_policy);
if (!ret) { if (!ret) {
if (attrs[XDSL_NL_MSG] ) { if (attrs[XDSL_NL_MSG] ) {
message = nla_get_string(attrs[XDSL_NL_MSG]); memcpy(message, nla_get_string(attrs[XDSL_NL_MSG]),
nla_len(attrs[XDSL_NL_MSG]));
dslmngr_ubus_event(ctx, message); dslmngr_ubus_event(ctx, message);
} }
} }
......
...@@ -58,7 +58,7 @@ int main(int argc, char **argv) ...@@ -58,7 +58,7 @@ int main(int argc, char **argv)
pthread_t evtid; pthread_t evtid;
pthread_attr_t attr; pthread_attr_t attr;
while ((ch = getopt(argc, argv, "cs:")) != -1) { while ((ch = getopt(argc, argv, "s:")) != -1) {
switch (ch) { switch (ch) {
case 's': case 's':
ubus_socket = optarg; ubus_socket = optarg;
...@@ -79,11 +79,6 @@ int main(int argc, char **argv) ...@@ -79,11 +79,6 @@ int main(int argc, char **argv)
pthread_attr_setschedparam(&attr, &sp); pthread_attr_setschedparam(&attr, &sp);
} }
if (pthread_create(&evtid, &attr, &dslmngr_event_main, ctx) != 0)
fprintf(stderr, "dslmngr: event thread create error!\n");
/* dslmngr_cmd_main(ctx); */
uloop_init(); uloop_init();
ctx = ubus_connect(ubus_socket); ctx = ubus_connect(ubus_socket);
if (!ctx) { if (!ctx) {
...@@ -93,6 +88,11 @@ int main(int argc, char **argv) ...@@ -93,6 +88,11 @@ int main(int argc, char **argv)
ubus_add_uloop(ctx); ubus_add_uloop(ctx);
if (pthread_create(&evtid, &attr, &dslmngr_event_main, ctx) != 0)
fprintf(stderr, "dslmngr: event thread create error!\n");
/* dslmngr_cmd_main(ctx); */
if (dsl_add_ubus_objects(ctx) != 0) if (dsl_add_ubus_objects(ctx) != 0)
goto __ret; goto __ret;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment