Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <string>
#include <vector>
#include <algorithm>
#ifdef __APPLE__
#include <libproc.h>
#endif

#include "launcher.h"

Expand Down Expand Up @@ -72,6 +75,14 @@ int main(int argc, char **argv) {
// by calling readlink on /proc/<pid>/exe.
int findBaseDir(std::string* shinyServerPath) {

#ifdef __APPLE__
char execPath[PROC_PIDPATHINFO_MAXSIZE];
if (!proc_pidpath(getpid(), execPath, sizeof(execPath))) {
perror("proc_pidpath");
// unexpected error
return 2;
}
#else // assuming Linux
char execPath[MAXPATHLEN + 1];
int cn = snprintf(execPath, MAXPATHLEN + 1, "/proc/%d/exe", getpid());
if (cn < 0 || cn > MAXPATHLEN) {
Expand Down Expand Up @@ -107,7 +118,7 @@ int findBaseDir(std::string* shinyServerPath) {
}
std::copy(execBuf.begin(), execBuf.begin() + cb, execPath);
execPath[cb] = '\0';

#endif
*shinyServerPath = dirname(dirname(execPath));

return 0;
Expand Down