Fix getting the process binary for FreeBSD or macOS

This commit is contained in:
Chris Robinson 2018-11-11 22:19:32 -08:00
parent 5848dab92d
commit c23ea494ea

View File

@ -484,21 +484,19 @@ PathNamePair GetProcBinary()
{
pathname.resize(pathlen + 1);
sysctl(mib, 4, pathname.data(), &pathlen, nullptr, 0);
pathname[pathlen] = 0;
pathname.resize(pathlen);
}
#endif
#ifdef HAVE_PROC_PIDPATH
if(pathname.empty())
{
const pid_t pid = getpid();
char procpath[PROC_PIDPATHINFO_MAXSIZE];
int ret;
ret = proc_pidpath(pid, procpath, sizeof(procpath));
char procpath[PROC_PIDPATHINFO_MAXSIZE]{};
const pid_t pid{getpid()};
const int ret{proc_pidpath(pid, procpath, sizeof(procpath))};
if(ret < 1)
WARN("proc_pidpath(%d, ...) failed: %s\n", pid, strerror(errno));
ERR("proc_pidpath(%d, ...) failed: %s\n", pid, strerror(errno));
else
pathname.append(procpath, procpath+strlen(procpath));
pathname.insert(pathname.end(), procpath, procpath+strlen(procpath));
}
#endif
if(pathname.empty())