Skip to content
Snippets Groups Projects
Commit ba1e6b6f authored by Vivek Dutta's avatar Vivek Dutta
Browse files

Added customized timeout option for ubus call

parent aadcbdd5
No related branches found
No related tags found
1 merge request!3Added customized timeout option for ubus call
...@@ -41,13 +41,14 @@ struct global_args_t { ...@@ -41,13 +41,14 @@ struct global_args_t {
const char *dir_path; const char *dir_path;
} global_args; } global_args;
static const char *opt_string = "f:d:h"; static const char *opt_string = "f:d:t:h";
static void show_usage(char *application_name) { static void show_usage(char *application_name) {
fprintf(stdout, fprintf(stdout,
"\nUsage: %s: <options> \n" "\nUsage: %s: <options> \n"
"Options: \n" "Options: \n"
" -t Timeout for ubus call in seconds\n"
" -f json file with ubus objects\n" " -f json file with ubus objects\n"
" -d directory with json files \n" " -d directory with json files \n"
" -h help\n\n", " -h help\n\n",
...@@ -68,6 +69,10 @@ static void parse_command_line_args(int argc, char *argv[]) { ...@@ -68,6 +69,10 @@ static void parse_command_line_args(int argc, char *argv[]) {
global_args.dir_path = optarg; global_args.dir_path = optarg;
break; break;
case 't':
set_ubus_timeout(atoi(optarg));
break;
case 'h': case 'h':
show_usage(argv[0]); show_usage(argv[0]);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
......
...@@ -22,10 +22,15 @@ ...@@ -22,10 +22,15 @@
#include "ubus_call.h" #include "ubus_call.h"
#include <time.h> #include <time.h>
#define UBUS_DEFAULT_TIMEOUT 1500
#define UBUS_DEFAULT_POLL_10_SEC 10000 #define UBUS_DEFAULT_POLL_10_SEC 10000
#define UBUS_DEFAULT_TIMEOUT 1500
struct ubus_context *ctx; struct ubus_context *ctx;
int g_ubus_timeout = UBUS_DEFAULT_TIMEOUT;
void set_ubus_timeout(int timeout) {
g_ubus_timeout = timeout * 1000;
}
int ubus_init(void) { int ubus_init(void) {
...@@ -99,7 +104,7 @@ struct ubus_result *ubus_call(const char *object, const char *method, ...@@ -99,7 +104,7 @@ struct ubus_result *ubus_call(const char *object, const char *method,
rv = ubus_invoke(ctx, obj_id, method, buff.head, rv = ubus_invoke(ctx, obj_id, method, buff.head,
(ubus_data_handler_t)parse_ubus_cb, &json_ubus_result, (ubus_data_handler_t)parse_ubus_cb, &json_ubus_result,
UBUS_DEFAULT_TIMEOUT); g_ubus_timeout);
res = calloc(1, sizeof(struct ubus_result)); res = calloc(1, sizeof(struct ubus_result));
if (!res) if (!res)
...@@ -112,4 +117,4 @@ out: ...@@ -112,4 +117,4 @@ out:
blob_buf_free(&buff); blob_buf_free(&buff);
return res; return res;
} }
\ No newline at end of file
...@@ -13,8 +13,9 @@ struct ubus_result ...@@ -13,8 +13,9 @@ struct ubus_result
}; };
int ubus_init(void); int ubus_init(void);
void set_ubus_timeout(int timeout);
struct ubus_result *ubus_call(const char *object, const char *method, const char *args); struct ubus_result *ubus_call(const char *object, const char *method, const char *args);
#endif /* UBUS_CALL_H */ #endif /* UBUS_CALL_H */
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment