Repository: mesos
Updated Branches:
  refs/heads/master dc6cde747 -> e590f2fd2


FreeBSD: Add basic support to stout

Review: https://reviews.apache.org/r/39636/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ef38ec31
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ef38ec31
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ef38ec31

Branch: refs/heads/master
Commit: ef38ec31072a2449477d90b81236365ad6f038c2
Parents: dc6cde7
Author: David Forsythe <[email protected]>
Authored: Mon Dec 14 09:23:54 2015 -0800
Committer: Ian Downes <[email protected]>
Committed: Mon Dec 14 09:25:55 2015 -0800

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/ip.hpp         |  6 +-
 .../3rdparty/stout/include/stout/mac.hpp        |  4 +-
 .../3rdparty/stout/include/stout/net.hpp        | 10 ++-
 .../3rdparty/stout/include/stout/os.hpp         | 28 ++++---
 .../3rdparty/stout/include/stout/os/freebsd.hpp | 77 ++++++++++++++++++++
 .../stout/include/stout/os/posix/bootid.hpp     |  6 +-
 .../stout/include/stout/os/posix/fork.hpp       |  3 +
 .../stout/include/stout/os/posix/sendfile.hpp   | 19 ++++-
 .../stout/include/stout/os/posix/signals.hpp    |  5 ++
 .../stout/include/stout/os/raw/environment.hpp  |  2 +-
 .../3rdparty/stout/include/stout/os/sysctl.hpp  |  4 +-
 .../3rdparty/stout/include/stout/posix/os.hpp   |  3 +
 .../stout/tests/dynamiclibrary_tests.cpp        |  2 +
 .../3rdparty/stout/tests/os_tests.cpp           | 54 ++++++++++++--
 14 files changed, 191 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
index 1d34d4e..ffeb2d7 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
@@ -18,9 +18,9 @@
 #include <arpa/inet.h>
 #endif // __WINDOWS__
 
-#if defined(__linux__) || defined(__APPLE__)
+#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
 #include <ifaddrs.h>
-#endif // __linux__ || __APPLE__
+#endif // __linux__ || __APPLE__ || __FreeBSD__
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
@@ -427,7 +427,7 @@ inline Result<IPNetwork> IPNetwork::fromLinkDevice(
     const std::string& name,
     int family)
 {
-#if !defined(__linux__) && !defined(__APPLE__)
+#if !defined(__linux__) && !defined(__APPLE__) && !defined(__FreeBSD__)
   return Error("Not implemented");
 #else
   if (family != AF_INET) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp
index a1af2c4..09c0d49 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp
@@ -13,7 +13,7 @@
 #ifndef __STOUT_MAC_HPP__
 #define __STOUT_MAC_HPP__
 
-#if defined(__linux__) || defined(__APPLE__)
+#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
 #include <ifaddrs.h>
 #endif
 #include <stdint.h>
@@ -138,7 +138,7 @@ inline std::ostream& operator<<(std::ostream& stream, const 
MAC& mac)
 // does not have a MAC address (e.g., loopback).
 inline Result<MAC> mac(const std::string& name)
 {
-#if !defined(__linux__) && !defined(__APPLE__)
+#if !defined(__linux__) && !defined(__APPLE__) && !defined(__FreeBSD__)
   return Error("Not implemented");
 #else
   struct ifaddrs* ifaddr = NULL;

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp
index 828ac46..3c80910 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp
@@ -31,6 +31,10 @@
 #include <net/if_types.h>
 #endif // __APPLE__
 
+#ifdef __FreeBSD__
+#include <ifaddrs.h>
+#endif // __FreeBSD__
+
 // Note: Header grouping and ordering is considered before
 // inclusion/exclusion by platform.
 #ifndef __WINDOWS__
@@ -248,7 +252,11 @@ inline Try<std::string> getHostname(const IP& ip)
 
   int error = getnameinfo(
       (struct sockaddr*) &storage,
+#ifdef __FreeBSD__
+      sizeof(struct sockaddr_in),
+#else
       sizeof(storage),
+#endif
       hostname,
       MAXHOSTNAMELEN,
       NULL,
@@ -266,7 +274,7 @@ inline Try<std::string> getHostname(const IP& ip)
 // Returns the names of all the link devices in the system.
 inline Try<std::set<std::string>> links()
 {
-#if !defined(__linux__) && !defined(__APPLE__)
+#if !defined(__linux__) && !defined(__APPLE__) && !defined(__FreeBSD__)
   return Error("Not implemented");
 #else
   struct ifaddrs* ifaddr = NULL;

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 581ec5b..14fbca6 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -216,9 +216,10 @@ inline Try<Version> release()
     return Error(info.error());
   }
 
+  int major, minor, patch = 0;
+#ifndef __FreeBSD__
   // TODO(karya): Replace sscanf with Version::parse() once Version
   // starts supporting labels and build metadata.
-  int major, minor, patch;
   if (::sscanf(
           info.get().release.c_str(),
           "%d.%d.%d",
@@ -227,7 +228,12 @@ inline Try<Version> release()
           &patch) != 3) {
     return Error("Failed to parse: " + info.get().release);
   }
-
+#else
+  // TODO(dforsyth): Handle FreeBSD patch versions (-pX).
+  if (::sscanf(info.get().release.c_str(), "%d.%d-%*s", &major, &minor) != 2) {
+    return Error("Failed to parse: " + info.get().release);
+  }
+#endif
   return Version(major, minor, patch);
 }
 
@@ -294,10 +300,10 @@ inline std::string expandName(const std::string& 
libraryName)
 {
   const char* prefix = "lib";
   const char* extension =
-#ifdef __linux__
-    ".so";
-#else
+#ifdef __APPLE__
     ".dylib";
+#else
+    ".so";
 #endif
 
   return prefix + libraryName + extension;
@@ -308,10 +314,10 @@ inline std::string expandName(const std::string& 
libraryName)
 inline std::string paths()
 {
   const char* environmentVariable =
-#ifdef __linux__
-    "LD_LIBRARY_PATH";
-#else
+#ifdef __APPLE__
     "DYLD_LIBRARY_PATH";
+#else
+    "LD_LIBRARY_PATH";
 #endif
   const Option<std::string> path = getenv(environmentVariable);
   return path.isSome() ? path.get() : std::string();
@@ -322,10 +328,10 @@ inline std::string paths()
 inline void setPaths(const std::string& newPaths)
 {
   const char* environmentVariable =
-#ifdef __linux__
-    "LD_LIBRARY_PATH";
-#else
+#ifdef __APPLE__
     "DYLD_LIBRARY_PATH";
+#else
+    "LD_LIBRARY_PATH";
 #endif
   setenv(environmentVariable, newPaths);
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/os/freebsd.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/freebsd.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/freebsd.hpp
new file mode 100644
index 0000000..269e35f
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/freebsd.hpp
@@ -0,0 +1,77 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_FREEBSD_HPP__
+#define __STOUT_OS_FREEBSD_HPP__
+
+// This file contains FreeBSD-only OS utilities.
+#ifndef __FreeBSD__
+#error "stout/os/freebsd.hpp is only available on FreeBSD systems."
+#endif
+
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#ifdef __FreeBSD__
+#include <stout/os/freebsd.hpp>
+#endif
+#include <sys/user.h>
+#include <unistd.h>
+
+namespace os {
+
+inline Result<Process> process(pid_t pid)
+{
+  // KERN_PROC_PID fails for zombies, so we fetch the whole process table and
+  // find our process manually.
+
+  const Try<std::vector<kinfo_proc>> kinfos =
+    os::sysctl(CTL_KERN, KERN_PROC, KERN_PROC_ALL).table();
+
+  if (kinfos.isError()) {
+    return Error("Failed to retrieve process table via sysctl: " +
+                 kinfos.error());
+  }
+
+  foreach (const kinfo_proc& kinfo, kinfos.get()) {
+    if (kinfo.ki_pid == pid) {
+      int pagesize = getpagesize();
+      return Process(kinfo.ki_pid,
+                     kinfo.ki_ppid,
+                     kinfo.ki_pgid,
+                     kinfo.ki_sid,
+                     kinfo.ki_rssize * pagesize,
+                     kinfo.ki_rusage.ru_utime,
+                     kinfo.ki_rusage.ru_stime,
+                     kinfo.ki_comm,
+                     kinfo.ki_stat == SZOMB);
+    }
+  }
+
+  return None();
+}
+
+inline Try<std::set<pid_t>> pids()
+{
+  std::set<pid_t> result;
+
+  const Try<std::vector<kinfo_proc>> kinfos =
+    os::sysctl(CTL_KERN, KERN_PROC, KERN_PROC_ALL).table();
+
+  foreach (const kinfo_proc& kinfo, kinfos.get()) {
+    result.insert(kinfo.ki_pid);
+  }
+
+  return result;
+}
+} // namespace os {
+
+#endif

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp
----------------------------------------------------------------------
diff --git 
a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp
index 84659e8..7ea5e46 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp
@@ -23,9 +23,9 @@
 #include <stout/try.hpp>
 
 #include <stout/os/read.hpp>
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #include <stout/os/sysctl.hpp>
-#endif // __APPLE__
+#endif // __APPLE__ || __FreeBSD__
 
 
 namespace os {
@@ -38,7 +38,7 @@ inline Try<std::string> bootId()
     return read;
   }
   return strings::trim(read.get());
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) || defined(__FreeBSD__)
   // For OS X, we use the boot time in seconds as a unique boot id.
   // Although imperfect, this works quite well in practice. NOTE: we can't use
   // milliseconds here instead of seconds because the relatively high

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp
index fb73158..11557e3 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp
@@ -17,6 +17,9 @@
 #include <unistd.h>
 
 #include <sys/mman.h>
+#ifdef __FreeBSD__
+#include <sys/stat.h>
+#endif // __FreeBSD__
 #include <sys/types.h>
 #include <sys/wait.h>
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp
----------------------------------------------------------------------
diff --git 
a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp
index 5fd80f3..293f82f 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp
@@ -18,11 +18,11 @@
 #if defined(__linux__) || defined(__sun)
 #include <sys/sendfile.h>
 #endif
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/uio.h>
-#endif // __APPLE__
+#endif // __APPLE__ || __FreeBSD__
 
 #include <stout/os/signals.hpp>
 #include <stout/unreachable.hpp>
@@ -56,7 +56,20 @@ inline ssize_t sendfile(int s, int fd, off_t offset, size_t 
length)
   }
 
   return _length;
-#endif // __APPLE__
+#elif defined __FreeBSD__
+  off_t _length = 0;
+
+  SUPPRESS (SIGPIPE) {
+      if (::sendfile(fd, s, offset, length, NULL, &_length, 0) < 0) {
+        if (errno == EAGAIN && length > 0) {
+          return _length;
+        }
+        return -1;
+      }
+  }
+
+  return _length;
+#endif
 }
 
 } // namespace os {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/signals.hpp
----------------------------------------------------------------------
diff --git 
a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/signals.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/signals.hpp
index 8f73397..f46f591 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/signals.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/signals.hpp
@@ -144,7 +144,12 @@ struct Suppressor
       // We chose to use the latter technique as it works on all
       // POSIX systems and is less likely to swallow process signals,
       // provided the thread signal and process signal are not merged.
+
+      // Delivering on this thread an extra time will require an extra sigwait
+      // call on FreeBSD, so we skip it.
+#ifndef __FreeBSD__
       pthread_kill(pthread_self(), signal);
+#endif
 
       sigset_t mask;
       sigemptyset(&mask);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/os/raw/environment.hpp
----------------------------------------------------------------------
diff --git 
a/3rdparty/libprocess/3rdparty/stout/include/stout/os/raw/environment.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/raw/environment.hpp
index b173682..80cc45b 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/raw/environment.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/raw/environment.hpp
@@ -15,7 +15,7 @@
 
 #ifdef __APPLE__
 #include <crt_externs.h> // For _NSGetEnviron().
-#elif defined(__linux__)
+#elif !defined(__WINDOWS__)
 // Need to declare 'environ' pointer for platforms that are not OS X or 
Windows.
 extern char** environ;
 #endif

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp
index 46bf489..8cfc77f 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp
@@ -14,8 +14,8 @@
 #define __STOUT_OS_SYSCTL_HPP__
 
 // Only provide sysctl support for OS X.
-#ifndef __APPLE__
-#error "stout/os/sysctl.hpp is only available on OS X."
+#if !defined(__APPLE__) && !defined(__FreeBSD__)
+#error "stout/os/sysctl.hpp is only available on OS X and FreeBSD."
 #endif
 
 #include <sys/sysctl.h>

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
index 42733d4..4cf693f 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
@@ -67,6 +67,9 @@
 #include <stout/os/exists.hpp>
 #include <stout/os/fcntl.hpp>
 #include <stout/os/fork.hpp>
+#ifdef __FreeBSD__
+#include <stout/os/freebsd.hpp>
+#endif
 #ifdef __linux__
 #include <stout/os/linux.hpp>
 #endif // __linux__

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp 
b/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp
index 1a23c44..27626ae 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp
@@ -23,6 +23,8 @@ TEST(DynamicLibraryTest, LoadKnownSymbol)
 
 #ifdef __linux__
   Try<Nothing> result = dltest.open("libdl.so");
+#elif defined(__FreeBSD__)
+  Try<Nothing> result = dltest.open("libc.so.7");
 #else
   Try<Nothing> result = dltest.open("libdl.dylib");
 #endif

http://git-wip-us.apache.org/repos/asf/mesos/blob/ef38ec31/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp 
b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
index 743facd..e0a898d 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
@@ -15,6 +15,10 @@
 #ifndef __linux__
 #include <sys/time.h> // For gettimeofday.
 #endif
+#ifdef __FreeBSD__
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#endif
 
 #include <cstdlib> // For rand.
 #include <list>
@@ -40,7 +44,7 @@
 #include <stout/try.hpp>
 #include <stout/uuid.hpp>
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #include <stout/os/sysctl.hpp>
 #endif
 
@@ -70,6 +74,21 @@ static hashset<string> listfiles(const string& directory)
 }
 
 
+#ifdef __FreeBSD__
+static bool isJailed() {
+  int mib[4];
+  size_t len = 4;
+  ::sysctlnametomib("security.jail.jailed", mib, &len);
+  Try<int> jailed = os::sysctl(mib[0], mib[1], mib[2]).integer();
+  if (jailed.isSome()) {
+      return jailed.get() == 1;
+  }
+
+  return false;
+}
+#endif
+
+
 class OsTest : public TemporaryDirectoryTest {};
 
 
@@ -288,8 +307,8 @@ TEST_F(OsTest, BootId)
   Try<string> read = os::read("/proc/sys/kernel/random/boot_id");
   ASSERT_SOME(read);
   EXPECT_EQ(bootId.get(), strings::trim(read.get()));
-#elif defined(__APPLE__)
-  // For OS X systems, the boot id is the system boot time in
+#elif defined(__APPLE__) || defined(__FreeBSD__)
+  // For OS X and FreeBSD systems, the boot id is the system boot time in
   // seconds, so assert it can be numified and is a reasonable value.
   Try<uint64_t> numified = numify<uint64_t>(bootId.get());
   ASSERT_SOME(numified);
@@ -350,7 +369,7 @@ TEST_F(OsTest, Sleep)
 }
 
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
 TEST_F(OsTest, Sysctl)
 {
   // String test.
@@ -380,7 +399,11 @@ TEST_F(OsTest, Sysctl)
   std::set<pid_t> pids;
 
   foreach (const kinfo_proc& process, processes.get()) {
+#ifdef __APPLE__
     pids.insert(process.kp_proc.p_pid);
+#else
+    pids.insert(process.ki_pid);
+#endif // __APPLE__
   }
 
   EXPECT_EQ(1, pids.count(getpid()));
@@ -395,7 +418,7 @@ TEST_F(OsTest, Sysctl)
   EXPECT_GT(Seconds(bootTime.get().tv_sec), Seconds(0));
   EXPECT_LT(Seconds(bootTime.get().tv_sec), Seconds(time.tv_sec));
 }
-#endif // __APPLE__
+#endif // __APPLE__ || __FreeBSD__
 
 
 TEST_F(OsTest, Pids)
@@ -404,7 +427,15 @@ TEST_F(OsTest, Pids)
   ASSERT_SOME(pids);
   EXPECT_NE(0u, pids.get().size());
   EXPECT_EQ(1u, pids.get().count(getpid()));
-  EXPECT_EQ(1u, pids.get().count(1));
+
+  // In a FreeBSD jail, pid 1 may not exist.
+#ifdef __FreeBSD__
+  if (!isJailed()) {
+#endif
+    EXPECT_EQ(1u, pids.get().count(1));
+#ifdef __FreeBSD__
+  }
+#endif
 
   pids = os::pids(getpgid(0), None());
   EXPECT_SOME(pids);
@@ -738,10 +769,18 @@ TEST_F(OsTest, KilltreeNoRoot)
   ASSERT_NE(child, _grandchild.get().parent);
   ASSERT_FALSE(_grandchild.get().zombie);
 
+  // Check to see if we're in a jail on FreeBSD in case we've been
+  // reparented to pid 1
+#if __FreeBSD__
+  if (!isJailed()) {
+#endif
   // Check that grandchild's parent is also not a zombie.
   Result<os::Process> currentParent = os::process(_grandchild.get().parent);
   ASSERT_SOME(currentParent);
   ASSERT_FALSE(currentParent.get().zombie);
+#ifdef __FreeBSD__
+  }
+#endif
 
 
   // Kill the process tree. Even though the root process has exited,
@@ -821,10 +860,13 @@ TEST_F(OsTest, ProcessExists)
   // Check we exist.
   EXPECT_TRUE(os::exists(::getpid()));
 
+  // In a FreeBSD jail, pid 1 may not exist.
+#if !defined(__FreeBSD__)
   // Check init/launchd/systemd exists.
   // NOTE: This should return true even if we don't have permission to signal
   // the pid.
   EXPECT_TRUE(os::exists(1));
+#endif
 
   // Check existence of a child process through its lifecycle: running,
   // zombied, reaped.

Reply via email to