Skip to content

Give sed POSIX-compliant input to remove the need for gsed. Add FreeBSD support. #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

add_executable(shiny-server launcher.cc)
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
target_link_libraries(shiny-server procstat)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
31 changes: 30 additions & 1 deletion src/launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
#include <vector>
#include <algorithm>

#ifdef __FreeBSD__
#include <err.h>
#include <sys/socket.h>
#include <sys/queue.h>
#include <libprocstat.h>
#include <sysexits.h>
#include <sys/sysctl.h>
#endif

#include "launcher.h"

// The purpose of this executable is to provide a clean entry point for
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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));

Expand Down