Merge "Clean up property setting code."
This commit is contained in:
commit
b721e8f4d2
4 changed files with 39 additions and 61 deletions
|
|
@ -14,31 +14,31 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.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 <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <stdio.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)
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue