diff options
author | Elliott Hughes <enh@google.com> | 2015-03-20 09:45:18 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-03-20 10:03:32 -0700 |
commit | db3f267c99411b10144998c6c1f1a6288d0191bc (patch) | |
tree | 989b8000829cefb26964ed177ce986b3e38230a9 | |
parent | 1b8dbe74412dd27f2950e0c84feaf09c5b7dcbf0 (diff) | |
download | system_core-db3f267c99411b10144998c6c1f1a6288d0191bc.zip system_core-db3f267c99411b10144998c6c1f1a6288d0191bc.tar.gz system_core-db3f267c99411b10144998c6c1f1a6288d0191bc.tar.bz2 |
Clean up property setting code.
In particular, ensure that all property_set failures are reported.
Change-Id: Iab94a28bcba2346868c0f39bcfe26e55a2c55562
-rw-r--r-- | init/builtins.cpp | 67 | ||||
-rw-r--r-- | init/init.cpp | 4 | ||||
-rw-r--r-- | init/keywords.h | 4 | ||||
-rw-r--r-- | 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 <sys/types.h> -#include <sys/stat.h> +#include <errno.h> #include <fcntl.h> -#include <unistd.h> -#include <string.h> +#include <net/if.h> #include <stdio.h> -#include <linux/kd.h> -#include <errno.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <linux/if.h> -#include <arpa/inet.h> #include <stdlib.h> +#include <string.h> +#include <sys/socket.h> #include <sys/mount.h> #include <sys/resource.h> #include <sys/time.h> +#include <sys/types.h> +#include <sys/stat.h> #include <sys/wait.h> +#include <unistd.h> #include <linux/loop.h> -#include <cutils/partition_utils.h> -#include <cutils/android_reboot.h> -#include <fs_mgr.h> #include <selinux/selinux.h> #include <selinux/label.h> +#include <fs_mgr.h> +#include <base/stringprintf.h> +#include <cutils/partition_utils.h> +#include <cutils/android_reboot.h> +#include <private/android_filesystem_config.h> + #include "init.h" #include "keywords.h" #include "property_service.h" @@ -47,8 +47,6 @@ #include "util.h" #include "log.h" -#include <private/android_filesystem_config.h> - #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; |