Make embed_file use raw logging

PiperOrigin-RevId: 242868093
Change-Id: Ibf1f448878219a9ce8fc6bb7d3e93626fa24b1f6
This commit is contained in:
Kevin Hamacher 2019-04-10 07:55:46 -07:00 committed by Copybara-Service
parent 79525950fe
commit 6b5f3645ab
2 changed files with 15 additions and 12 deletions

View File

@ -36,6 +36,7 @@ cc_library(
"//sandboxed_api/sandbox2:util",
"//sandboxed_api/sandbox2/util:fileops",
"//sandboxed_api/sandbox2/util:strerror",
"//sandboxed_api/util:raw_logging",
"//sandboxed_api/util:status",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings",

View File

@ -26,6 +26,7 @@
#include "sandboxed_api/sandbox2/util.h"
#include "sandboxed_api/sandbox2/util/fileops.h"
#include "sandboxed_api/sandbox2/util/strerror.h"
#include "sandboxed_api/util/raw_logging.h"
#include "sandboxed_api/util/canonical_errors.h"
#include "sandboxed_api/util/status.h"
@ -42,14 +43,14 @@ int EmbedFile::CreateFdForFileToc(const FileToc* toc) {
// Create a memfd/temp file and write contents of the SAPI library to it.
int embed_fd = -1;
if (!sandbox2::util::CreateMemFd(&embed_fd, toc->name)) {
LOG(ERROR) << "Couldn't create a temporary file for TOC name '" << toc->name
<< "'";
SAPI_RAW_LOG(ERROR, "Couldn't create a temporary file for TOC name '%s'",
toc->name);
return -1;
}
if (!file_util::fileops::WriteToFD(embed_fd, toc->data, toc->size)) {
PLOG(ERROR) << "Couldn't write SAPI embed file '" << toc->name
<< "' to memfd file";
SAPI_RAW_PLOG(ERROR, "Couldn't write SAPI embed file '%s' to memfd file",
toc->name);
close(embed_fd);
return -1;
}
@ -57,7 +58,7 @@ int EmbedFile::CreateFdForFileToc(const FileToc* toc) {
// Make the underlying file non-writeable.
if (fchmod(embed_fd,
S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1) {
PLOG(ERROR) << "Could't make FD=" << embed_fd << " RX-only";
SAPI_RAW_PLOG(ERROR, "Could't make FD=%d RX-only", embed_fd);
close(embed_fd);
return -1;
}
@ -72,20 +73,21 @@ int EmbedFile::GetFdForFileToc(const FileToc* toc) {
// If a file-descriptor for this toc already exists, just return it.
auto entry = file_tocs_.find(toc);
if (entry != file_tocs_.end()) {
VLOG(3) << "Returning pre-existing embed file entry for '" << toc->name
<< "', fd: " << entry->second << " (orig name:'"
<< entry->first->name << "')";
SAPI_RAW_VLOG(3,
"Returning pre-existing embed file entry for '%s', fd: %d "
"(orig name: '%s')",
toc->name, entry->second, entry->first->name);
return entry->second;
}
int embed_fd = CreateFdForFileToc(toc);
if (embed_fd == -1) {
LOG(ERROR) << "Cannot create a file for FileTOC: '" << toc->name << "'";
SAPI_RAW_LOG(ERROR, "Cannot create a file for FileTOC: '%s'", toc->name);
return -1;
}
VLOG(1) << "Created new embed file entry for '" << toc->name
<< "' with fd: " << embed_fd;
SAPI_RAW_VLOG(1, "Created new embed file entry for '%s' with fd: %d",
toc->name, embed_fd);
file_tocs_[toc] = embed_fd;
return embed_fd;
@ -98,7 +100,7 @@ int EmbedFile::GetDupFdForFileToc(const FileToc* toc) {
}
fd = dup(fd);
if (fd == -1) {
PLOG(ERROR) << "dup(" << fd << ") failed";
SAPI_RAW_PLOG(ERROR, "dup failed");
}
return fd;
}