aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-04-04 18:48:11 +0200
committerFlorin Coras <florin.coras@gmail.com>2022-04-04 19:12:10 +0000
commit2e90b299ac3f32bbf82785eda5e00a2e2d61f718 (patch)
treec3138a24a361fa85d413d30fb9bbd86a90799f69 /src
parent0dde17573261d32e50d86ea584bc70f0796e0f46 (diff)
vlib: improve exec path search
Fixes VPP invocation with relative path, i.e.: $ bin/vpp unix interactive Type: improvement Change-Id: I0278710bb472b92e31389b2d28955c3d33550230 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vlib/cli.c2
-rw-r--r--src/vlib/main.h7
-rw-r--r--src/vlib/unix/main.c32
-rw-r--r--src/vpp/app/version.c3
4 files changed, 35 insertions, 9 deletions
diff --git a/src/vlib/cli.c b/src/vlib/cli.c
index 2187d2886fc..b7c4c0030b0 100644
--- a/src/vlib/cli.c
+++ b/src/vlib/cli.c
@@ -1097,7 +1097,7 @@ restart_cmd_fn (vlib_main_t * vm, unformat_input_t * input,
/* *INDENT-ON* */
/* Exec ourself */
- execve (vgm->name, (char **) vm->argv, environ);
+ execve (vgm->name, (char **) vgm->argv, environ);
return 0;
}
diff --git a/src/vlib/main.h b/src/vlib/main.h
index 18ec3be05e1..2581d491019 100644
--- a/src/vlib/main.h
+++ b/src/vlib/main.h
@@ -220,7 +220,6 @@ typedef struct vlib_main_t
volatile u32 queue_signal_pending;
volatile u32 api_queue_nonempty;
void (*queue_signal_callback) (struct vlib_main_t *);
- u8 **argv;
/* Top of (worker) dispatch loop callback */
void (**volatile worker_thread_main_loop_callbacks)
@@ -283,6 +282,12 @@ typedef struct vlib_global_main_t
/* Name for e.g. syslog. */
char *name;
+ /* full path to main executable */
+ char *exec_path;
+
+ /* command line arguments */
+ u8 **argv;
+
/* post-mortem callbacks */
void (**post_mortem_callbacks) (void);
diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c
index ba1c9d1bd63..0ebda240899 100644
--- a/src/vlib/unix/main.c
+++ b/src/vlib/unix/main.c
@@ -647,12 +647,13 @@ static uword
thread0 (uword arg)
{
vlib_main_t *vm = (vlib_main_t *) arg;
+ vlib_global_main_t *vgm = vlib_get_global_main ();
unformat_input_t input;
int i;
vlib_process_finish_switch_stack (vm);
- unformat_init_command_line (&input, (char **) vm->argv);
+ unformat_init_command_line (&input, (char **) vgm->argv);
i = vlib_main (vm, &input);
unformat_free (&input);
@@ -675,6 +676,10 @@ vlib_thread_stack_init (uword thread_index)
return stack;
}
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
int
vlib_unix_main (int argc, char *argv[])
{
@@ -682,12 +687,27 @@ vlib_unix_main (int argc, char *argv[])
vlib_main_t *vm = vlib_get_first_main (); /* one and only time for this! */
unformat_input_t input;
clib_error_t *e;
+ char buffer[PATH_MAX];
int i;
vec_validate_aligned (vgm->vlib_mains, 0, CLIB_CACHE_LINE_BYTES);
- vm->argv = (u8 **) argv;
- vgm->name = argv[0];
+ if ((i = readlink ("/proc/self/exe", buffer, sizeof (buffer) - 1)) > 0)
+ {
+ int j;
+ buffer[i] = 0;
+ vgm->exec_path = vec_new (char, i + 1);
+ clib_memcpy_fast (vgm->exec_path, buffer, i + 1);
+ for (j = i - 1; j > 0; j--)
+ if (buffer[j - 1] == '/')
+ break;
+ vgm->name = vec_new (char, i - j + 1);
+ clib_memcpy_fast (vgm->name, buffer + j, i - j + 1);
+ }
+ else
+ vgm->exec_path = vgm->name = argv[0];
+
+ vgm->argv = (u8 **) argv;
vm->heap_base = clib_mem_get_heap ();
vm->heap_aligned_base =
(void *) (((uword) vm->heap_base) & ~(CLIB_CACHE_LINE_BYTES - 1));
@@ -700,7 +720,7 @@ vlib_unix_main (int argc, char *argv[])
elog_init (vlib_get_elog_main (), vgm->configured_elog_ring_size);
elog_enable_disable (vlib_get_elog_main (), 1);
- unformat_init_command_line (&input, (char **) vm->argv);
+ unformat_init_command_line (&input, (char **) vgm->argv);
if ((e = vlib_plugin_config (vm, &input)))
{
clib_error_report (e);
@@ -712,7 +732,7 @@ vlib_unix_main (int argc, char *argv[])
if (i)
return i;
- unformat_init_command_line (&input, (char **) vm->argv);
+ unformat_init_command_line (&input, (char **) vgm->argv);
if (vgm->init_functions_called == 0)
vgm->init_functions_called = hash_create (0, /* value bytes */ 0);
e = vlib_call_all_config_functions (vm, &input, 1 /* early */ );
@@ -724,7 +744,7 @@ vlib_unix_main (int argc, char *argv[])
unformat_free (&input);
/* always load symbols, for signal handler and mheap memory get/put backtrace */
- clib_elf_main_init (vgm->name);
+ clib_elf_main_init (vgm->exec_path);
vec_validate (vlib_thread_stacks, 0);
vlib_thread_stack_init (0);
diff --git a/src/vpp/app/version.c b/src/vpp/app/version.c
index db13c863965..e6a73283ab2 100644
--- a/src/vpp/app/version.c
+++ b/src/vpp/app/version.c
@@ -59,7 +59,8 @@ show_vpe_version_command_fn (vlib_main_t * vm,
int verbose = 0;
int cmdline = 0;
int indent = 2;
- char **argv = (char **) vm->argv;
+ vlib_global_main_t *vgm = vlib_get_global_main ();
+ char **argv = (char **) vgm->argv;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{