Skip to content

Commit

Permalink
Avoid program_invocation_name which is available only on Linux
Browse files Browse the repository at this point in the history
`program_invocation_name` is defined by the system headers only on
Linux, or at least it is not available on FreeBSD.

Thus, maintain own global variable that contains the program name.
  • Loading branch information
vasild committed Oct 24, 2024
1 parent d595541 commit 2442b30
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Boss/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# include "config.h"
#endif

std::string g_argv0{"unknown"};

namespace Boss {

class Main::Impl {
Expand Down Expand Up @@ -62,6 +64,7 @@ class Main::Impl {
{
assert(argv.size() >= 1);
argv0 = argv[0];
g_argv0 = argv[0];
if (argv.size() >= 2) {
auto argv1 = argv[1];
if (argv1 == "--version" || argv1 == "-V")
Expand Down
5 changes: 4 additions & 1 deletion Util/BacktraceException.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <sstream>
#include <vector>
#include <string.h>
#include <string>

extern std::string g_argv0;

namespace Util {

Expand Down Expand Up @@ -80,7 +83,7 @@ class BacktraceException : public T {
std::string addr2line(void* addr) const {
char cmd[512];
snprintf(cmd, sizeof(cmd),
"addr2line -C -f -p -e %s %p", program_invocation_name, addr);
"addr2line -C -f -p -e %s %p", g_argv0.c_str(), addr);

std::array<char, 128> buffer;
std::string result;
Expand Down

0 comments on commit 2442b30

Please sign in to comment.