summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_go.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-06-06 16:53:35 +0300
committerValentin Bartenev <vbart@nginx.com>2018-06-06 16:53:35 +0300
commitceeb30188152426d76eac1f40ca8ceb24ddb5d0a (patch)
tree910a973b915b7320746d87b9088fd29b37aafe79 /src/nxt_go.c
parent857bddeea613cdf7ce0f9228ec6601285bf3bde7 (diff)
downloadunit-ceeb30188152426d76eac1f40ca8ceb24ddb5d0a.tar.gz
unit-ceeb30188152426d76eac1f40ca8ceb24ddb5d0a.tar.bz2
Go: specifying command line arguments to the executable.
This closes #110 issue on GitHub.
Diffstat (limited to 'src/nxt_go.c')
-rw-r--r--src/nxt_go.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/nxt_go.c b/src/nxt_go.c
index edcd5eff..67a5afb6 100644
--- a/src/nxt_go.c
+++ b/src/nxt_go.c
@@ -58,12 +58,17 @@ nxt_go_fd_no_cloexec(nxt_task_t *task, nxt_socket_t fd)
static nxt_int_t
nxt_go_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
{
- char *argv[2];
+ char **argv;
u_char buf[256];
u_char *p, *end;
+ uint32_t index;
+ size_t size;
+ nxt_str_t str;
nxt_int_t rc;
+ nxt_uint_t i, argc;
nxt_port_t *my_port, *main_port;
nxt_runtime_t *rt;
+ nxt_conf_value_t *value;
nxt_go_app_conf_t *c;
rt = task->thread->runtime;
@@ -114,13 +119,59 @@ nxt_go_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
c = &conf->u.go;
+ argc = 2;
+ size = 0;
+
+ if (c->arguments != NULL) {
+
+ for (index = 0; /* void */ ; index++) {
+ value = nxt_conf_get_array_element(c->arguments, index);
+ if (value == NULL) {
+ break;
+ }
+
+ nxt_conf_get_string(value, &str);
+
+ size += str.length + 1;
+ argc++;
+ }
+ }
+
+ argv = nxt_malloc(argc * sizeof(argv[0]) + size);
+ if (nxt_slow_path(argv == NULL)) {
+ nxt_alert(task, "failed to allocate arguments");
+ return NXT_ERROR;
+ }
+
argv[0] = c->executable;
- argv[1] = NULL;
+ i = 1;
+
+ if (c->arguments != NULL) {
+ p = (u_char *) &argv[argc];
+
+ for (index = 0; /* void */ ; index++) {
+ value = nxt_conf_get_array_element(c->arguments, index);
+ if (value == NULL) {
+ break;
+ }
+
+ argv[i++] = (char *) p;
+
+ nxt_conf_get_string(value, &str);
+
+ p = nxt_cpymem(p, str.start, str.length);
+ *p++ = '\0';
+ }
+ }
+
+ argv[i] = NULL;
(void) execve(c->executable, argv, environ);
nxt_alert(task, "execve(%s) failed %E", c->executable, nxt_errno);
+ nxt_free(argv);
+
return NXT_ERROR;
}