Commit cd464069 authored by Tudor Bosman's avatar Tudor Bosman Committed by facebook-github-bot-4

Add executable_path() and convert SubprocessTest to use it

Summary: Because I didn't want to write it again.

Reviewed By: @yfeldblum

Differential Revision: D2217246
parent 89282758
......@@ -16,6 +16,9 @@
#include <folly/experimental/io/FsUtil.h>
#include <unistd.h>
#include <folly/Exception.h>
namespace bsys = ::boost::system;
namespace folly {
......@@ -66,5 +69,9 @@ path canonical_parent(const path& pth, const path& base) {
return canonical(pth.parent_path(), base) / pth.filename();
}
path executable_path() {
return read_symlink("/proc/self/exe");
}
} // namespace fs
} // namespace folly
......@@ -52,6 +52,20 @@ path remove_prefix(const path& p, const path& prefix);
*/
path canonical_parent(const path& p, const path& basePath = current_path());
/**
* Get the path to the current executable.
*
* Note that this is not reliable and not recommended in general; it may not be
* implemented on your platform (in which case it will throw), the executable
* might have been moved or replaced while running, and applications comprising
* of multiple executables should use some form of configuration system to
* find the other executables rather than relying on relative paths from one
* to another.
*
* So this should only be used for tests, logging, or other innocuous purposes.
*/
path executable_path();
} // namespace fs
} // namespace folly
......
......@@ -31,6 +31,7 @@
#include <folly/gen/Base.h>
#include <folly/gen/File.h>
#include <folly/gen/String.h>
#include <folly/experimental/TestUtil.h>
#include <folly/experimental/io/FsUtil.h>
using namespace folly;
......@@ -189,15 +190,8 @@ TEST(SimpleSubprocessTest, FdLeakTest) {
TEST(ParentDeathSubprocessTest, ParentDeathSignal) {
// Find out where we are.
static constexpr size_t pathLength = 2048;
char buf[pathLength + 1];
int r = readlink("/proc/self/exe", buf, pathLength);
CHECK_ERR(r);
buf[r] = '\0';
fs::path helper(buf);
helper.remove_filename();
helper /= "subprocess_test_parent_death_helper";
auto helper = fs::executable_path();
helper.remove_filename() /= "subprocess_test_parent_death_helper";
fs::path tempFile(fs::temp_directory_path() / fs::unique_path());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment