You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2016/09/06 16:44:01 UTC
[1/2] mesos git commit: Replaced use of `readdir_r` with `readdir`.
Repository: mesos
Updated Branches:
refs/heads/master 19c9f09ea -> ea1469fd5
Replaced use of `readdir_r` with `readdir`.
`readdir_r` is deprecated in glibc >= 2.24 [1], which breaks the build.
In practice, modern implementations of `readdir` should be thread-safe
when concurrently invoked on different directory streams.
[1] https://sourceware.org/ml/libc-alpha/2016-02/msg00093.html
Review: https://reviews.apache.org/r/51324/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5f8c187c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5f8c187c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5f8c187c
Branch: refs/heads/master
Commit: 5f8c187c238d5b76476ba74d1d3c83e08c5efaa6
Parents: 19c9f09
Author: Neil Conway <ne...@gmail.com>
Authored: Tue Sep 6 18:24:52 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Tue Sep 6 18:24:52 2016 +0200
----------------------------------------------------------------------
.../include/stout/internal/windows/dirent.hpp | 33 -------------------
3rdparty/stout/include/stout/os/ls.hpp | 34 +++++++++-----------
2 files changed, 15 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/5f8c187c/3rdparty/stout/include/stout/internal/windows/dirent.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/dirent.hpp b/3rdparty/stout/include/stout/internal/windows/dirent.hpp
index c6aa907..fe33210 100644
--- a/3rdparty/stout/include/stout/internal/windows/dirent.hpp
+++ b/3rdparty/stout/include/stout/internal/windows/dirent.hpp
@@ -144,39 +144,6 @@ inline struct dirent* readdir(DIR* directory)
// Implementation of the standard POSIX function. See documentation[1].
//
-// On success: return 0 and set `*result` (note that `result` is not the same
-// as `*result`) to point at the next directory entry, or `nullptr` if we've
-// reached the end of the stream.
-//
-// On failure: return a positive error number and set `*result` (not `result`)
-// to point at `nullptr`.
-//
-// [1] https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html
-inline int readdir_r(
- DIR* directory,
- struct dirent* entry,
- struct dirent** result)
-{
- if (directory == nullptr) {
- errno = EBADF;
- *result = nullptr;
- return 1;
- }
-
- if (!internal::reentrant_advance_dir_stream(directory)) {
- *result = nullptr;
- return 0;
- }
-
- memcpy(entry, &directory->curr, sizeof(*entry));
- *result = &directory->curr;
-
- return 0;
-}
-
-
-// Implementation of the standard POSIX function. See documentation[1].
-//
// On success, return 0; on failure, return -1 and set `errno` appropriately.
//
// [1] http://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html#Reading_002fClosing-Directory
http://git-wip-us.apache.org/repos/asf/mesos/blob/5f8c187c/3rdparty/stout/include/stout/os/ls.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/ls.hpp b/3rdparty/stout/include/stout/os/ls.hpp
index f8da9ef..25e2bec 100644
--- a/3rdparty/stout/include/stout/os/ls.hpp
+++ b/3rdparty/stout/include/stout/os/ls.hpp
@@ -18,6 +18,8 @@
#else
#include <dirent.h>
#endif // __WINDOWS__
+
+#include <errno.h>
#include <stdlib.h>
#include <list>
@@ -26,8 +28,6 @@
#include <stout/error.hpp>
#include <stout/try.hpp>
-#include <stout/os/direntsize.hpp>
-
namespace os {
@@ -36,36 +36,32 @@ inline Try<std::list<std::string>> ls(const std::string& directory)
DIR* dir = opendir(directory.c_str());
if (dir == nullptr) {
- // Preserve `opendir` error.
return ErrnoError("Failed to opendir '" + directory + "'");
}
- dirent* temp = (dirent*) malloc(os::dirent_size(dir));
-
- if (temp == nullptr) {
- // Preserve `malloc` error.
- ErrnoError error("Failed to allocate directory entries");
- closedir(dir);
- return error;
- }
-
std::list<std::string> result;
struct dirent* entry;
- int error;
- while ((error = readdir_r(dir, temp, &entry)) == 0 && entry != nullptr) {
+ // Zero `errno` before starting to call `readdir`. This is necessary
+ // to allow us to determine when `readdir` returns an error.
+ errno = 0;
+
+ while ((entry = readdir(dir)) != nullptr) {
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
result.push_back(entry->d_name);
}
- free(temp);
- closedir(dir);
+ if (errno != 0) {
+ // Preserve `readdir` error.
+ Error error = ErrnoError("Failed to read directory");
+ closedir(dir);
+ return error;
+ }
- if (error != 0) {
- // Preserve `readdir_r` error.
- return ErrnoError("Failed to read directories");
+ if (closedir(dir) == -1) {
+ return ErrnoError("Failed to close directory");
}
return result;
[2/2] mesos git commit: Removed unused function `os::dirent_size`.
Posted by al...@apache.org.
Removed unused function `os::dirent_size`.
Review: https://reviews.apache.org/r/51325/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ea1469fd
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ea1469fd
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ea1469fd
Branch: refs/heads/master
Commit: ea1469fd5fed4149739dcf6a95260c7d7b385811
Parents: 5f8c187
Author: Neil Conway <ne...@gmail.com>
Authored: Tue Sep 6 18:25:38 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Tue Sep 6 18:25:38 2016 +0200
----------------------------------------------------------------------
3rdparty/stout/include/Makefile.am | 3 --
3rdparty/stout/include/stout/os/direntsize.hpp | 26 ------------
.../stout/include/stout/os/posix/direntsize.hpp | 42 -------------------
.../include/stout/os/windows/direntsize.hpp | 43 --------------------
4 files changed, 114 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/ea1469fd/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index 1f2ee85..b0b08d8 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -64,7 +64,6 @@ nobase_include_HEADERS = \
stout/os/chroot.hpp \
stout/os/close.hpp \
stout/os/constants.hpp \
- stout/os/direntsize.hpp \
stout/os/environment.hpp \
stout/os/exists.hpp \
stout/os/fcntl.hpp \
@@ -108,7 +107,6 @@ nobase_include_HEADERS = \
stout/os/posix/chown.hpp \
stout/os/posix/chroot.hpp \
stout/os/posix/close.hpp \
- stout/os/posix/direntsize.hpp \
stout/os/posix/exists.hpp \
stout/os/posix/fcntl.hpp \
stout/os/posix/fork.hpp \
@@ -134,7 +132,6 @@ nobase_include_HEADERS = \
stout/os/windows/bootid.hpp \
stout/os/windows/chroot.hpp \
stout/os/windows/close.hpp \
- stout/os/windows/direntsize.hpp \
stout/os/windows/exists.hpp \
stout/os/windows/fcntl.hpp \
stout/os/windows/fork.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/ea1469fd/3rdparty/stout/include/stout/os/direntsize.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/direntsize.hpp b/3rdparty/stout/include/stout/os/direntsize.hpp
deleted file mode 100644
index 819f99a..0000000
--- a/3rdparty/stout/include/stout/os/direntsize.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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_DIRENTSIZE_HPP__
-#define __STOUT_OS_DIRENTSIZE_HPP__
-
-
-// For readability, we minimize the number of #ifdef blocks in the code by
-// splitting platform specifc system calls into separate directories.
-#ifdef __WINDOWS__
-#include <stout/os/windows/direntsize.hpp>
-#else
-#include <stout/os/posix/direntsize.hpp>
-#endif // __WINDOWS__
-
-
-#endif // __STOUT_OS_DIRENTSIZE_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/ea1469fd/3rdparty/stout/include/stout/os/posix/direntsize.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/direntsize.hpp b/3rdparty/stout/include/stout/os/posix/direntsize.hpp
deleted file mode 100644
index 9d8f72e..0000000
--- a/3rdparty/stout/include/stout/os/posix/direntsize.hpp
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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_POSIX_DIRENTSIZE_HPP__
-#define __STOUT_OS_POSIX_DIRENTSIZE_HPP__
-
-#include <dirent.h>
-#include <unistd.h>
-
-
-namespace os {
-
-inline size_t dirent_size(DIR* dir)
-{
- // Calculate the size for a "directory entry".
- long name_max = fpathconf(dirfd(dir), _PC_NAME_MAX);
-
- // If we don't get a valid size, check NAME_MAX, but fall back on
- // 255 in the worst case ... Danger, Will Robinson!
- if (name_max == -1) {
- name_max = (NAME_MAX > 255) ? NAME_MAX : 255;
- }
-
- size_t name_end = (size_t) offsetof(dirent, d_name) + name_max + 1;
-
- size_t size = (name_end > sizeof(dirent) ? name_end : sizeof(dirent));
-
- return size;
-}
-
-} // namespace os {
-
-#endif // __STOUT_OS_POSIX_DIRENTSIZE_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/ea1469fd/3rdparty/stout/include/stout/os/windows/direntsize.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/direntsize.hpp b/3rdparty/stout/include/stout/os/windows/direntsize.hpp
deleted file mode 100644
index 7c8c7a0..0000000
--- a/3rdparty/stout/include/stout/os/windows/direntsize.hpp
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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_WINDOWS_DIRENTSIZE_HPP__
-#define __STOUT_OS_WINDOWS_DIRENTSIZE_HPP__
-
-#include <stout/internal/windows/dirent.hpp>
-
-#include <stout/windows.hpp>
-
-
-namespace os {
-
-inline size_t dirent_size(DIR* dir)
-{
- // NOTE: Size calculation logic here is much simpler than on POSIX because
- // our implementation of `dirent` is constant-sized. In particular, on POSIX,
- // we usually have to calculate the maximum name size for a path before we
- // can alloc a correctly-size `dirent`, but on Windows, `dirent.d_name` is
- // always `MAX_PATH` bytes in size.
- //
- // This follows closely from the Windows standard API data structures for
- // manipulating and querying directories. For example, the structures
- // `WIN32_FIND_DATA`[1] (which in many ways is the Windows equivalent of
- // `dirent`) has a field `cFileName` (which is much like `d_name`) that is
- // also `MAX_PATH` in size.
- //
- // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365740(v=vs.85).aspx
- return sizeof(dirent);
-}
-
-} // namespace os {
-
-#endif // __STOUT_OS_WINDOWS_DIRENTSIZE_HPP__