You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ti...@apache.org on 2015/06/05 18:07:17 UTC

mesos git commit: Added support for Solaris within stout.

Repository: mesos
Updated Branches:
  refs/heads/master 482a944b3 -> c0b32fc71


Added support for Solaris within stout.

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


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

Branch: refs/heads/master
Commit: c0b32fc713a5358ee64d48cf3711531ff587eb54
Parents: 482a944
Author: Stan Teresen <su...@gmail.com>
Authored: Fri Jun 5 18:06:08 2015 +0200
Committer: Till Toenshoff <to...@me.com>
Committed: Fri Jun 5 18:06:09 2015 +0200

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os.hpp         |  21 +++-
 .../3rdparty/stout/include/stout/os/open.hpp    |   3 +
 .../3rdparty/stout/include/stout/os/read.hpp    |  17 +++
 .../stout/include/stout/os/sendfile.hpp         |   6 +-
 .../3rdparty/stout/include/stout/os/sunos.hpp   | 115 +++++++++++++++++++
 5 files changed, 157 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c0b32fc7/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 68626b0..95b4b33 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -19,7 +19,15 @@
 #endif
 #include <dirent.h>
 #include <errno.h>
+#ifdef __sun
+#include <sys/loadavg.h>
+#define dirfd(dir) ((dir)->d_fd)
+#ifndef NAME_MAX
+#define NAME_MAX MAXNAMLEN
+#endif // NAME_MAX
+#else
 #include <fts.h>
+#endif // __sun
 #include <glob.h>
 #include <grp.h>
 #include <libgen.h>
@@ -79,6 +87,9 @@
 #include <stout/os/osx.hpp>
 #endif // __APPLE__
 #include <stout/os/permissions.hpp>
+#ifdef __sun
+#include <stout/os/sunos.hpp>
+#endif // __sun
 #include <stout/os/pstree.hpp>
 #include <stout/os/read.hpp>
 #include <stout/os/rename.hpp>
@@ -90,11 +101,15 @@
 #include <stout/os/sysctl.hpp>
 #endif // __APPLE__
 
-#ifdef __APPLE__
+#if defined(__APPLE__)
 // Assigning the result pointer to ret silences an unused var warning.
 #define gethostbyname2_r(name, af, ret, buf, buflen, result, h_errnop)  \
   ({ (void)ret; *(result) = gethostbyname2(name, af); 0; })
-#endif // __APPLE__
+#elif defined(__sun)
+#define gethostbyname2_r(name, af, ret, buf, buflen, result, h_errnop)  \
+  ({ (void)af; *(result) = \
+    gethostbyname_r(name, ret, buf, buflen, h_errnop); 0; })
+#endif
 
 // Need to declare 'environ' pointer for non OS X platforms.
 #ifndef __APPLE__
@@ -403,6 +418,7 @@ inline Try<std::string> mkdtemp(const std::string& path = "/tmp/XXXXXX")
 // By default, recursively deletes a directory akin to: 'rm -r'. If the
 // programmer sets recursive to false, it deletes a directory akin to: 'rmdir'.
 // Note that this function expects an absolute path.
+#ifndef __sun // FTS is not available on Solaris.
 inline Try<Nothing> rmdir(const std::string& directory, bool recursive = true)
 {
   if (!recursive) {
@@ -447,6 +463,7 @@ inline Try<Nothing> rmdir(const std::string& directory, bool recursive = true)
 
   return Nothing();
 }
+#endif // __sun
 
 
 // Executes a command by calling "/bin/sh -c <command>", and returns

http://git-wip-us.apache.org/repos/asf/mesos/blob/c0b32fc7/3rdparty/libprocess/3rdparty/stout/include/stout/os/open.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/open.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/open.hpp
index 86949ec..134453e 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/open.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/open.hpp
@@ -44,6 +44,9 @@ namespace os {
 #elif defined(__linux__)
 // Copied from '/usr/include/asm-generic/fcntl.h'.
 #define O_CLOEXEC 02000000
+#elif defined(__sun)
+// Not defined on Solaris, taking a spare flag.
+#define O_CLOEXEC 0x1000000
 #endif
 #endif
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/c0b32fc7/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
index b0ed5cc..59cde89 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
@@ -17,6 +17,10 @@
 #include <stdio.h>
 #include <unistd.h>
 
+#ifdef __sun
+#include <fstream>
+#endif // __sun
+
 #include <stout/error.hpp>
 #include <stout/result.hpp>
 #include <stout/try.hpp>
@@ -64,6 +68,18 @@ inline Result<std::string> read(int fd, size_t size)
 
 
 // Returns the contents of the file.
+#ifdef __sun // getline is not available on Solaris, using STL.
+inline Try<std::string> read(const std::string& path)
+{
+  std::ifstream ifs(path.c_str());
+  if (!ifs.is_open())
+  {
+    return ErrnoError("Failed to open file '" + path + "'");
+  }
+  return std::string((std::istreambuf_iterator<char>(ifs)),
+                     (std::istreambuf_iterator<char>()));
+}
+#else
 inline Try<std::string> read(const std::string& path)
 {
   FILE* file = fopen(path.c_str(), "r");
@@ -103,6 +119,7 @@ inline Try<std::string> read(const std::string& path)
   fclose(file);
   return result;
 }
+#endif // __sun
 
 } // namespace os {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/c0b32fc7/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp
index 81d64cc..4485e41 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp
@@ -16,9 +16,9 @@
 
 #include <errno.h>
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__sun)
 #include <sys/sendfile.h>
