From ad6c64548dcf84bde30f844cd4a9dd221a48002d Mon Sep 17 00:00:00 2001 From: Jan Bramkamp Date: Mon, 23 Jun 2014 20:15:47 +0200 Subject: [PATCH 1/4] Include as required. The msghdr structure used in static yerr_t _command_list_loop(void*,ybin_t,ybin_t) is defined in . Fixes build error on FreeBSD. --- src/server/command_list.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/command_list.c b/src/server/command_list.c index 4dc78e9..c12c44e 100644 --- a/src/server/command_list.c +++ b/src/server/command_list.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "nanomsg/nn.h" #include "snappy.h" From 47f7810dc6457905040f14ee855b87b34ac4603d Mon Sep 17 00:00:00 2001 From: Jan Bramkamp Date: Mon, 23 Jun 2014 20:33:17 +0200 Subject: [PATCH 2/4] Implement const char *get_self_path() for FreeBSD. Each platform offers a different API for reading the path to the executable file. On FreeBSD this path is readable through a sysctl MIB. --- src/server/self_path.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/server/self_path.c b/src/server/self_path.c index 2f2647d..238701b 100644 --- a/src/server/self_path.c +++ b/src/server/self_path.c @@ -53,4 +53,26 @@ const char *get_self_path() { return (path); } +#elif defined __FreeBSD__ + +# include +# include +# include + +const char *get_self_path() { + static char path[PATH_MAX] = { '\0' }; + + if ( path[0] == '\0' ) { + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + size_t size = sizeof(path); + char *pt; + + sysctl(mib, sizeof(mib)/sizeof(*mib), path, &size, NULL, 0); + if ((pt = strrchr(path, '/')) != NULL) + *pt = '\0'; + return path; + } + return path; +} + #endif From a06fef71bed9d1bfa5f56f05663504d41a077079 Mon Sep 17 00:00:00 2001 From: Jan Bramkamp Date: Mon, 23 Jun 2014 20:39:30 +0200 Subject: [PATCH 3/4] Only include on Linux. The header is Linux specific and src/server/server.c compiles on FreeBSD without including this header. --- src/server/server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/server.c b/src/server/server.c index 081d9cf..ac79f71 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -1,4 +1,6 @@ +#ifdef __linux__ #include +#endif #include #include #include From 57b9348f5a186f43ecd19a9f64fe9f450fcc806d Mon Sep 17 00:00:00 2001 From: Jan Bramkamp Date: Mon, 23 Jun 2014 20:50:39 +0200 Subject: [PATCH 4/4] Add automatic fallback from O_DSYNC to O_SYNC. Some platforms (e.g. FreeBSD) lack O_DSYNC. It is easier and cleaner to detect a missing define with ifdefs than with make. --- lib/lmdb/mdb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/lmdb/mdb.c b/lib/lmdb/mdb.c index a90d7d5..e73bbd5 100644 --- a/lib/lmdb/mdb.c +++ b/lib/lmdb/mdb.c @@ -237,7 +237,11 @@ mdb_sem_wait(sem_t *sem) * Otherwise compile with the less efficient -DMDB_DSYNC=O_SYNC. */ #ifndef MDB_DSYNC +#ifdef O_DSYNC # define MDB_DSYNC O_DSYNC +#else +# define MDB_DSYNC O_SYNC +#endif #endif #endif