1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-21 02:33:24 +00:00

Initial modifications to support FreeBSD

This commit is contained in:
Bryan Roe
2019-06-17 15:45:46 -07:00
parent cefab43b99
commit 124c0d386f
16 changed files with 74 additions and 38 deletions

View File

@@ -24,6 +24,7 @@ limitations under the License.
#include "../microstack/ILibProcessPipe.h"
#include "../microstack/ILibRemoteLogging.h"
#ifndef _NOHECI
#ifdef WIN32
#include <windows.h>
@@ -1143,3 +1144,6 @@ void ILibDuktape_HECI_Init(duk_context *ctx)
{
ILibDuktape_ModSearch_AddHandler(ctx, "heci", ILibDuktape_HECI_Push);
}
#endif

View File

@@ -27,10 +27,10 @@ limitations under the License.
#ifndef NO_IFADDR
#include <ifaddrs.h>
#endif
#ifndef __APPLE__
#include <netpacket/packet.h>
#else
#include <mach-o/dyld.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#elif !defined(_FREEBSD)
#include <netpacket/packet.h>
#endif
#include <sys/utsname.h>
#endif
@@ -467,7 +467,11 @@ void ILibDuktape_ScriptContainer_CheckEmbedded(char **script, int *scriptLen)
if (_NSGetExecutablePath(exePath, &len) != 0) ILIBCRITICALEXIT(247);
exePath[len] = 0;
#elif defined(NACL)
#else
#elif defined(_FREEBSD)
int x = readlink("/proc/curproc/file", exePath, sizeof(exePath));
if (x < 0 || x >= sizeof(exePath)) ILIBCRITICALEXIT(246);
exePath[x] = 0;
#elif
int x = readlink("/proc/self/exe", exePath, sizeof(exePath));
if (x < 0 || x >= sizeof(exePath)) ILIBCRITICALEXIT(246);
exePath[x] = 0;
@@ -1015,6 +1019,8 @@ void ILibDuktape_ScriptContainer_Process_Init(duk_context *ctx, char **argList)
duk_push_string(ctx, "win32");
#elif defined(__APPLE__)
duk_push_string(ctx, "darwin");
#elif defined(_FREEBSD)
duk_push_string(ctx, "freebsd");
#else
duk_push_string(ctx, "linux");
#endif
@@ -1346,7 +1352,7 @@ int ILibDuktape_ScriptContainer_os_isWirelessInterface(char *interfaceName)
return(retVal);
}
#endif
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(_FREEBSD)
duk_ret_t ILibDuktape_ScriptContainer_OS_networkInterfaces(duk_context *ctx)
{
#if !defined(WIN32)
@@ -1607,7 +1613,7 @@ void ILibDuktape_ScriptContainer_OS_Push(duk_context *ctx, void *chain)
ILibDuktape_CreateInstanceMethod(ctx, "arch", ILibDuktape_ScriptContainer_OS_arch, 0);
ILibDuktape_CreateInstanceMethod(ctx, "platform", ILibDuktape_ScriptContainer_OS_platform, 0);
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(_FREEBSD)
ILibDuktape_CreateInstanceMethod(ctx, "networkInterfaces", ILibDuktape_ScriptContainer_OS_networkInterfaces, 0);
#endif
ILibDuktape_CreateInstanceMethod(ctx, "hostname", ILibDuktape_ScriptContainer_OS_hostname, 0);

View File

@@ -39,8 +39,8 @@ limitations under the License.
#ifdef _POSIX
#include <sys/stat.h>
#if !defined(_NOFSWATCHER) && !defined(__APPLE__)
#include <sys/inotify.h>
#if !defined(_NOFSWATCHER) && !defined(__APPLE__) && !defined(_FREEBSD)
#include <sys/inotify.h>
#endif
#endif
#ifdef __APPLE__
@@ -905,7 +905,7 @@ duk_ret_t ILibDuktape_fs_watcher_close(duk_context *ctx)
ILibProcessPipe_WaitHandle_Remove(data->pipeManager, data->overlapped.hEvent);
CloseHandle(data->h);
data->h = NULL;
#elif defined(_POSIX) && !defined(__APPLE__)
#elif defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD)
ILibHashtable_Remove(data->linuxWatcher->watchTable, data->wd.p, NULL, 0);
if (inotify_rm_watch(data->linuxWatcher->fd, data->wd.i) != 0) { ILibRemoteLogging_printf(ILibChainGetLogger(Duktape_GetChain(ctx)), ILibRemoteLogging_Modules_Agent_GuardPost | ILibRemoteLogging_Modules_ConsolePrint, ILibRemoteLogging_Flags_VerbosityLevel_1, "FSWatcher.close(): Error removing wd[%d] from fd[%d]", data->wd.i, data->linuxWatcher->fd); }
else
@@ -1046,7 +1046,7 @@ duk_ret_t ILibDuktape_fs_watcher_finalizer(duk_context *ctx)
return 0;
}
#if defined(_POSIX) && !defined(__APPLE__)
#if defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD)
void ILibDuktape_fs_notifyDispatcher_PreSelect(void* object, fd_set *readset, fd_set *writeset, fd_set *errorset, int* blocktime)
{
ILibDuktape_fs_linuxWatcher *data = (ILibDuktape_fs_linuxWatcher*)object;
@@ -1296,7 +1296,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx)
duk_pop(ctx); // ...
}
#elif defined(_POSIX)
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(_FREEBSD)
// Linux
ILibDuktape_fs_linuxWatcher *notifyDispatcher = NULL;
duk_push_this(ctx); // [fs]
@@ -1320,7 +1320,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx)
duk_put_prop_string(ctx, -2, FS_NOTIFY_DISPATCH_PTR); // [fs]
duk_pop(ctx); // ...
}
#else
#elif defined(__APPLE__)
// MacOS
ILibDuktape_fs_appleWatcher *watcher = NULL;
duk_push_this(ctx); // [fs]
@@ -1363,7 +1363,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx)
data->chain = chain;
data->pipeManager = pipeMgr;
data->recursive = recursive;
#elif defined(_POSIX) && !defined(__APPLE__)
#elif defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD)
data->linuxWatcher = notifyDispatcher;
#endif
#ifdef __APPLE__
@@ -1396,7 +1396,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx)
return(ILibDuktape_Error(ctx, "fs.watch(): Error creating watcher"));
}
ILibProcessPipe_WaitHandle_Add(pipeMgr, data->overlapped.hEvent, data, ILibDuktape_fs_watch_iocompletion);
#elif defined(_POSIX) && !defined(__APPLE__)
#elif defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD)
data->wd.i = inotify_add_watch(data->linuxWatcher->fd, path, IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVED_FROM | IN_MOVED_TO);
if (data->wd.i < 0)
{