-#endif // __linux__
+#endif
 #ifdef __APPLE__
 #include <sys/socket.h>
 #include <sys/types.h>
@@ -39,7 +39,7 @@ namespace os {
 //   2. fd must be a regular file descriptor.
 inline ssize_t sendfile(int s, int fd, off_t offset, size_t length)
 {
-#ifdef __linux__
+#if defined(__linux__) || defined(__sun)
   suppress (SIGPIPE) {
     // This will set errno to EPIPE if a SIGPIPE occurs.
     return ::sendfile(s, fd, &offset, length);

http://git-wip-us.apache.org/repos/asf/mesos/blob/c0b32fc7/3rdparty/libprocess/3rdparty/stout/include/stout/os/sunos.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sunos.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sunos.hpp
new file mode 100644
index 0000000..cfe6d74
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sunos.hpp
@@ -0,0 +1,115 @@
+/**
+ * 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_SUNOS_HPP__
+#define __STOUT_OS_SUNOS_HPP__
+
+// This file contains Solaris-only OS utilities.
+#ifndef __sun
+#error "stout/os/sunos.hpp is only available on Solaris systems."
+#endif
+
+#include <sys/types.h> // For pid_t.
+#include <fcntl.h>
+#include <procfs.h>
+
+#include <set>
+
+#include <stout/error.hpp>
+#include <stout/foreach.hpp>
+#include <stout/option.hpp>
+#include <stout/result.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/process.hpp>
+#include <stout/os/open.hpp>
+
+namespace os {
+
+inline Result<Process> process(pid_t pid)
+{
+  std::string fn = "/proc/" + stringify(pid) + "/status";
+  struct pstatus pstatus;
+
+  Try<int> fd = os::open(fn, O_RDONLY);
+  if (fd.isError()) {
+    return ErrnoError("Cannot open " + fn);
+  }
+
+  if (::read(fd.get(), &pstatus, sizeof(pstatus)) != sizeof(pstatus))
+  {
+    os::close(fd.get());
+    return Error("Cannot read from " + fn);
+  }
+  os::close(fd.get());
+
+  fn = "/proc/" + stringify(pid) + "/psinfo";
+  struct psinfo psinfo;
+
+  fd = os::open(fn, O_RDONLY);
+  if (fd.isError()) {
+    return ErrnoError("Cannot open " + fn);
+  }
+
+  if (::read(fd.get(), &psinfo, sizeof(psinfo)) != sizeof(psinfo))
+  {
+    os::close(fd.get());
+    return Error("Cannot read from " + fn);
+  }
+  os::close(fd.get());
+
+  Try<Duration> utime =
+    Seconds(pstatus.pr_utime.tv_sec) + Nanoseconds(pstatus.pr_utime.tv_nsec);
+  Try<Duration> stime =
+    Seconds(pstatus.pr_stime.tv_sec) + Nanoseconds(pstatus.pr_stime.tv_nsec);
+
+  return Process(pstatus.pr_pid,
+                 pstatus.pr_ppid,
+                 pstatus.pr_ppid,
+                 pstatus.pr_sid,
+                 None(),
+                 utime.isSome() ? utime.get() : Option<Duration>::none(),
+                 stime.isSome() ? stime.get() : Option<Duration>::none(),
+                 psinfo.pr_fname,
+                 (psinfo.pr_nzomb == 0) &&
+                  (psinfo.pr_nlwp == 0) &&
+                  (psinfo.pr_lwp.pr_lwpid == 0));
+}
+
+// Reads from /proc and returns a list of all running processes.
+inline Try<std::set<pid_t> > pids()
+{
+  std::set<pid_t> pids;
+
+  Try<std::list<std::string> > entries = os::ls("/proc");
+  if (entries.isError()) {
+    return Error("Failed to list files in /proc: " + entries.error());
+  }
+
+  foreach (const std::string& entry, entries.get()) {
+    Try<pid_t> pid = numify<pid_t>(entry);
+    if (pid.isSome()) {
+      pids.insert(pid.get()); // Ignore entries that can't be numified.
+    }
+  }
+
+  if (!pids.empty()) {
+    return pids;
+  }
+
+  return Error("Failed to determine pids from /proc");
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_SUNOS_HPP__