exec: increase maximum execution time to 120s
Increase the maximum possible execution time to 120 seconds and add a new command line flag `-t` which allows overwriting the default value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
41333abee4
commit
ecd1660f17
3 changed files with 19 additions and 3 deletions
2
exec.c
2
exec.c
|
@ -350,7 +350,7 @@ rpc_exec(const char **args, rpc_exec_write_cb_t in,
|
||||||
uloop_process_add(&c->process);
|
uloop_process_add(&c->process);
|
||||||
|
|
||||||
c->timeout.cb = rpc_exec_timeout_cb;
|
c->timeout.cb = rpc_exec_timeout_cb;
|
||||||
uloop_timeout_set(&c->timeout, RPC_EXEC_MAX_RUNTIME);
|
uloop_timeout_set(&c->timeout, exec_timeout);
|
||||||
|
|
||||||
if (c->stdin_cb)
|
if (c->stdin_cb)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <libubox/ustream.h>
|
#include <libubox/ustream.h>
|
||||||
|
|
||||||
#define RPC_EXEC_MAX_SIZE (4096 * 64)
|
#define RPC_EXEC_MAX_SIZE (4096 * 64)
|
||||||
#define RPC_EXEC_MAX_RUNTIME (30 * 1000)
|
#define RPC_EXEC_DEFAULT_TIMEOUT (120 * 1000)
|
||||||
|
|
||||||
#define ustream_for_each_read_buffer(stream, ptr, len) \
|
#define ustream_for_each_read_buffer(stream, ptr, len) \
|
||||||
for (ptr = ustream_get_read_buf(stream, &len); \
|
for (ptr = ustream_get_read_buf(stream, &len); \
|
||||||
|
@ -50,6 +50,7 @@
|
||||||
ustream_fd_init(&us, fd); \
|
ustream_fd_init(&us, fd); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
extern int exec_timeout;
|
||||||
|
|
||||||
typedef int (*rpc_exec_write_cb_t)(struct ustream *, void *);
|
typedef int (*rpc_exec_write_cb_t)(struct ustream *, void *);
|
||||||
typedef int (*rpc_exec_read_cb_t)(struct blob_buf *, char *, int, void *);
|
typedef int (*rpc_exec_read_cb_t)(struct blob_buf *, char *, int, void *);
|
||||||
|
|
17
main.c
17
main.c
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <libubox/blobmsg_json.h>
|
#include <libubox/blobmsg_json.h>
|
||||||
#include <libubus.h>
|
#include <libubus.h>
|
||||||
|
@ -32,6 +33,8 @@
|
||||||
static struct ubus_context *ctx;
|
static struct ubus_context *ctx;
|
||||||
static bool respawn = false;
|
static bool respawn = false;
|
||||||
|
|
||||||
|
int exec_timeout = RPC_EXEC_DEFAULT_TIMEOUT;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_signal(int sig)
|
handle_signal(int sig)
|
||||||
{
|
{
|
||||||
|
@ -64,16 +67,28 @@ int main(int argc, char **argv)
|
||||||
const char *ubus_socket = NULL;
|
const char *ubus_socket = NULL;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "s:")) != -1) {
|
while ((ch = getopt(argc, argv, "s:t:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 's':
|
case 's':
|
||||||
ubus_socket = optarg;
|
ubus_socket = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 't':
|
||||||
|
exec_timeout = strtol(optarg, NULL, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exec_timeout < 1 || exec_timeout > 600) {
|
||||||
|
fprintf(stderr, "Invalid execution timeout specified\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
exec_timeout *= 1000;
|
||||||
|
|
||||||
if (stat(RPC_UCI_DIR_PREFIX, &s))
|
if (stat(RPC_UCI_DIR_PREFIX, &s))
|
||||||
mkdir(RPC_UCI_DIR_PREFIX, 0700);
|
mkdir(RPC_UCI_DIR_PREFIX, 0700);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue