diff --git a/main.c b/main.c index e1968d40ad481c8ef5d2a2178b9af8091db75b0a..6be16832b0f0d1558158ad0ee08b66c519207010 100644 --- a/main.c +++ b/main.c @@ -41,13 +41,14 @@ struct global_args_t { const char *dir_path; } 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) { fprintf(stdout, "\nUsage: %s: <options> \n" "Options: \n" + " -t Timeout for ubus call in seconds\n" " -f json file with ubus objects\n" " -d directory with json files \n" " -h help\n\n", @@ -68,6 +69,10 @@ static void parse_command_line_args(int argc, char *argv[]) { global_args.dir_path = optarg; break; + case 't': + set_ubus_timeout(atoi(optarg)); + break; + case 'h': show_usage(argv[0]); exit(EXIT_SUCCESS); diff --git a/ubus_call.c b/ubus_call.c index 354bc8a8b087cfc505f035d759573c5506fcf310..67410ee1254e32bf27250455e9fb5c2c264ffd16 100644 --- a/ubus_call.c +++ b/ubus_call.c @@ -22,10 +22,15 @@ #include "ubus_call.h" #include <time.h> -#define UBUS_DEFAULT_TIMEOUT 1500 #define UBUS_DEFAULT_POLL_10_SEC 10000 +#define UBUS_DEFAULT_TIMEOUT 1500 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) { @@ -99,7 +104,7 @@ struct ubus_result *ubus_call(const char *object, const char *method, rv = ubus_invoke(ctx, obj_id, method, buff.head, (ubus_data_handler_t)parse_ubus_cb, &json_ubus_result, - UBUS_DEFAULT_TIMEOUT); + g_ubus_timeout); res = calloc(1, sizeof(struct ubus_result)); if (!res) @@ -112,4 +117,4 @@ out: blob_buf_free(&buff); return res; -} \ No newline at end of file +} diff --git a/ubus_call.h b/ubus_call.h index cefdc5716994ef1e79f6857c21ab5fe163304f86..14e13d7f30c719c921729ae0dfa0e97bb4e3156f 100644 --- a/ubus_call.h +++ b/ubus_call.h @@ -13,8 +13,9 @@ struct ubus_result }; int ubus_init(void); +void set_ubus_timeout(int timeout); struct ubus_result *ubus_call(const char *object, const char *method, const char *args); -#endif /* UBUS_CALL_H */ \ No newline at end of file +#endif /* UBUS_CALL_H */