mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Make embed_file use raw logging
PiperOrigin-RevId: 242868093 Change-Id: Ibf1f448878219a9ce8fc6bb7d3e93626fa24b1f6
This commit is contained in:
parent
79525950fe
commit
6b5f3645ab
|
@ -36,6 +36,7 @@ cc_library(
|
||||||
"//sandboxed_api/sandbox2:util",
|
"//sandboxed_api/sandbox2:util",
|
||||||
"//sandboxed_api/sandbox2/util:fileops",
|
"//sandboxed_api/sandbox2/util:fileops",
|
||||||
"//sandboxed_api/sandbox2/util:strerror",
|
"//sandboxed_api/sandbox2/util:strerror",
|
||||||
|
"//sandboxed_api/util:raw_logging",
|
||||||
"//sandboxed_api/util:status",
|
"//sandboxed_api/util:status",
|
||||||
"@com_google_absl//absl/container:flat_hash_map",
|
"@com_google_absl//absl/container:flat_hash_map",
|
||||||
"@com_google_absl//absl/strings",
|
"@com_google_absl//absl/strings",
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "sandboxed_api/sandbox2/util.h"
|
#include "sandboxed_api/sandbox2/util.h"
|
||||||
#include "sandboxed_api/sandbox2/util/fileops.h"
|
#include "sandboxed_api/sandbox2/util/fileops.h"
|
||||||
#include "sandboxed_api/sandbox2/util/strerror.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/canonical_errors.h"
|
||||||
#include "sandboxed_api/util/status.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.
|
// Create a memfd/temp file and write contents of the SAPI library to it.
|
||||||
int embed_fd = -1;
|
int embed_fd = -1;
|
||||||
if (!sandbox2::util::CreateMemFd(&embed_fd, toc->name)) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_util::fileops::WriteToFD(embed_fd, toc->data, toc->size)) {
|
if (!file_util::fileops::WriteToFD(embed_fd, toc->data, toc->size)) {
|
||||||
PLOG(ERROR) << "Couldn't write SAPI embed file '" << toc->name
|
SAPI_RAW_PLOG(ERROR, "Couldn't write SAPI embed file '%s' to memfd file",
|
||||||
<< "' to memfd file";
|
toc->name);
|
||||||
close(embed_fd);
|
close(embed_fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +58,7 @@ int EmbedFile::CreateFdForFileToc(const FileToc* toc) {
|
||||||
// Make the underlying file non-writeable.
|
// Make the underlying file non-writeable.
|
||||||
if (fchmod(embed_fd,
|
if (fchmod(embed_fd,
|
||||||
S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1) {
|
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);
|
close(embed_fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -72,20 +73,21 @@ int EmbedFile::GetFdForFileToc(const FileToc* toc) {
|
||||||
// If a file-descriptor for this toc already exists, just return it.
|
// If a file-descriptor for this toc already exists, just return it.
|
||||||
auto entry = file_tocs_.find(toc);
|
auto entry = file_tocs_.find(toc);
|
||||||
if (entry != file_tocs_.end()) {
|
if (entry != file_tocs_.end()) {
|
||||||
VLOG(3) << "Returning pre-existing embed file entry for '" << toc->name
|
SAPI_RAW_VLOG(3,
|
||||||
<< "', fd: " << entry->second << " (orig name:'"
|
"Returning pre-existing embed file entry for '%s', fd: %d "
|
||||||
<< entry->first->name << "')";
|
"(orig name: '%s')",
|
||||||
|
toc->name, entry->second, entry->first->name);
|
||||||
return entry->second;
|
return entry->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
int embed_fd = CreateFdForFileToc(toc);
|
int embed_fd = CreateFdForFileToc(toc);
|
||||||
if (embed_fd == -1) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VLOG(1) << "Created new embed file entry for '" << toc->name
|
SAPI_RAW_VLOG(1, "Created new embed file entry for '%s' with fd: %d",
|
||||||
<< "' with fd: " << embed_fd;
|
toc->name, embed_fd);
|
||||||
|
|
||||||
file_tocs_[toc] = embed_fd;
|
file_tocs_[toc] = embed_fd;
|
||||||
return embed_fd;
|
return embed_fd;
|
||||||
|
@ -98,7 +100,7 @@ int EmbedFile::GetDupFdForFileToc(const FileToc* toc) {
|
||||||
}
|
}
|
||||||
fd = dup(fd);
|
fd = dup(fd);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
PLOG(ERROR) << "dup(" << fd << ") failed";
|
SAPI_RAW_PLOG(ERROR, "dup failed");
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user