Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace readdir_r #1641

Merged
merged 28 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a58c972
Add unit test for function FindMatchingFiles in common/file/Util.cpp
kripton May 16, 2020
05c7cce
Respect 80 char per line limit
kripton May 17, 2020
ecd3742
Replace readdir_r with readdir. Fixes #1055
kripton May 17, 2020
4ab07ba
Revert https://github.com/OpenLightingProject/ola/pull/1168
kripton May 17, 2020
da75e79
Use TEST_SRC_DIR to make the test also work in shadow builds
kripton May 22, 2020
0455ef7
Linting fix: Include <vector> since we are using it
kripton May 22, 2020
8759a59
FindMatchingFiles test: Explicitely check for returned file names
kripton Jun 12, 2020
c2e19c0
Make the path we're testing the FindMatchingFiles-function in Windows…
kripton Jun 13, 2020
e6e6d6a
Code linting fixes. No change in behaviour
kripton Jun 13, 2020
92669ae
remove the slash from /man since we are using the proper PATH_SEPARAT…
kripton Jun 13, 2020
a40ddbe
Use a later Python to fix codespell
peternewman Jun 14, 2020
9a837e8
Install codespell via pip3 instead
peternewman Jun 14, 2020
00f5e5d
Third time lucky with codespell?
peternewman Jun 14, 2020
b0be464
Hopefully really fix the codespell run
peternewman Jun 14, 2020
9b0543f
Set the path earlier so all the python stuff uses the same version
peternewman Jun 14, 2020
0439d63
Use the correct path
peternewman Jun 14, 2020
a1d3f73
Use PATH_SEPARATOR from ola::file instead of copying the code to the …
kripton Jun 26, 2020
7943200
Add an assert to testFindMatchingFiles to make sure that ola::file::P…
kripton Jun 26, 2020
93cb39e
Use ola::StringEndsWith instead of a custom inline function
kripton Jun 26, 2020
66ea089
Add asserts to make sure the files have not been reported as found be…
kripton Jun 26, 2020
aff5656
Fix linting errors (two spaces between code and comment)
kripton Jun 26, 2020
196c9bc
Add comments about explicitely setting errno to 0 and use "else if" f…
kripton Jul 7, 2020
56e76a8
Add "and various fixes" to Jannis Achstetter's contributions in AUTHO…
kripton Jul 7, 2020
7a80865
Document changes regarding readdir_r-replacement
kripton Jul 7, 2020
6c64346
Fix codespell issues
kripton Jul 7, 2020
da81b0e
Review fixes: Don't rely on C++11 and true/false instead of 1/0
kripton Jul 8, 2020
4702dc4
Comment and whitespace fixes
kripton Jul 8, 2020
fce9c4f
Merge branch '0.10' into ReplaceReaddir_r
peternewman Jul 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ matrix:
- moreutils
- os: linux
dist: xenial
env: TASK='codespell'
env:
- TASK='codespell'
- PATH=/opt/python/3.7.1/bin:$PATH
addons:
apt:
packages:
Expand Down Expand Up @@ -312,7 +314,7 @@ install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then pip install --user numpy; fi
- if [ "$TASK" = "coverage" ]; then pip install --user cpp-coveralls; fi
- if [ "$TASK" = "flake8" ]; then pip install --user flake8; fi
- if [ "$TASK" = "codespell" ]; then pip install --user git+https://github.com/codespell-project/codespell.git; fi
- if [ "$TASK" = "codespell" ]; then pip3 install --user git+https://github.com/codespell-project/codespell.git; fi
- if [ "$TASK" = "jshint" ]; then npm install -g grunt-cli; fi

before_install:
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Contributors:
Hakan Lindestaf, Renard plugin
Harry F, for the Eurolite USB Pro code
Heikki Junnila, bug fixes for the debian packaging files
Jannis Achstetter, compile fixes for newer dependencies
Jannis Achstetter, compile fixes for newer dependencies and various fixes
Laurent (Renzo), Debian packages, FreeBSD & RDM testing.
Lukas Erlinghagen, win32 port.
Johan Nilsson, Philips Hue trigger config
Expand Down
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ x/y/2019 ola-0.10.8
the Python RDM Test code, also the relevant comments

Internal:
*
* Replace "readdir_r" with "readdir" since the former has been deprecated
* Add a unit test for the functions that used readdir_r before

13/7/2018 ola-0.10.7
Features:
Expand Down
18 changes: 13 additions & 5 deletions common/file/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,19 @@ bool FindMatchingFiles(const string &directory,
FindClose(h_find);
#else
DIR *dp;
struct dirent dir_ent;
struct dirent *dir_ent_p;
if ((dp = opendir(directory.data())) == NULL) {
OLA_WARN << "Could not open " << directory << ": " << strerror(errno);
return false;
}

if (readdir_r(dp, &dir_ent, &dir_ent_p)) {
OLA_WARN << "readdir_r(" << directory << "): " << strerror(errno);
// Explicitly set errno to 0 so we can reliably check the value after
// the call to readdir. It might have a undefined value otherwise since
// a successful call may but doesn't need to set a value.
errno = 0;
peternewman marked this conversation as resolved.
Show resolved Hide resolved
dir_ent_p = readdir(dp);
if ((dir_ent_p == NULL) && (errno != 0)) {
OLA_WARN << "readdir(" << directory << "): " << strerror(errno);
closedir(dp);
return false;
}
Expand All @@ -151,8 +155,12 @@ bool FindMatchingFiles(const string &directory,
files->push_back(str.str());
}
}
if (readdir_r(dp, &dir_ent, &dir_ent_p)) {
OLA_WARN << "readdir_r(" << directory << "): " << strerror(errno);
// Explicitly set errno to 0 so we can reliably check the value after
// the call. It might have an undefined value otherwise.
errno = 0;
peternewman marked this conversation as resolved.
Show resolved Hide resolved
dir_ent_p = readdir(dp);
if ((dir_ent_p == NULL) && (errno != 0)) {
OLA_WARN << "readdir(" << directory << "): " << strerror(errno);
closedir(dp);
return false;
}
Expand Down
61 changes: 60 additions & 1 deletion common/file/UtilTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,31 @@

#include <cppunit/extensions/HelperMacros.h>
#include <string>
#include <iterator>
#include <vector>

#include "ola/StringUtils.h"
#include "ola/file/Util.h"
#include "ola/testing/TestUtils.h"


using ola::file::FilenameFromPath;
using ola::file::FilenameFromPathOrDefault;
using ola::file::FilenameFromPathOrPath;
using ola::file::JoinPaths;
using ola::file::FindMatchingFiles;
using std::string;

class UtilTest: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(UtilTest);
CPPUNIT_TEST(testJoinPaths);
CPPUNIT_TEST(testFilenameFromPath);
CPPUNIT_TEST(testFindMatchingFiles);
CPPUNIT_TEST_SUITE_END();

public:
void testFilenameFromPath();
void testJoinPaths();
void testFindMatchingFiles();
};


Expand Down Expand Up @@ -90,3 +95,57 @@ void UtilTest::testFilenameFromPath() {
OLA_ASSERT_EQ(string("baz"), FilenameFromPathOrPath("/foo/bar/baz"));
}

/*
* Test the FindMatchingFiles function
*/
void UtilTest::testFindMatchingFiles() {
bool okay = false;

std::vector<std::string> files;
std::vector<std::string>::iterator file;

OLA_ASSERT_TRUE_MSG(ola::file::PATH_SEPARATOR == '/' ||
ola::file::PATH_SEPARATOR == '\\',
"ola::file::PATH_SEPARATOR is neither / nor \\");

okay = FindMatchingFiles(std::string(TEST_SRC_DIR) +
ola::file::PATH_SEPARATOR + std::string("man"),
std::string("rdm_"), &files);

OLA_ASSERT_TRUE_MSG(okay, "FindMatchingFiles returned false");

// At the time this test was written, there were 3 files in folder "man"
// starting with "rdm_". If this changed, please adapt the number below
// Or find something better to match against
peternewman marked this conversation as resolved.
Show resolved Hide resolved
OLA_ASSERT_EQ_MSG(3, (int)files.size(),
"Not exactly 3 files man/rdm_* returned");

bool rdm_model_collector_found = false;
bool rdm_responder_test_found = false;
bool rdm_test_server_found = false;

// Iterate over all files that have been returned and check if the ones
// we expected are in that list
for (file = files.begin(); file < files.end(); file++) {
if (ola::StringEndsWith(*file, "rdm_model_collector.py.1")) {
// make sure it has not been reported as found before
OLA_ASSERT_FALSE(rdm_model_collector_found);
rdm_model_collector_found = true;
} else if (ola::StringEndsWith(*file, "rdm_responder_test.py.1")) {
// make sure it has not been reported as found before
OLA_ASSERT_FALSE(rdm_responder_test_found);
rdm_responder_test_found = true;
} else if (ola::StringEndsWith(*file, "rdm_test_server.py.1")) {
// make sure it has not been reported as found before
OLA_ASSERT_FALSE(rdm_test_server_found);
rdm_test_server_found = true;
}
}

OLA_ASSERT_TRUE_MSG(rdm_model_collector_found,
"Result lacks rdm_model_collector.py.1");
OLA_ASSERT_TRUE_MSG(rdm_responder_test_found,
"Result lacks rdm_responder_test.py.1");
OLA_ASSERT_TRUE_MSG(rdm_test_server_found,
"Result lacks rdm_test_server.py.1");
}
23 changes: 0 additions & 23 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,6 @@ AC_CHECK_FUNCS([bzero gettimeofday memmove memset mkdir strdup strrchr \
socket strerror getifaddrs getloadavg getpwnam_r getpwuid_r \
getgrnam_r getgrgid_r secure_getenv])

AC_MSG_CHECKING(for readdir_r deprecation)
old_cxxflags=$CXXFLAGS
CXXFLAGS="${CXXFLAGS} -Werror=deprecated-declarations"
AC_CACHE_VAL(ac_cv_readdir_r_deprecation,
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <dirent.h>
#include <unistd.h>]],[[
const char* arg = "/";
DIR * dir;
struct dirent *buf, *de;
dir = opendir(arg);
readdir_r(dir,buf,&de);
]])],
[ac_cv_readdir_r_deprecation=no],
[ac_cv_readdir_r_deprecation=yes])
)
CXXFLAGS=$old_cxxflags
AC_MSG_RESULT($ac_cv_readdir_r_deprecation)

AS_IF([test "x$ac_cv_readdir_r_deprecation" = xyes],
[CXXFLAGS="$CXXFLAGS -Wno-error=deprecated-declarations"],
[])

peternewman marked this conversation as resolved.
Show resolved Hide resolved
LT_INIT([win32-dll])

# Decide if we're building on Windows early on.
Expand Down
2 changes: 1 addition & 1 deletion include/ola/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#define OLA_WARN OLA_LOG(ola::OLA_LOG_WARN)

/**
* Provide a stream to log an infomational message.
* Provide a stream to log an informational message.
* @code
* OLA_INFO << "Reading configs from " << config_dir;
* @endcode
Expand Down