diff --git a/plugins/in_exec_wasi/in_exec_wasi.c b/plugins/in_exec_wasi/in_exec_wasi.c index 6a533d0b23a..ba0164c1610 100644 --- a/plugins/in_exec_wasi/in_exec_wasi.c +++ b/plugins/in_exec_wasi/in_exec_wasi.c @@ -74,7 +74,14 @@ static int in_exec_wasi_collect(struct flb_input_instance *ins, } } - wasm = flb_wasm_instantiate(config, ctx->wasi_path, ctx->accessible_dir_list, -1, fileno(stdoutp), -1); + if (ctx->wasm_conf == NULL) { + flb_plg_error(ctx->ins, "wasm_conf cannot be NULL"); + return -1; + } + ctx->wasm_conf->stdoutfd = fileno(stdoutp); + + wasm = flb_wasm_instantiate(config, ctx->wasi_path, ctx->accessible_dir_list, + ctx->wasm_conf); if (wasm == NULL) { flb_plg_debug(ctx->ins, "instantiate wasm [%s] failed", ctx->wasi_path); goto collect_end; @@ -289,6 +296,7 @@ static int in_exec_wasi_init(struct flb_input_instance *in, struct flb_config *config, void *data) { struct flb_exec_wasi *ctx = NULL; + struct flb_wasm_config *wasm_conf = NULL; int ret = -1; /* Allocate space for the configuration */ @@ -341,6 +349,20 @@ static int in_exec_wasi_init(struct flb_input_instance *in, flb_plg_error(in, "could not set collector for exec input plugin"); goto init_error; } + + wasm_conf = flb_wasm_config_init(config); + if (wasm_conf == NULL) { + goto init_error; + } + ctx->wasm_conf = wasm_conf; + + if (ctx->wasm_heap_size > FLB_WASM_DEFAULT_HEAP_SIZE) { + wasm_conf->heap_size = ctx->wasm_heap_size; + } + if (ctx->wasm_stack_size > FLB_WASM_DEFAULT_STACK_SIZE) { + wasm_conf->stack_size = ctx->wasm_stack_size; + } + ctx->coll_fd = ret; return 0; @@ -391,6 +413,7 @@ static int in_exec_wasi_exit(void *data, struct flb_config *config) { struct flb_exec_wasi *ctx = data; + flb_wasm_config_destroy(ctx->wasm_conf); flb_wasm_destroy_all(config); delete_exec_wasi_config(ctx); return 0; @@ -433,6 +456,16 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct flb_exec_wasi, oneshot), "execute the command only once" }, + { + FLB_CONFIG_MAP_SIZE, "wasm_heap_size", DEFAULT_WASM_HEAP_SIZE, + 0, FLB_TRUE, offsetof(struct flb_exec_wasi, wasm_heap_size), + "Set the heap size of wasm runtime" + }, + { + FLB_CONFIG_MAP_SIZE, "wasm_stack_size", DEFAULT_WASM_STACK_SIZE, + 0, FLB_TRUE, offsetof(struct flb_exec_wasi, wasm_stack_size), + "Set the stack size of wasm runtime" + }, /* EOF */ {0} }; diff --git a/plugins/in_exec_wasi/in_exec_wasi.h b/plugins/in_exec_wasi/in_exec_wasi.h index aa07f264141..1fafbd43d6e 100644 --- a/plugins/in_exec_wasi/in_exec_wasi.h +++ b/plugins/in_exec_wasi/in_exec_wasi.h @@ -34,6 +34,9 @@ #define DEFAULT_INTERVAL_SEC "1" #define DEFAULT_INTERVAL_NSEC "0" +#define DEFAULT_WASM_HEAP_SIZE "8192" +#define DEFAULT_WASM_STACK_SIZE "8192" + struct flb_exec_wasi { flb_sds_t wasi_path; struct mk_list *accessible_dir_list; /* list of directories to be @@ -44,10 +47,13 @@ struct flb_exec_wasi { size_t buf_size; struct flb_input_instance *ins; struct flb_wasm *wasm; + struct flb_wasm_config *wasm_conf; int oneshot; flb_pipefd_t ch_manager[2]; int interval_sec; int interval_nsec; + size_t wasm_heap_size; + size_t wasm_stack_size; struct flb_log_event_encoder log_encoder; int coll_fd; };