[PATCH] D52562: [lib/fuzzer] Fix logging for Fuchsia
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 2 10:22:42 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343607: [lib/fuzzer] Fix logging for Fuchsia (authored by phosek, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D52562?vs=167160&id=167973#toc
Repository:
rL LLVM
https://reviews.llvm.org/D52562
Files:
compiler-rt/trunk/lib/fuzzer/FuzzerCommand.h
compiler-rt/trunk/lib/fuzzer/FuzzerUtilFuchsia.cpp
Index: compiler-rt/trunk/lib/fuzzer/FuzzerCommand.h
===================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerCommand.h
+++ compiler-rt/trunk/lib/fuzzer/FuzzerCommand.h
@@ -81,7 +81,7 @@
}
// Like hasArgument, but checks for "-[Flag]=...".
- bool hasFlag(const std::string &Flag) {
+ bool hasFlag(const std::string &Flag) const {
std::string Arg("-" + Flag + "=");
auto IsMatch = [&](const std::string &Other) {
return Arg.compare(0, std::string::npos, Other, 0, Arg.length()) == 0;
@@ -92,7 +92,7 @@
// Returns the value of the first instance of a given flag, or an empty string
// if the flag isn't present. Ignores any occurrences after
// "-ignore_remaining_args=1", if present.
- std::string getFlagValue(const std::string &Flag) {
+ std::string getFlagValue(const std::string &Flag) const {
std::string Arg("-" + Flag + "=");
auto IsMatch = [&](const std::string &Other) {
return Arg.compare(0, std::string::npos, Other, 0, Arg.length()) == 0;
Index: compiler-rt/trunk/lib/fuzzer/FuzzerUtilFuchsia.cpp
===================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerUtilFuchsia.cpp
+++ compiler-rt/trunk/lib/fuzzer/FuzzerUtilFuchsia.cpp
@@ -375,19 +375,28 @@
Argv[i] = Args[i].c_str();
Argv[Argc] = nullptr;
- // Determine stdout
+ // Determine output. On Fuchsia, the fuzzer is typically run as a component
+ // that lacks a mutable working directory. Fortunately, when this is the case
+ // a mutable output directory must be specified using "-artifact_prefix=...",
+ // so write the log file(s) there.
int FdOut = STDOUT_FILENO;
-
if (Cmd.hasOutputFile()) {
- auto Filename = Cmd.getOutputFile();
- FdOut = open(Filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0);
+ std::string Path;
+ if (Cmd.hasFlag("artifact_prefix"))
+ Path = Cmd.getFlagValue("artifact_prefix") + "/" + Cmd.getOutputFile();
+ else
+ Path = Cmd.getOutputFile();
+ FdOut = open(Path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0);
if (FdOut == -1) {
- Printf("libFuzzer: failed to open %s: %s\n", Filename.c_str(),
+ Printf("libFuzzer: failed to open %s: %s\n", Path.c_str(),
strerror(errno));
return ZX_ERR_IO;
}
}
- auto CloseFdOut = at_scope_exit([&]() { close(FdOut); } );
+ auto CloseFdOut = at_scope_exit([FdOut]() {
+ if (FdOut != STDOUT_FILENO)
+ close(FdOut);
+ });
// Determine stderr
int FdErr = STDERR_FILENO;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52562.167973.patch
Type: text/x-patch
Size: 2557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181002/f6d6be39/attachment.bin>
More information about the llvm-commits
mailing list