From 0bbeef6e866eca575d2e3b97b78ae299257801c7 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 29 Sep 2023 12:55:07 +0000 Subject: [PATCH] use /proc/self/cmdline to get tests path --- test/tap/tap/command_line.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/tap/tap/command_line.cpp b/test/tap/tap/command_line.cpp index 759616f8a2..47746fb621 100644 --- a/test/tap/tap/command_line.cpp +++ b/test/tap/tap/command_line.cpp @@ -130,12 +130,28 @@ int CommandLine::getEnv() { { // load environment char temp[PATH_MAX]; - ssize_t len = readlink("/proc/self/exe", temp, sizeof(temp)); +// ssize_t len = readlink("/proc/self/exe", temp, sizeof(temp)); + { + FILE* fp = fopen("/proc/self/cmdline", "r"); // Linux + if (!fp) + fp = fopen("/proc/curproc/cmdline", "r"); // FreeBSD, needs procfs mounted + assert(fp); // MacOS ? + fgets(temp, PATH_MAX, fp); + fclose(fp); + } +// diag(">>> cmdline = %s <<<", temp); + ssize_t len = strlen(realpath(temp, temp)); +// diag(">>> realpath() = %s <<<", temp); std::string exe_path = (len > 0) ? std::string(temp, len) : std::string(""); std::string exe_name = exe_path.substr(exe_path.find_last_of('/') + 1); std::string dir_path = exe_path.substr(0, exe_path.find_last_of('/')); std::string dir_name = dir_path.substr(dir_path.find_last_of('/') + 1); +// diag(">>> exe_path = %s <<<", exe_path.c_str()); +// diag(">>> exe_name = %s <<<", exe_name.c_str()); +// diag(">>> dir_path = %s <<<", dir_path.c_str()); +// diag(">>> dir_name = %s <<<", dir_name.c_str()); + env.load_dotenv((dir_path + "/.env").c_str(), true); bool loaded1 = env.loaded;