From db3f267c99411b10144998c6c1f1a6288d0191bc Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 20 Mar 2015 09:45:18 -0700 Subject: Clean up property setting code. In particular, ensure that all property_set failures are reported. Change-Id: Iab94a28bcba2346868c0f39bcfe26e55a2c55562 --- init/builtins.cpp | 67 ++++++++++++++++------------------------------- init/init.cpp | 4 +-- init/keywords.h | 4 +-- init/property_service.cpp | 23 +++++++++------- 4 files changed, 38 insertions(+), 60 deletions(-) diff --git a/init/builtins.cpp b/init/builtins.cpp index 01217c1..e659cfa 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -14,31 +14,31 @@ * limitations under the License. */ -#include -#include +#include #include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include #include +#include +#include #include #include #include +#include +#include #include +#include #include -#include -#include -#include #include #include +#include +#include +#include +#include +#include + #include "init.h" #include "keywords.h" #include "property_service.h" @@ -47,8 +47,6 @@ #include "util.h" #include "log.h" -#include - #define chmod DO_NOT_USE_CHMOD_USE_FCHMODAT_SYMLINK_NOFOLLOW int add_environment(const char *name, const char *value); @@ -674,41 +672,20 @@ int do_sysclktz(int nargs, char **args) } int do_verity_load_state(int nargs, char **args) { - if (nargs == 1) { - int mode = -1; - int rc = fs_mgr_load_verity_state(&mode); - - if (rc == 0 && mode == VERITY_MODE_LOGGING) { - action_for_each_trigger("verity-logging", action_add_queue_tail); - } - - return rc; + int mode = -1; + int rc = fs_mgr_load_verity_state(&mode); + if (rc == 0 && mode == VERITY_MODE_LOGGING) { + action_for_each_trigger("verity-logging", action_add_queue_tail); } - return -1; + return rc; } -static void verity_update_property(struct fstab_rec *fstab, - const char *mount_point, int status) { - char key[PROP_NAME_MAX]; - int ret; - - ret = snprintf(key, PROP_NAME_MAX, "partition.%s.verified", mount_point); - if (ret >= PROP_NAME_MAX) { - ERROR("Error setting verified property for %s: name too long\n", - mount_point); - return; - } - - ret = property_set(key, "1"); - if (ret < 0) - ERROR("Error setting verified property %s: %d\n", key, ret); +static void verity_update_property(fstab_rec *fstab, const char *mount_point, int status) { + property_set(android::base::StringPrintf("partition.%s.verified", mount_point).c_str(), "1"); } -int do_verity_update_state(int nargs, char **args) { - if (nargs == 1) { - return fs_mgr_update_verity_state(verity_update_property); - } - return -1; +int do_verity_update_state(int nargs, char** args) { + return fs_mgr_update_verity_state(verity_update_property); } int do_write(int nargs, char **args) diff --git a/init/init.cpp b/init/init.cpp index dda2aeb..1449bc6 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -807,9 +807,7 @@ static void process_kernel_dt(void) std::replace(dt_file.begin(), dt_file.end(), ',', '.'); std::string property_name = android::base::StringPrintf("ro.boot.%s", dp->d_name); - if (property_set(property_name.c_str(), dt_file.c_str())) { - ERROR("Could not set property %s to value %s", property_name.c_str(), dt_file.c_str()); - } + property_set(property_name.c_str(), dt_file.c_str()); } } diff --git a/init/keywords.h b/init/keywords.h index 09f645b..532d7c5 100644 --- a/init/keywords.h +++ b/init/keywords.h @@ -89,8 +89,8 @@ enum { KEYWORD(symlink, COMMAND, 1, do_symlink) KEYWORD(sysclktz, COMMAND, 1, do_sysclktz) KEYWORD(user, OPTION, 0, 0) - KEYWORD(verity_load_state, COMMAND, 0, do_verity_load_state) - KEYWORD(verity_update_state, COMMAND, 0, do_verity_update_state) + KEYWORD(verity_load_state, COMMAND, 1, do_verity_load_state) + KEYWORD(verity_update_state, COMMAND, 1, do_verity_update_state) KEYWORD(wait, COMMAND, 1, do_wait) KEYWORD(write, COMMAND, 2, do_write) KEYWORD(copy, COMMAND, 2, do_copy) diff --git a/init/property_service.cpp b/init/property_service.cpp index ddb8050..13d671f 100644 --- a/init/property_service.cpp +++ b/init/property_service.cpp @@ -199,18 +199,14 @@ static bool is_legal_property_name(const char* name, size_t namelen) return true; } -int property_set(const char *name, const char *value) -{ - prop_info *pi; - int ret; - +static int property_set_impl(const char* name, const char* value) { size_t namelen = strlen(name); size_t valuelen = strlen(value); if (!is_legal_property_name(name, namelen)) return -1; if (valuelen >= PROP_VALUE_MAX) return -1; - pi = (prop_info*) __system_property_find(name); + prop_info* pi = (prop_info*) __system_property_find(name); if(pi != 0) { /* ro.* properties may NEVER be modified once set */ @@ -218,10 +214,9 @@ int property_set(const char *name, const char *value) __system_property_update(pi, value, valuelen); } else { - ret = __system_property_add(name, namelen, value, valuelen); - if (ret < 0) { - ERROR("Failed to set '%s'='%s'\n", name, value); - return ret; + int rc = __system_property_add(name, namelen, value, valuelen); + if (rc < 0) { + return rc; } } /* If name starts with "net." treat as a DNS property. */ @@ -250,6 +245,14 @@ int property_set(const char *name, const char *value) return 0; } +int property_set(const char* name, const char* value) { + int rc = property_set_impl(name, value); + if (rc == -1) { + ERROR("property_set(\"%s\", \"%s\" failed\n", name, value); + } + return rc; +} + void handle_property_set_fd() { prop_msg msg; -- cgit v1.1