From 60bfd76dc03c85a57af615d6e0a2882b0304f975 Mon Sep 17 00:00:00 2001 From: mtbakerguy Date: Sun, 29 Jan 2023 10:18:46 -0800 Subject: [PATCH 1/2] Give sed POSIX-compliant input to remove the need for gsed. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6881ac0..45ad5e33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ else() endif() # Extract the shiny-server version number from package.json -execute_process(COMMAND sed -n "s/\\s*\"version\": \"\\(.*\\)\",\\s*/\\1/p" +execute_process(COMMAND sed '/^.*"version": .*$/!d;s/",//;s/^.*"//' INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/package.json" OUTPUT_VARIABLE NPM_PACKAGE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) From b3bea3335ac6bb85a00420cc963c2dab0218cfab Mon Sep 17 00:00:00 2001 From: mtbakerguy Date: Sun, 29 Jan 2023 18:57:17 -0800 Subject: [PATCH 2/2] Add FreeBSD support that doesn't require procfs to the launcher. --- src/CMakeLists.txt | 6 +++++- src/launcher.cc | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1e5f293b..7830ee40 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,2 +1,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/launcher.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/launcher.h") -add_executable(shiny-server launcher.cc) \ No newline at end of file + +add_executable(shiny-server launcher.cc) +IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") +target_link_libraries(shiny-server procstat) +ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") diff --git a/src/launcher.cc b/src/launcher.cc index d8d04b63..9732ebd7 100644 --- a/src/launcher.cc +++ b/src/launcher.cc @@ -23,6 +23,15 @@ #include #include +#ifdef __FreeBSD__ +#include +#include +#include +#include +#include +#include +#endif + #include "launcher.h" // The purpose of this executable is to provide a clean entry point for @@ -63,7 +72,7 @@ int main(int argc, char **argv) { // This will actually never get called. free(newargs[0]); free(newargs[1]); - delete newargs; + delete[] newargs; return 0; } @@ -73,6 +82,25 @@ int main(int argc, char **argv) { int findBaseDir(std::string* shinyServerPath) { char execPath[MAXPATHLEN + 1]; +#ifdef __FreeBSD__ + struct kinfo_proc* p; + unsigned int cnt; + struct procstat *prstat = procstat_open_sysctl(); + if(prstat == 0) { + fprintf(stderr, "Failed opening procstat\n"); + return 2; + } + if((p = procstat_getprocs(prstat, KERN_PROC_PID, getpid(), &cnt)) == 0) { + fprintf(stderr, "Failed finding process %d\n", getpid()); + procstat_close(prstat); + return 1; + } + (void)procstat_getpathname(prstat, p, execPath, sizeof(execPath)); + procstat_freeprocs(prstat, p); + procstat_close(prstat); +#endif + +#ifdef __linux__ int cn = snprintf(execPath, MAXPATHLEN + 1, "/proc/%d/exe", getpid()); if (cn < 0 || cn > MAXPATHLEN) { // Not expected @@ -107,6 +135,7 @@ int findBaseDir(std::string* shinyServerPath) { } std::copy(execBuf.begin(), execBuf.begin() + cb, execPath); execPath[cb] = '\0'; +#endif *shinyServerPath = dirname(dirname(execPath));