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

[1/3] mesos git commit: Windows: Added support for `files/files.hpp`.

Repository: mesos
Updated Branches:
  refs/heads/master 050736825 -> a798048b2


Windows: Added support for `files/files.hpp`.

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


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

Branch: refs/heads/master
Commit: a798048b24bfba9de552a1551c14dd167bcbd3a8
Parents: 33d332e
Author: Alex Clemmer <cl...@gmail.com>
Authored: Thu Dec 17 13:35:04 2015 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Dec 17 13:35:51 2015 -0800

----------------------------------------------------------------------
 src/files/files.hpp | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a798048b/src/files/files.hpp
----------------------------------------------------------------------
diff --git a/src/files/files.hpp b/src/files/files.hpp
index 60049c0..7b65a0a 100644
--- a/src/files/files.hpp
+++ b/src/files/files.hpp
@@ -17,8 +17,13 @@
 #ifndef __FILES_HPP__
 #define __FILES_HPP__
 
+#ifdef __WINDOWS__
+#include <stout/internal/windows/grp.hpp>
+#include <stout/internal/windows/pwd.hpp>
+#else
 #include <grp.h>
 #include <pwd.h>
+#endif // __WINDOWS__
 
 #include <sys/stat.h>
 
@@ -32,6 +37,12 @@
 #include <stout/nothing.hpp>
 #include <stout/path.hpp>
 
+#include <stout/os/permissions.hpp>
+
+#ifdef __WINDOWS__
+#include <stout/windows.hpp>
+#endif // __WINDOWS__
+
 namespace mesos {
 namespace internal {
 
@@ -105,22 +116,22 @@ inline JSON::Object jsonFileInfo(const std::string& path,
     filetype = '-';
   }
 
-  int owner = (s.st_mode & 0700) >> 6;
-  int group = (s.st_mode & 0070) >> 3;
-  int other = s.st_mode & 0007;
+  struct os::Permissions permissions(s.st_mode);
 
-  file.values["mode"] = strings::format("%c%c%c%c%c%c%c%c%c%c",
+  file.values["mode"] = strings::format(
+      "%c%c%c%c%c%c%c%c%c%c",
       filetype,
-      (owner & 0x4) ? 'r' : '-',
-      (owner & 0x2) ? 'w' : '-',
-      (owner & 0x1) ? 'x' : '-',
-      (group & 0x4) ? 'r' : '-',
-      (group & 0x2) ? 'w' : '-',
-      (group & 0x1) ? 'x' : '-',
-      (other & 0x4) ? 'r' : '-',
-      (other & 0x2) ? 'w' : '-',
-      (other & 0x1) ? 'x' : '-').get();
-
+      permissions.owner.r ? 'r' : '-',
+      permissions.owner.w ? 'w' : '-',
+      permissions.owner.x ? 'x' : '-',
+      permissions.group.r ? 'r' : '-',
+      permissions.group.w ? 'w' : '-',
+      permissions.group.x ? 'x' : '-',
+      permissions.others.r ? 'r' : '-',
+      permissions.others.w ? 'w' : '-',
+      permissions.others.x ? 'x' : '-').get();
+
+  // NOTE: `getpwuid` and `getgrgid` return `NULL` on Windows.
   passwd* p = getpwuid(s.st_uid);
   if (p != NULL) {
     file.values["uid"] = p->pw_name;


[2/3] mesos git commit: Windows: Stout: Added compatibility code for `grp.h` and `pwd.h`.

Posted by jo...@apache.org.
Windows: Stout: Added compatibility code for `grp.h` and `pwd.h`.

This code will be particularly useful when we expand Windows support for
`files/files.hpp`.

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


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

Branch: refs/heads/master
Commit: 33d332ef4bbb339df96f442a90e8775d48a0f817
Parents: ce09c58
Author: Alex Clemmer <cl...@gmail.com>
Authored: Wed Dec 16 17:17:49 2015 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Dec 17 13:35:51 2015 -0800

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  2 +
 .../include/stout/internal/windows/grp.hpp      | 51 +++++++++++++++++++
 .../include/stout/internal/windows/pwd.hpp      | 52 ++++++++++++++++++++
 .../3rdparty/stout/include/stout/windows.hpp    | 11 +++++
 4 files changed, 116 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/33d332ef/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index d1ef6f0..b2dea9b 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -36,6 +36,8 @@ nobase_include_HEADERS =		\
   stout/gzip.hpp			\
   stout/hashmap.hpp			\
   stout/hashset.hpp			\
+  stout/internal/windows/grp.hpp	\
+  stout/internal/windows/pwd.hpp	\
   stout/interval.hpp			\
   stout/ip.hpp				\
   stout/json.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/33d332ef/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/grp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/grp.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/grp.hpp
new file mode 100644
index 0000000..1b74be6
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/grp.hpp
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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_INTERNAL_WINDOWS_GRP_HPP__
+#define __STOUT_INTERNAL_WINDOWS_GRP_HPP__
+
+#include <sys/types.h>
+
+#include <stout/windows.hpp>
+
+
+// Dummy struct for POSIX compliance.
+struct group
+{
+  char* gr_name; // The name of the group.
+  gid_t gr_gid;  // Numerical group ID.
+  char** gr_mem; // Pointer to a null-terminated array of character pointers to
+                 // member names.
+};
+
+
+extern "C" {
+// Dummy implementation of `getgrgid` for POSIX compliance. Per the POSIX
+// specification[1], we are to return `NULL` if an entry matching the GID is
+// not found. On Windows, we will never find such an entry, so we always return
+// `NULL`. Just to be safe, we also set `errno` to `ENOSYS` which indicates the
+// function is not implemented.
+//
+// [1] http://pubs.opengroup.org/onlinepubs/009695399/functions/getgrgid.html
+struct group* getgrgid(gid_t)
+{
+  errno = ENOSYS;
+  return NULL;
+}
+} // extern "C" {
+
+
+#endif // __STOUT_INTERNAL_WINDOWS_GRP_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/33d332ef/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/pwd.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/pwd.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/pwd.hpp
new file mode 100644
index 0000000..60990bb
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/pwd.hpp
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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_INTERNAL_WINDOWS_PWD_HPP__
+#define __STOUT_INTERNAL_WINDOWS_PWD_HPP__
+
+#include <sys/types.h>
+
+#include <stout/windows.hpp>
+
+
+// Dummy struct for POSIX compliance.
+struct passwd
+{
+  char* pw_name;  // User's login name.
+  uid_t pw_uid;   // Numerical user ID.
+  gid_t pw_gid;   // Numerical group ID.
+  char* pw_dir;   // Initial working directory.
+  char* pw_shell; // Program to use as shell.
+};
+
+
+extern "C" {
+// Dummy implementation of `getpwuid` for POSIX compliance. Per the POSIX
+// specification[1], we are to return `NULL` if an entry matching the UID is
+// not found. On Windows, we will never find such an entry, so we always return
+// `NULL`. Just to be safe, we also set `errno` to `ENOSYS` which indicates the
+// function is not implemented.
+//
+// [1] http://pubs.opengroup.org/onlinepubs/009695399/functions/getgrgid.html
+struct passwd* getpwuid(uid_t)
+{
+  errno = ENOSYS;
+  return NULL;
+}
+} // extern "C" {
+
+
+#endif // __STOUT_INTERNAL_WINDOWS_PWD_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/33d332ef/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
index 6711a16..d46e262 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
@@ -120,6 +120,9 @@ typedef int mode_t;
 // including functions like `OpenProcess`.
 typedef DWORD pid_t;
 
+typedef int uid_t;
+typedef int gid_t;
+
 typedef SSIZE_T ssize_t;
 
 // Socket flags. Define behavior of a socket when it (e.g.) shuts down. We map
@@ -127,6 +130,14 @@ typedef SSIZE_T ssize_t;
 // have to change any socket code.
 constexpr int SHUT_RD = SD_RECEIVE;
 
+// Macros that test whether a `stat` struct represents a directory or a file.
+#define S_ISDIR(mode)  (((mode) & S_IFMT) == S_IFDIR)  // Directory.
+#define S_ISREG(mode)  (((mode) & S_IFMT) == S_IFREG)  // File.
+#define S_ISCHR(mode)  (((mode) & S_IFMT) == S_IFCHR)  // Character device.
+#define S_ISFIFO(mode) (((mode) & S_IFMT) == _S_IFIFO) // Pipe.
+#define S_ISBLK(mode)  0                               // Block special device.
+#define S_ISSOCK(mode) 0                               // Socket.
+#define S_ISLNK(mode)  0                               // Symbolic link.
 
 // Permissions API. (cf. MESOS-3176 to track ongoing permissions work.)
 //


[3/3] mesos git commit: Windows: Replaced global `GetMessage` macro with inline function.

Posted by jo...@apache.org.
Windows: Replaced global `GetMessage` macro with inline function.

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


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

Branch: refs/heads/master
Commit: ce09c584134e0dbcbebd8b724c88ff6c81fc9247
Parents: 0507368
Author: Alex Clemmer <cl...@gmail.com>
Authored: Wed Dec 16 17:09:48 2015 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Dec 17 13:35:51 2015 -0800

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/windows.hpp    | 43 ++++++++++++++++++++
 1 file changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ce09c584/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
index 43c85f5..6711a16 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
@@ -41,6 +41,49 @@
 //     that uses it (such as Mesos).
 
 
+// This code un-defines the global `GetMessage` macro defined by the Windows
+// headers, and replaces it with an inline function that is equivalent.
+//
+// There are two reasons for doing this. The first is because this macro
+// interferes with `google::protobufs::Reflection::GetMessage`. Replacing the
+// `GetMessage` macro with an inline function allows people calling the
+// `GetMessage` macro to carry on doing so with no code changes, but it will
+// also allow us to use `google::protobufs::Reflection::GetMessage` without
+// interference from the macro.
+//
+// The second is because we don't want to obliterate the `GetMessage` macro for
+// people who include this header, either on purpose, or incidentally as part
+// of some other Mesos header. The effect is that our need to call protobuf's
+// `GetMessage` function has no deleterious effect on customers of this API.
+//
+// NOTE: the Windows headers also don't use define-once semantics for the
+// `GetMessage` macro. In particular, this means that every time you include
+// `Winuser.h` and a `GetMessage` macro isn't defined, the Windows headers will
+// redefine it for you. The impact of this is that you should re-un-define the
+// macro every time you include `Windows.h`; since we should be including
+// `Windows.h` only from this file, we un-define it just after we include
+// `Windows.h`.
+#ifdef GetMessage
+inline BOOL GetMessageWindows(
+    LPMSG lpMsg,
+    HWND hWnd,
+    UINT wMsgFilterMin,
+    UINT wMsgFilterMax)
+{
+  return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
+}
+#undef GetMessage
+inline BOOL GetMessage(
+    LPMSG lpMsg,
+    HWND hWnd,
+    UINT wMsgFilterMin,
+    UINT wMsgFilterMax)
+{
+  return GetMessageWindows(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
+}
+#endif
+
+
 // Define constants used for Windows compat. Allows a lot of code on
 // Windows and POSIX systems to be the same, because we can pass the
 // same constants to functions we call to do things like file I/O.