Merge "Use a class for system properties filenames." into main am: 6f6df7376e
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2734834 Change-Id: I7dbafaa711937b741a00e14c7e576139c57efffa Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
bcfaa004a4
5 changed files with 39 additions and 52 deletions
|
@ -49,17 +49,11 @@ bool ContextNode::Open(bool access_rw, bool* fsetxattr_failed) {
|
|||
return true;
|
||||
}
|
||||
|
||||
char filename[PROP_FILENAME_MAX];
|
||||
int len = async_safe_format_buffer(filename, sizeof(filename), "%s/%s", filename_, context_);
|
||||
if (len < 0 || len >= PROP_FILENAME_MAX) {
|
||||
lock_.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
PropertiesFilename filename(filename_, context_);
|
||||
if (access_rw) {
|
||||
pa_ = prop_area::map_prop_area_rw(filename, context_, fsetxattr_failed);
|
||||
pa_ = prop_area::map_prop_area_rw(filename.c_str(), context_, fsetxattr_failed);
|
||||
} else {
|
||||
pa_ = prop_area::map_prop_area(filename);
|
||||
pa_ = prop_area::map_prop_area(filename.c_str());
|
||||
}
|
||||
lock_.unlock();
|
||||
return pa_;
|
||||
|
@ -84,13 +78,8 @@ void ContextNode::ResetAccess() {
|
|||
}
|
||||
|
||||
bool ContextNode::CheckAccess() {
|
||||
char filename[PROP_FILENAME_MAX];
|
||||
int len = async_safe_format_buffer(filename, sizeof(filename), "%s/%s", filename_, context_);
|
||||
if (len < 0 || len >= PROP_FILENAME_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return access(filename, R_OK) == 0;
|
||||
PropertiesFilename filename(filename_, context_);
|
||||
return access(filename.c_str(), R_OK) == 0;
|
||||
}
|
||||
|
||||
void ContextNode::Unmap() {
|
||||
|
|
|
@ -66,18 +66,12 @@ bool ContextsSerialized::InitializeContextNodes() {
|
|||
}
|
||||
|
||||
bool ContextsSerialized::MapSerialPropertyArea(bool access_rw, bool* fsetxattr_failed) {
|
||||
char filename[PROP_FILENAME_MAX];
|
||||
int len = async_safe_format_buffer(filename, sizeof(filename), "%s/properties_serial", filename_);
|
||||
if (len < 0 || len >= PROP_FILENAME_MAX) {
|
||||
serial_prop_area_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
PropertiesFilename filename(filename_, "properties_serial");
|
||||
if (access_rw) {
|
||||
serial_prop_area_ =
|
||||
prop_area::map_prop_area_rw(filename, "u:object_r:properties_serial:s0", fsetxattr_failed);
|
||||
serial_prop_area_ = prop_area::map_prop_area_rw(
|
||||
filename.c_str(), "u:object_r:properties_serial:s0", fsetxattr_failed);
|
||||
} else {
|
||||
serial_prop_area_ = prop_area::map_prop_area(filename);
|
||||
serial_prop_area_ = prop_area::map_prop_area(filename.c_str());
|
||||
}
|
||||
return serial_prop_area_;
|
||||
}
|
||||
|
|
|
@ -192,18 +192,12 @@ static int read_spec_entries(char* line_buf, int num_args, ...) {
|
|||
}
|
||||
|
||||
bool ContextsSplit::MapSerialPropertyArea(bool access_rw, bool* fsetxattr_failed) {
|
||||
char filename[PROP_FILENAME_MAX];
|
||||
int len = async_safe_format_buffer(filename, sizeof(filename), "%s/properties_serial", filename_);
|
||||
if (len < 0 || len >= PROP_FILENAME_MAX) {
|
||||
serial_prop_area_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
PropertiesFilename filename(filename_, "properties_serial");
|
||||
if (access_rw) {
|
||||
serial_prop_area_ =
|
||||
prop_area::map_prop_area_rw(filename, "u:object_r:properties_serial:s0", fsetxattr_failed);
|
||||
serial_prop_area_ = prop_area::map_prop_area_rw(
|
||||
filename.c_str(), "u:object_r:properties_serial:s0", fsetxattr_failed);
|
||||
} else {
|
||||
serial_prop_area_ = prop_area::map_prop_area(filename);
|
||||
serial_prop_area_ = prop_area::map_prop_area(filename.c_str());
|
||||
}
|
||||
return serial_prop_area_;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,24 @@
|
|||
#include "contexts_serialized.h"
|
||||
#include "contexts_split.h"
|
||||
|
||||
constexpr int PROP_FILENAME_MAX = 1024;
|
||||
class PropertiesFilename {
|
||||
public:
|
||||
PropertiesFilename() = default;
|
||||
PropertiesFilename(const char* dir, const char* file) {
|
||||
if (snprintf(filename_, sizeof(filename_), "%s/%s", dir, file) >=
|
||||
static_cast<int>(sizeof(filename_))) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
void operator=(const char* value) {
|
||||
if (strlen(value) >= sizeof(filename_)) abort();
|
||||
strcpy(filename_, value);
|
||||
}
|
||||
const char* c_str() { return filename_; }
|
||||
|
||||
private:
|
||||
char filename_[1024];
|
||||
};
|
||||
|
||||
class SystemProperties {
|
||||
public:
|
||||
|
@ -86,5 +103,5 @@ class SystemProperties {
|
|||
Contexts* contexts_;
|
||||
|
||||
bool initialized_;
|
||||
char property_filename_[PROP_FILENAME_MAX];
|
||||
PropertiesFilename properties_filename_;
|
||||
};
|
||||
|
|
|
@ -67,26 +67,23 @@ bool SystemProperties::Init(const char* filename) {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (strlen(filename) >= PROP_FILENAME_MAX) {
|
||||
return false;
|
||||
}
|
||||
strcpy(property_filename_, filename);
|
||||
properties_filename_ = filename;
|
||||
|
||||
if (is_dir(property_filename_)) {
|
||||
if (is_dir(properties_filename_.c_str())) {
|
||||
if (access("/dev/__properties__/property_info", R_OK) == 0) {
|
||||
contexts_ = new (contexts_data_) ContextsSerialized();
|
||||
if (!contexts_->Initialize(false, property_filename_, nullptr)) {
|
||||
if (!contexts_->Initialize(false, properties_filename_.c_str(), nullptr)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
contexts_ = new (contexts_data_) ContextsSplit();
|
||||
if (!contexts_->Initialize(false, property_filename_, nullptr)) {
|
||||
if (!contexts_->Initialize(false, properties_filename_.c_str(), nullptr)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
contexts_ = new (contexts_data_) ContextsPreSplit();
|
||||
if (!contexts_->Initialize(false, property_filename_, nullptr)) {
|
||||
if (!contexts_->Initialize(false, properties_filename_.c_str(), nullptr)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -95,13 +92,9 @@ bool SystemProperties::Init(const char* filename) {
|
|||
}
|
||||
|
||||
bool SystemProperties::AreaInit(const char* filename, bool* fsetxattr_failed) {
|
||||
if (strlen(filename) >= PROP_FILENAME_MAX) {
|
||||
return false;
|
||||
}
|
||||
strcpy(property_filename_, filename);
|
||||
|
||||
properties_filename_ = filename;
|
||||
contexts_ = new (contexts_data_) ContextsSerialized();
|
||||
if (!contexts_->Initialize(true, property_filename_, fsetxattr_failed)) {
|
||||
if (!contexts_->Initialize(true, properties_filename_.c_str(), fsetxattr_failed)) {
|
||||
return false;
|
||||
}
|
||||
initialized_ = true;
|
||||
|
|
Loading…
Reference in a new issue