$OpenBSD: patch-src_cpp_core_system_PosixSystem_cpp,v 1.1.1.1 2020/07/01 18:10:07 bcallah Exp $

Adapted from FreeBSD.
No way to get the path of an executable at runtime.

Index: src/cpp/core/system/PosixSystem.cpp
--- src/cpp/core/system/PosixSystem.cpp.orig
+++ src/cpp/core/system/PosixSystem.cpp
@@ -47,13 +47,18 @@
 #include <gsl/gsl>
 #endif
 
-#ifndef __APPLE__
+#ifndef __OpenBSD__
 #include <sys/prctl.h>
 #include <sys/sysinfo.h>
 #include <linux/kernel.h>
 #include <dirent.h>
 #endif
 
+#ifdef __OpenBSD__
+#include <netinet/in.h>
+#include <dirent.h>
+#endif
+
 #include <boost/thread.hpp>
 #include <boost/format.hpp>
 #include <boost/lexical_cast.hpp>
@@ -926,9 +931,8 @@ Error executablePath(const char * argv0,
    // need to also search the PATH for the exe name in argv[0]
    //
 
-   // use argv[0] and initial path
-   FilePath initialPath = FilePath::initialPath();
-   executablePath = initialPath.completePath(argv0).getAbsolutePath();
+   // XXX: OpenBSD: assume localbase
+   executablePath = std::string("LOCALBASE/lib/rstudio/bin/rstudio");
 
 #endif
 
@@ -1405,9 +1409,11 @@ Error osResourceLimit(ResourceLimit limit, int* pLimit
 {
    switch(limit)
    {
+#ifndef __OpenBSD__
       case MemoryLimit:
          *pLimit = RLIMIT_AS;
          break;
+#endif
       case FilesLimit:
          *pLimit = RLIMIT_NOFILE;
          break;
@@ -1426,7 +1432,7 @@ Error osResourceLimit(ResourceLimit limit, int* pLimit
       case CpuLimit:
          *pLimit = RLIMIT_CPU;
          break;
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
       case NiceLimit:
          *pLimit = RLIMIT_NICE;
          break;
@@ -1499,7 +1505,7 @@ Error systemInformation(SysInfo* pSysInfo)
 {
    pSysInfo->cores = boost::thread::hardware_concurrency();
 
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
    struct sysinfo info;
    if (::sysinfo(&info) == -1)
       return systemError(errno, ERROR_LOCATION);
@@ -1939,7 +1945,7 @@ Error restrictCoreDumps()
       return error;
 
    // no ptrace core dumps permitted
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
    int res = ::prctl(PR_SET_DUMPABLE, 0);
    if (res == -1)
       return systemError(errno, ERROR_LOCATION);
@@ -1950,7 +1956,7 @@ Error restrictCoreDumps()
 
 Error enableCoreDumps()
 {
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
    int res = ::prctl(PR_SET_DUMPABLE, 1);
    if (res == -1)
       return systemError(errno, ERROR_LOCATION);
@@ -1976,7 +1982,7 @@ void printCoreDumpable(const std::string& context)
    ostr << "  hard limit: " << rLimitHard << std::endl;
 
    // ptrace
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
    int dumpable = ::prctl(PR_GET_DUMPABLE, nullptr, nullptr, nullptr, nullptr);
    if (dumpable == -1)
       LOG_ERROR(systemError(errno, ERROR_LOCATION));
