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>
This commit is contained in:
Tom Jones
2024-04-24 10:30:20 +00:00
parent c0580f91a1
commit ab47993a00
5 changed files with 73 additions and 30 deletions

View File

@@ -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)
return clib_error_return (
0, "could not stat /proc/self/exe - set monitor manually");
path = os_get_exec_path ();
/* readlink doesn't provide null termination */
path[rv] = 0;
if (path == 0)
return clib_error_return (
0, "could not get exec path - set monitor manually");
/* 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)
{