Skip to content

Commit 36a1a37

Browse files
committed
product-mini/platforms/posix: Propagate WASI exit code as iwasm's exit code
It seems like a common practice for engines with a cli. Also, use non-zero exit code on an exeception.
1 parent 71d9c5b commit 36a1a37

File tree

1 file changed

+23
-8
lines changed
  • product-mini/platforms/posix

1 file changed

+23
-8
lines changed

product-mini/platforms/posix/main.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ app_instance_main(wasm_module_inst_t module_inst)
8686
wasm_application_execute_main(module_inst, app_argc, app_argv);
8787
if ((exception = wasm_runtime_get_exception(module_inst)))
8888
printf("%s\n", exception);
89-
return NULL;
89+
return exception;
9090
}
9191

9292
static void *
@@ -96,7 +96,7 @@ app_instance_func(wasm_module_inst_t module_inst, const char *func_name)
9696
app_argv + 1);
9797
/* The result of wasm function or exception info was output inside
9898
wasm_application_execute_func(), here we don't output them again. */
99-
return NULL;
99+
return wasm_runtime_get_exception(module_inst);
100100
}
101101

102102
/**
@@ -643,14 +643,29 @@ main(int argc, char *argv[])
643643
}
644644
#endif
645645

646-
if (is_repl_mode)
646+
ret = 0;
647+
if (is_repl_mode) {
647648
app_instance_repl(wasm_module_inst);
648-
else if (func_name)
649-
app_instance_func(wasm_module_inst, func_name);
650-
else
651-
app_instance_main(wasm_module_inst);
649+
}
650+
else if (func_name) {
651+
if (app_instance_func(wasm_module_inst, func_name)) {
652+
/* got an exception */
653+
ret = 1;
654+
}
655+
}
656+
else {
657+
if (app_instance_main(wasm_module_inst)) {
658+
/* got an exception */
659+
ret = 1;
660+
}
661+
}
652662

653-
ret = 0;
663+
#if WASM_ENABLE_LIBC_WASI != 0
664+
if (ret == 0) {
665+
/* propagate wasi exit code. */
666+
ret = wasm_runtime_get_wasi_exit_code(wasm_module_inst);
667+
}
668+
#endif
654669

655670
#if WASM_ENABLE_DEBUG_INTERP != 0
656671
fail4:

0 commit comments

Comments
 (0)