From 2bef967af1b6e809fae55329137dfae8cf36ef17 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 29 Mar 2021 03:46:07 -0700 Subject: [PATCH] Make systemproperties more match AOSP --- .../systemproperties/include/private/hacks.h | 1 - .../include/system_properties/prop_area.h | 7 +++---- native/jni/external/systemproperties/prop_area.cpp | 14 ++++++++------ .../systemproperties/system_properties.cpp | 2 +- native/jni/resetprop/resetprop.cpp | 3 +++ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/native/jni/external/systemproperties/include/private/hacks.h b/native/jni/external/systemproperties/include/private/hacks.h index b30c16afd..5ac34e195 100644 --- a/native/jni/external/systemproperties/include/private/hacks.h +++ b/native/jni/external/systemproperties/include/private/hacks.h @@ -12,7 +12,6 @@ #endif // Missing functions -#define fsetxattr(...) syscall(__NR_fsetxattr, __VA_ARGS__) #define getline compat_getline ssize_t compat_getline(char **, size_t *, FILE *); diff --git a/native/jni/external/systemproperties/include/system_properties/prop_area.h b/native/jni/external/systemproperties/include/system_properties/prop_area.h index 9dcd0081b..b1b50b5b4 100644 --- a/native/jni/external/systemproperties/include/system_properties/prop_area.h +++ b/native/jni/external/systemproperties/include/system_properties/prop_area.h @@ -110,8 +110,7 @@ class prop_area { const prop_info* find(const char* name); bool add(const char* name, unsigned int namelen, const char* value, unsigned int valuelen); - /* resetprop */ - bool del(const char *name); + bool rm(const char *name); bool foreach (void (*propfn)(const prop_info* pi, void* cookie), void* cookie); @@ -126,7 +125,7 @@ class prop_area { } 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); 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(); - /* 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, uint32_t namelen, bool alloc_if_needed); diff --git a/native/jni/external/systemproperties/prop_area.cpp b/native/jni/external/systemproperties/prop_area.cpp index 92098b1bf..f3919a108 100644 --- a/native/jni/external/systemproperties/prop_area.cpp +++ b/native/jni/external/systemproperties/prop_area.cpp @@ -26,6 +26,8 @@ * SUCH DAMAGE. */ +#include "system_properties/prop_area.h" + #include #include #include @@ -39,8 +41,6 @@ #include -#include "system_properties/prop_area.h" - constexpr size_t PA_SIZE = 128 * 1024; constexpr uint32_t PROP_AREA_MAGIC = 0x504f5250; 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; } -/* resetprop: map_fd_ro -> map_fd_rw */ -prop_area* prop_area::map_fd_rw(const int fd) { +prop_area* prop_area::map_fd_ro(const int fd) { struct stat fd_stat; if (fstat(fd, &fd_stat) < 0) { 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); if (fd == -1) return nullptr; - prop_area* map_result = map_fd_rw(fd); + prop_area* map_result = map_fd_ro(fd); close(fd); 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) { 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; } +/* 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 char* value, uint32_t valuelen, 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); } -bool prop_area::del(const char *name) { +bool prop_area::rm(const char *name) { prop_bt* node = find_prop_bt(root_node(), name, false); if (!node) return false; diff --git a/native/jni/external/systemproperties/system_properties.cpp b/native/jni/external/systemproperties/system_properties.cpp index f03bfb9d4..df39831bb 100644 --- a/native/jni/external/systemproperties/system_properties.cpp +++ b/native/jni/external/systemproperties/system_properties.cpp @@ -311,7 +311,7 @@ int SystemProperties::Delete(const char *name) { return -1; } - bool ret = pa->del(name); + bool ret = pa->rm(name); if (!ret) { return -1; } diff --git a/native/jni/resetprop/resetprop.cpp b/native/jni/resetprop/resetprop.cpp index f8596e127..9aebd5974 100644 --- a/native/jni/resetprop/resetprop.cpp +++ b/native/jni/resetprop/resetprop.cpp @@ -21,6 +21,9 @@ static bool verbose = false; #define system_property_read_callback __system_property_read_callback #define system_property_foreach __system_property_foreach #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 static int (*system_property_set)(const char*, const char*); static int (*system_property_read)(const prop_info*, char*, char*);