diff options
author | Tom Jones <thj@freebsd.org> | 2024-04-24 10:30:20 +0000 |
---|---|---|
committer | Tom Jones <thj@freebsd.org> | 2024-04-24 10:30:20 +0000 |
commit | ab47993a00e8854d64ae90de0cdd4b9272653473 (patch) | |
tree | bbf7b7fc9ac6ae379506fcc1914e040e265831b6 /src/plugins | |
parent | c0580f91a14cb4a68f1978c6702a91efc46d12a9 (diff) |
vppinfra: Add method for getting current executable name
Add a unix method for getting the current executable name. This is
implemented to match the readlink api for existing calls.
Type: improvement
Change-Id: Id06a55892d09d0b305a56b55a424f53ffb685a72
Signed-off-by: Tom Jones <thj@freebsd.org>
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/fateshare/fateshare.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/plugins/fateshare/fateshare.c b/src/plugins/fateshare/fateshare.c index 33ee167bce3..37cd0300ab7 100644 --- a/src/plugins/fateshare/fateshare.c +++ b/src/plugins/fateshare/fateshare.c @@ -17,6 +17,7 @@ #include <vnet/vnet.h> #include <vnet/plugin/plugin.h> +#include <vppinfra/unix.h> #include <fateshare/fateshare.h> #include <vlibapi/api.h> @@ -197,24 +198,30 @@ fateshare_config (vlib_main_t *vm, unformat_input_t *input) if (fmp->monitor_cmd == 0) { - char *p, path[PATH_MAX]; - int rv; + char *p; + u8 *path; /* find executable path */ - if ((rv = readlink ("/proc/self/exe", path, PATH_MAX - 1)) == -1) + path = os_get_exec_path (); + + if (path == 0) return clib_error_return ( - 0, "could not stat /proc/self/exe - set monitor manually"); + 0, "could not get exec path - set monitor manually"); - /* readlink doesn't provide null termination */ - path[rv] = 0; + /* add null termination */ + vec_add1 (path, 0); /* strip filename */ - if ((p = strrchr (path, '/')) == 0) - return clib_error_return ( - 0, "could not determine vpp directory - set monitor manually"); + if ((p = strrchr ((char *) path, '/')) == 0) + { + vec_free (path); + return clib_error_return ( + 0, "could not determine vpp directory - set monitor manually"); + } *p = 0; fmp->monitor_cmd = format (0, "%s/vpp_fateshare_monitor\0", path); + vec_free (path); } if (fmp->monitor_logfile == 0) { |