Merge "Do not chmod ANRs" into main am: effe539c30

Original change: https://android-review.googlesource.com/c/platform/system/core/+/3006788

Change-Id: I3ef7f0ad6cb79f148d1ffc5c690f0dc704c21732
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Florian Mayer 2024-03-19 18:36:56 +00:00 committed by Automerger Merge Worker
commit b55b5e7433

View file

@ -96,7 +96,7 @@ struct Crash {
class CrashQueue {
public:
CrashQueue(const std::string& dir_path, const std::string& file_name_prefix, size_t max_artifacts,
size_t max_concurrent_dumps, bool supports_proto)
size_t max_concurrent_dumps, bool supports_proto, bool world_readable)
: file_name_prefix_(file_name_prefix),
dir_path_(dir_path),
dir_fd_(open(dir_path.c_str(), O_DIRECTORY | O_RDONLY | O_CLOEXEC)),
@ -104,7 +104,8 @@ class CrashQueue {
next_artifact_(0),
max_concurrent_dumps_(max_concurrent_dumps),
num_concurrent_dumps_(0),
supports_proto_(supports_proto) {
supports_proto_(supports_proto),
world_readable_(world_readable) {
if (dir_fd_ == -1) {
PLOG(FATAL) << "failed to open directory: " << dir_path;
}
@ -127,14 +128,16 @@ class CrashQueue {
static CrashQueue* for_tombstones() {
static CrashQueue queue("/data/tombstones", "tombstone_" /* file_name_prefix */,
GetIntProperty("tombstoned.max_tombstone_count", 32),
1 /* max_concurrent_dumps */, true /* supports_proto */);
1 /* max_concurrent_dumps */, true /* supports_proto */,
true /* world_readable */);
return &queue;
}
static CrashQueue* for_anrs() {
static CrashQueue queue("/data/anr", "trace_" /* file_name_prefix */,
GetIntProperty("tombstoned.max_anr_count", 64),
4 /* max_concurrent_dumps */, false /* supports_proto */);
4 /* max_concurrent_dumps */, false /* supports_proto */,
false /* world_readable */);
return &queue;
}
@ -147,10 +150,12 @@ class CrashQueue {
PLOG(FATAL) << "failed to create temporary tombstone in " << dir_path_;
}
// We need to fchmodat after creating to avoid getting the umask applied.
std::string fd_path = StringPrintf("/proc/self/fd/%d", result.fd.get());
if (fchmodat(dir_fd_, fd_path.c_str(), 0664, 0) != 0) {
PLOG(ERROR) << "Failed to make tombstone world-readable";
if (world_readable_) {
// We need to fchmodat after creating to avoid getting the umask applied.
std::string fd_path = StringPrintf("/proc/self/fd/%d", result.fd.get());
if (fchmodat(dir_fd_, fd_path.c_str(), 0664, 0) != 0) {
PLOG(ERROR) << "Failed to make tombstone world-readable";
}
}
return std::move(result);
@ -262,6 +267,7 @@ class CrashQueue {
size_t num_concurrent_dumps_;
bool supports_proto_;
bool world_readable_;
std::deque<std::unique_ptr<Crash>> queued_requests_;