This avoids crash in case of UBUS fail. Signed-off-by: Rafał Miłecki <zaj...@gmail.com> --- session/builtin.c | 8 +++++++- session/builtin.h | 19 +++++++++++++++++++ session/main.c | 8 ++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 session/builtin.h
diff --git a/session/builtin.c b/session/builtin.c index 5f299c5..20af633 100644 --- a/session/builtin.c +++ b/session/builtin.c @@ -17,6 +17,7 @@ #include <libubox/blobmsg_json.h> #include <libubus.h> +#include "builtin.h" #include "soap.h" #include "rpc.h" #include "object.h" @@ -261,14 +262,19 @@ void cwmp_add_device_id(node_t *node) xml_add_multi(node, ROXML_ELM_NODE, ARRAY_SIZE(kv), kv, NULL); } -static void __constructor server_init(void) +int server_init(void) { ubus_ctx = ubus_connect(NULL); + if (!ubus_ctx) + return -1; + ubus_lookup_id(ubus_ctx, "cwmp", &cwmp_id); server_load_values(); cwmp_object_add(&server_object, "ManagementServer", NULL); cwmp_object_add(&devinfo_object, "DeviceInfo", NULL); + + return 0; } void cwmp_notify_completed(void) diff --git a/session/builtin.h b/session/builtin.h new file mode 100644 index 0000000..17da3ba --- /dev/null +++ b/session/builtin.h @@ -0,0 +1,19 @@ +/* + * cwmpd - CPE WAN Management Protocol daemon + * Copyright (C) 2014 Felix Fietkau <n...@openwrt.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#ifndef __UCWMP_BUILTIN_H +#define __UCWMP_BUILTIN_H + +int server_init(void); + +#endif diff --git a/session/main.c b/session/main.c index 9cb7127..147c949 100644 --- a/session/main.c +++ b/session/main.c @@ -20,6 +20,7 @@ #include <libubox/blobmsg.h> #include <libubox/blobmsg_json.h> +#include "builtin.h" #include "soap.h" #include "rpc.h" #include "attr.h" @@ -293,8 +294,15 @@ static int load_events(const char *data) int main(int argc, char **argv) { const char *progname = argv[0]; + int err; int ch; + err = server_init(); + if (err) { + fprintf(stderr, "Server init error %d\n", err); + return err; + } + uloop_init(); while ((ch = getopt(argc, argv, "a:d:I:e:m:u:p:")) != -1) { -- 1.8.4.5 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel