#include <folly/experimental/io/FsUtil.h>
+#include <unistd.h>
+#include <folly/Exception.h>
+
namespace bsys = ::boost::system;
namespace folly {
return canonical(pth.parent_path(), base) / pth.filename();
}
+path executable_path() {
+ return read_symlink("/proc/self/exe");
+}
+
} // namespace fs
} // namespace folly
*/
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
#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;
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());