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