[njs] Shell: added options for custom exit failure code.
Dmitry Volyntsev
xeioex at nginx.com
Thu Jan 27 13:03:23 UTC 2022
details: https://hg.nginx.org/njs/rev/328bb7c20642
branches:
changeset: 1819:328bb7c20642
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed Jan 26 17:24:57 2022 +0000
description:
Shell: added options for custom exit failure code.
diffstat:
src/njs_shell.c | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
diffs (59 lines):
diff -r d5d9605a6c55 -r 328bb7c20642 src/njs_shell.c
--- a/src/njs_shell.c Tue Jan 25 19:06:58 2022 +0000
+++ b/src/njs_shell.c Wed Jan 26 17:24:57 2022 +0000
@@ -36,6 +36,7 @@ typedef struct {
uint8_t version;
uint8_t ast;
uint8_t unhandled_rejection;
+ int exit_code;
char *file;
char *command;
@@ -319,7 +320,7 @@ done:
njs_options_free(&opts);
- return (ret == NJS_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
+ return (ret == NJS_OK) ? EXIT_SUCCESS : opts.exit_code;
}
@@ -344,6 +345,7 @@ njs_options_parse(njs_opts_t *opts, int
" -a print AST.\n"
" -c specify the command to execute.\n"
" -d print disassembled code.\n"
+ " -e set failure exit code.\n"
" -f disabled denormals mode.\n"
" -p set path prefix for modules.\n"
" -q disable interactive introduction prompt.\n"
@@ -357,8 +359,14 @@ njs_options_parse(njs_opts_t *opts, int
ret = NJS_DONE;
opts->denormals = 1;
+ opts->exit_code = EXIT_FAILURE;
opts->unhandled_rejection = NJS_VM_OPT_UNHANDLED_REJECTION_THROW;
+ p = getenv("NJS_EXIT_CODE");
+ if (p != NULL) {
+ opts->exit_code = atoi(p);
+ }
+
for (i = 1; i < argc; i++) {
p = argv[i];
@@ -396,6 +404,15 @@ njs_options_parse(njs_opts_t *opts, int
opts->disassemble = 1;
break;
+ case 'e':
+ if (++i < argc) {
+ opts->exit_code = atoi(argv[i]);
+ break;
+ }
+
+ njs_stderror("option \"-e\" requires argument\n");
+ return NJS_ERROR;
+
case 'f':
#if !(NJS_HAVE_DENORMALS_CONTROL)
More information about the nginx-devel
mailing list