diff --git a/makefile b/makefile index a29906f..7091dc6 100644 --- a/makefile +++ b/makefile @@ -110,6 +110,7 @@ # make linux ARCHID=27 # Linux ARM 32 bit HardFloat NOKVM (Old Raspberry Pi on Raspian 7, 2015-02-02 build) # gmake freebsd ARCHID=30 # FreeBSD x86 64 bit # gmake freebsd ARCHID=31 # Reserved for FreeBSD x86 32 bit +# gmake openbsd ARCHID=34 # OpenBSD x86 64 bit # # # Alpine Linux (MUSL) @@ -485,6 +486,15 @@ KVM = 0 LMS = 0 endif +# Official OpenBSD x86-64 +ifeq ($(ARCHID),34) +ARCHNAME = openbsd_x86-64 +CC = clang +CFLAGS += -I/usr/local/include +KVM = 0 +LMS = 0 +endif + ifeq ($(WEBLOG),1) CFLAGS += -D_REMOTELOGGINGSERVER -D_REMOTELOGGING @@ -724,3 +734,9 @@ freebsd: $(MAKE) EXENAME="$(EXENAME)_$(ARCHNAME)$(EXENAME2)" ADDITIONALSOURCES="$(LINUXKVMSOURCES)" AID="$(ARCHID)" CFLAGS="-std=gnu99 -Wall -DJPEGMAXBUF=$(KVMMaxTile) -DMESH_AGENTID=$(ARCHID) -D_POSIX -D_FREEBSD -D_NOHECI -D_NOILIBSTACKDEBUG -DMICROSTACK_PROXY -fno-strict-aliasing $(INCDIRS) $(CFLAGS) $(CEXTRA)" LDFLAGS="$(BSDSSL) $(BSDFLAGS) -L. -lpthread -ldl -lz -lutil $(LDFLAGS) $(LDEXTRA)" $(SYMBOLCP) $(STRIP) + +openbsd: + $(MAKE) EXENAME="$(EXENAME)_$(ARCHNAME)$(EXENAME2)" ADDITIONALSOURCES="$(LINUXKVMSOURCES)" AID="$(ARCHID)" CFLAGS="-std=gnu99 -Wall -DJPEGMAXBUF=$(KVMMaxTile) -DMESH_AGENTID=$(ARCHID) -D_POSIX -D_FREEBSD -D_OPENBSD -DILIB_NO_TIMEDJOIN -D_NOHECI -D_NOILIBSTACKDEBUG -DMICROSTACK_PROXY -fno-strict-aliasing $(INCDIRS) $(CFLAGS) $(CEXTRA)" LDFLAGS="$(BSDSSL) $(BSDFLAGS) -L. -lpthread -lz -lutil $(LDFLAGS) $(LDEXTRA)" + $(SYMBOLCP) + $(STRIP) + diff --git a/meshconsole/main.c b/meshconsole/main.c index dd564ca..bb69c27 100644 --- a/meshconsole/main.c +++ b/meshconsole/main.c @@ -34,6 +34,11 @@ limitations under the License. #include "microscript/ILibDuktape_Commit.h" MeshAgentHostContainer *agentHost = NULL; +#ifdef _OPENBSD +#include +char __agentExecPath[1024] = { 0 }; +#endif + #ifdef WIN32 BOOL CtrlHandler(DWORD fdwCtrlType) @@ -81,6 +86,10 @@ int wmain(int argc, char **wargv) int main(int argc, char **argv) #endif { +#ifdef _OPENBSD + realpath(argv[0], __agentExecPath); +#endif + // Check if .JS file is integrated with executable char *integratedJavaScript = NULL; int integratedJavaScriptLen = 0; diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index 8387b2e..55597ab 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -5770,7 +5770,11 @@ int MeshAgent_Start(MeshAgentHostContainer *agentHost, int paramLen, char **para #elif defined(NACL) #else #ifdef _FREEBSD - x = readlink("/proc/curproc/file", exePath, 1024); + #ifdef _OPENBSD + x = sprintf_s(exePath, 1024, "%s", __agentExecPath); + #else + x = readlink("/proc/curproc/file", exePath, 1024); + #endif #else x = readlink("/proc/self/exe", exePath, 1024); #endif diff --git a/microscript/ILibDuktape_ScriptContainer.c b/microscript/ILibDuktape_ScriptContainer.c index 7f16cde..ed965e4 100644 --- a/microscript/ILibDuktape_ScriptContainer.c +++ b/microscript/ILibDuktape_ScriptContainer.c @@ -52,6 +52,11 @@ limitations under the License. #include #endif +#ifdef _OPENBSD +extern char* __agentExecPath; +#endif + + #include "ILibDuktape_ScriptContainer.h" #include "ILibDuktapeModSearch.h" #include "ILibDuktape_EventEmitter.h" @@ -453,12 +458,16 @@ void ILibDuktape_ScriptContainer_CheckEmbedded(char **script, int *scriptLen) int x = readlink("/proc/curproc/file", exePath, sizeof(exePath)); if (x < 0 || x >= sizeof(exePath)) { +#ifdef _OPENBSD + strcpy_s(exePath, sizeof(exePath), __agentExecPath); +#else printf("\nYou'll need to mount procfs, which isn't mounted by default on FreeBSD.\n"); printf("Add the following line to /etc/fstab\n"); printf(" proc /proc procfs rw 0 0\n\n"); printf("If you don't reboot after, then you can manually mount with the command:\n"); printf(" mount -t procfs proc /proc\n\n"); ILIBCRITICALEXIT(246); +#endif } exePath[x] = 0; #else diff --git a/microstack/ILibProcessPipe.c b/microstack/ILibProcessPipe.c index 2bf1d34..ea7a85c 100644 --- a/microstack/ILibProcessPipe.c +++ b/microstack/ILibProcessPipe.c @@ -42,7 +42,11 @@ limitations under the License. #include #else #include +#ifdef _OPENBSD + #include +#else #include +#endif #endif #endif #endif