Make systemproperties more match AOSP

This commit is contained in:
topjohnwu 2021-03-29 03:46:07 -07:00
parent 7e4194418a
commit 2bef967af1
5 changed files with 15 additions and 12 deletions

View File

@ -12,7 +12,6 @@
#endif #endif
// Missing functions // Missing functions
#define fsetxattr(...) syscall(__NR_fsetxattr, __VA_ARGS__)
#define getline compat_getline #define getline compat_getline
ssize_t compat_getline(char **, size_t *, FILE *); ssize_t compat_getline(char **, size_t *, FILE *);

View File

@ -110,8 +110,7 @@ class prop_area {
const prop_info* find(const char* name); const prop_info* find(const char* name);
bool add(const char* name, unsigned int namelen, const char* value, unsigned int valuelen); bool add(const char* name, unsigned int namelen, const char* value, unsigned int valuelen);
/* resetprop */ bool rm(const char *name);
bool del(const char *name);
bool foreach (void (*propfn)(const prop_info* pi, void* cookie), void* cookie); bool foreach (void (*propfn)(const prop_info* pi, void* cookie), void* cookie);
@ -126,7 +125,7 @@ class prop_area {
} }
private: private:
static prop_area* map_fd_rw(const int fd); static prop_area* map_fd_ro(const int fd);
void* allocate_obj(const size_t size, uint_least32_t* const off); void* allocate_obj(const size_t size, uint_least32_t* const off);
prop_bt* new_prop_bt(const char* name, uint32_t namelen, uint_least32_t* const off); prop_bt* new_prop_bt(const char* name, uint32_t namelen, uint_least32_t* const off);
@ -138,7 +137,7 @@ class prop_area {
prop_bt* root_node(); prop_bt* root_node();
/* resetprop: Traverse through the trie and find the node */ /* resetprop new: traverse through the trie and find the node */
prop_bt *find_prop_bt(prop_bt *const bt, const char* name, bool alloc_if_needed); prop_bt *find_prop_bt(prop_bt *const bt, const char* name, bool alloc_if_needed);
prop_bt* find_prop_bt(prop_bt* const bt, const char* name, uint32_t namelen, bool alloc_if_needed); prop_bt* find_prop_bt(prop_bt* const bt, const char* name, uint32_t namelen, bool alloc_if_needed);

View File

@ -26,6 +26,8 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include "system_properties/prop_area.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
@ -39,8 +41,6 @@
#include <async_safe/log.h> #include <async_safe/log.h>
#include "system_properties/prop_area.h"
constexpr size_t PA_SIZE = 128 * 1024; constexpr size_t PA_SIZE = 128 * 1024;
constexpr uint32_t PROP_AREA_MAGIC = 0x504f5250; constexpr uint32_t PROP_AREA_MAGIC = 0x504f5250;
constexpr uint32_t PROP_AREA_VERSION = 0xfc6ed0ab; constexpr uint32_t PROP_AREA_VERSION = 0xfc6ed0ab;
@ -104,8 +104,7 @@ prop_area* prop_area::map_prop_area_rw(const char* filename, const char* context
return pa; return pa;
} }
/* resetprop: map_fd_ro -> map_fd_rw */ prop_area* prop_area::map_fd_ro(const int fd) {
prop_area* prop_area::map_fd_rw(const int fd) {
struct stat fd_stat; struct stat fd_stat;
if (fstat(fd, &fd_stat) < 0) { if (fstat(fd, &fd_stat) < 0) {
return nullptr; return nullptr;
@ -140,7 +139,7 @@ prop_area* prop_area::map_prop_area(const char* filename) {
int fd = open(filename, O_CLOEXEC | O_NOFOLLOW | O_RDWR); int fd = open(filename, O_CLOEXEC | O_NOFOLLOW | O_RDWR);
if (fd == -1) return nullptr; if (fd == -1) return nullptr;
prop_area* map_result = map_fd_rw(fd); prop_area* map_result = map_fd_ro(fd);
close(fd); close(fd);
return map_result; return map_result;
@ -275,6 +274,8 @@ prop_bt* prop_area::find_prop_bt(prop_bt* const bt, const char* name, uint32_t n
} }
} }
/* resetprop new: traverse through the trie and find the node.
* This was originally part of prop_area::find_property. */
prop_bt *prop_area::find_prop_bt(prop_bt *const trie, const char *name, bool alloc_if_needed) { prop_bt *prop_area::find_prop_bt(prop_bt *const trie, const char *name, bool alloc_if_needed) {
if (!trie) return nullptr; if (!trie) return nullptr;
@ -317,6 +318,7 @@ prop_bt *prop_area::find_prop_bt(prop_bt *const trie, const char *name, bool all
return current; return current;
} }
/* resetprop: move trie traversal logic out of the function */
const prop_info* prop_area::find_property(prop_bt* const trie, const char* name, uint32_t namelen, const prop_info* prop_area::find_property(prop_bt* const trie, const char* name, uint32_t namelen,
const char* value, uint32_t valuelen, const char* value, uint32_t valuelen,
bool alloc_if_needed) { bool alloc_if_needed) {
@ -378,7 +380,7 @@ bool prop_area::add(const char* name, unsigned int namelen, const char* value,
return find_property(root_node(), name, namelen, value, valuelen, true); return find_property(root_node(), name, namelen, value, valuelen, true);
} }
bool prop_area::del(const char *name) { bool prop_area::rm(const char *name) {
prop_bt* node = find_prop_bt(root_node(), name, false); prop_bt* node = find_prop_bt(root_node(), name, false);
if (!node) if (!node)
return false; return false;

View File

@ -311,7 +311,7 @@ int SystemProperties::Delete(const char *name) {
return -1; return -1;
} }
bool ret = pa->del(name); bool ret = pa->rm(name);
if (!ret) { if (!ret) {
return -1; return -1;
} }

View File

@ -21,6 +21,9 @@ static bool verbose = false;
#define system_property_read_callback __system_property_read_callback #define system_property_read_callback __system_property_read_callback
#define system_property_foreach __system_property_foreach #define system_property_foreach __system_property_foreach
#define system_property_read(...) #define system_property_read(...)
extern "C" int fsetxattr(int fd, const char* name, const void* value, size_t size, int flags) {
return syscall(__NR_fsetxattr, fd, name, value, size, flags);
}
#else #else
static int (*system_property_set)(const char*, const char*); static int (*system_property_set)(const char*, const char*);
static int (*system_property_read)(const prop_info*, char*, char*); static int (*system_property_read)(const prop_info*, char*, char*);