summaryrefslogtreecommitdiff
path: root/src/shim/vyshim.c
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-03-23 20:36:37 -0500
committerJohn Estabrook <jestabro@vyos.io>2021-05-14 10:03:31 -0500
commitc44599db534a4dcc47f5f4f22fb60c67943101bd (patch)
treeef797ed3c8afe01f8c60f1ab61f4a8982ac5ba2f /src/shim/vyshim.c
parent7a705d2d60a0f6b8eeb742065d17039952255856 (diff)
downloadvyos-1x-c44599db534a4dcc47f5f4f22fb60c67943101bd.tar.gz
vyos-1x-c44599db534a4dcc47f5f4f22fb60c67943101bd.zip
configd: T3426: correct pass_through function for scripts with args
(cherry picked from commit 5501e5f1de0201f4c977a8027b6e97caf1affa1b)
Diffstat (limited to 'src/shim/vyshim.c')
-rw-r--r--src/shim/vyshim.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/shim/vyshim.c b/src/shim/vyshim.c
index 196e3221e..e6d1d5a78 100644
--- a/src/shim/vyshim.c
+++ b/src/shim/vyshim.c
@@ -75,28 +75,32 @@ int main(int argc, char* argv[])
void *context = zmq_ctx_new();
void *requester = zmq_socket(context, ZMQ_REQ);
+ int ex_index;
int init_timeout = 0;
debug_print("Connecting to vyos-configd ...\n");
zmq_connect(requester, SOCKET_PATH);
+ for (int i = argc-1; i > 0 ; i--) {
+ strncat(&string_node_data[0], argv[i], 127);
+ }
+
+ debug_print("data to send: %s\n", string_node_data);
+
+ char *test = strstr(string_node_data, "VYOS_TAGNODE_VALUE");
+ ex_index = test ? 2 : 1;
+
if (access(COMMIT_MARKER, F_OK) != -1) {
init_timeout = initialization(requester);
if (!init_timeout) remove(COMMIT_MARKER);
}
- int end = argc > 3 ? 2 : argc - 1;
-
// if initial communication failed, pass through execution of script
if (init_timeout) {
- int ret = pass_through(argv, end);
+ int ret = pass_through(argv, ex_index);
return ret;
}
- for (int i = end; i > 0 ; i--) {
- strncat(&string_node_data[0], argv[i], 127);
- }
-
char error_code[1];
debug_print("Sending node data ...\n");
char *string_node_data_msg = mkjson(MKJSON_OBJ, 2,
@@ -116,13 +120,13 @@ int main(int argc, char* argv[])
if (err & PASS) {
debug_print("Received PASS\n");
- int ret = pass_through(argv, end);
+ int ret = pass_through(argv, ex_index);
return ret;
}
if (err & ERROR_DAEMON) {
debug_print("Received ERROR_DAEMON\n");
- int ret = pass_through(argv, end);
+ int ret = pass_through(argv, ex_index);
return ret;
}
@@ -232,14 +236,14 @@ int initialization(void* Requester)
return 0;
}
-int pass_through(char **argv, int end)
+int pass_through(char **argv, int ex_index)
{
- char *newargv[] = { NULL, NULL };
+ char **newargv = NULL;
pid_t child_pid;
- newargv[0] = argv[end];
- if (end > 1) {
- putenv(argv[end - 1]);
+ newargv = &argv[ex_index];
+ if (ex_index > 1) {
+ putenv(argv[ex_index - 1]);
}
debug_print("pass-through invoked\n");
@@ -248,9 +252,9 @@ int pass_through(char **argv, int end)
debug_print("fork() failed\n");
return -1;
} else if (child_pid == 0) {
- if (-1 == execv(argv[end], newargv)) {
+ if (-1 == execv(argv[ex_index], newargv)) {
debug_print("pass_through execve failed %s: %s\n",
- argv[end], strerror(errno));
+ argv[ex_index], strerror(errno));
return -1;
}
} else if (child_pid > 0) {