int property_set(const char *name, const char *value) { prop_info *pi; int ret; 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); if(pi != 0) { /* ro.* properties may NEVER be modified once set */ // ro,只读的property只能被设定一次 if(!strncmp(name, "ro.", 3)) return -1; __system_property_update(pi, value, valuelen); } else { // 将key和value写入到shared memory中 ret = __system_property_add(name, namelen, value, valuelen); if (ret < 0) { ERROR("Failed to set '%s'='%s'\n", name, value); return ret; } } /* If name starts with "net." treat as a DNS property. */ if (strncmp("net.", name, strlen("net.")) == 0) { if (strcmp("net.change", name) == 0) { return 0; } /* * The 'net.change' property is a special property used track when any * 'net.*' property name is updated. It is _ONLY_ updated here. Its value * contains the last updated 'net.*' property. */ property_set("net.change", name); } else if (persistent_properties_loaded && strncmp("persist.", name, strlen("persist.")) == 0) { char bootmode[PROP_VALUE_MAX]; ret = property_get("ro.bootmode", bootmode); if (ret <= 0 || (strcmp(bootmode, "charger") != 0)) //do not write prop while charger mode /* * Don't write properties to disk until after we have read all default properties * to prevent them from being overwritten by default values. */ write_persistent_property(name, value); } else if (strcmp("selinux.reload_policy", name) == 0 && strcmp("1", value) == 0) { selinux_reload_policy(); } property_changed(name, value); #ifdef AW_BOOSTUP_ENABLE aw_boost_up_perf(name, value); #endif return 0; }
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; if (strcmp("selinux.reload_policy", name) == 0 && strcmp("1", value) == 0) { if (selinux_reload_policy() != 0) { ERROR("Failed to reload policy\n"); } } else if (strcmp("selinux.restorecon_recursive", name) == 0 && valuelen > 0) { if (restorecon_recursive(value) != 0) { ERROR("Failed to restorecon_recursive %s\n", value); } } prop_info* pi = (prop_info*) __system_property_find(name); if(pi != 0) { /* ro.* properties may NEVER be modified once set */ if(!strncmp(name, "ro.", 3)) return -1; __system_property_update(pi, value, valuelen); } else { int rc = __system_property_add(name, namelen, value, valuelen); if (rc < 0) { return rc; } } /* If name starts with "net." treat as a DNS property. */ if (strncmp("net.", name, strlen("net.")) == 0) { if (strcmp("net.change", name) == 0) { return 0; } /* * The 'net.change' property is a special property used track when any * 'net.*' property name is updated. It is _ONLY_ updated here. Its value * contains the last updated 'net.*' property. */ property_set("net.change", name); } else if (persistent_properties_loaded && strncmp("persist.", name, strlen("persist.")) == 0) { /* * Don't write properties to disk until after we have read all default properties * to prevent them from being overwritten by default values. */ write_persistent_property(name, value); } property_changed(name, value); return 0; }
int property_set(const char *name, const char *value) { prop_area *pa; prop_info *pi; size_t namelen = strlen(name); size_t valuelen = strlen(value); if(namelen >= PROP_NAME_MAX) return -1; if(valuelen >= PROP_VALUE_MAX) return -1; if(namelen < 1) return -1; pi = (prop_info*) __system_property_find(name); if(pi != 0) { /* ro.* properties may NEVER be modified once set */ if(!strncmp(name, "ro.", 3)) return -1; pa = __system_property_area__; update_prop_info(pi, value, valuelen); pa->serial++; __futex_wake(&pa->serial, INT32_MAX); } else { pa = __system_property_area__; if(pa->count == PA_COUNT_MAX) return -1; pi = pa_info_array + pa->count; pi->serial = (valuelen << 24); memcpy(pi->name, name, namelen + 1); memcpy(pi->value, value, valuelen + 1); pa->toc[pa->count] = (namelen << 24) | (((unsigned) pi) - ((unsigned) pa)); pa->count++; pa->serial++; __futex_wake(&pa->serial, INT32_MAX); } /* If name starts with "net." treat as a DNS property. */ if (strncmp("net.", name, strlen("net.")) == 0) { if (strcmp("net.change", name) == 0) { return 0; } /* * The 'net.change' property is a special property used track when any * 'net.*' property name is updated. It is _ONLY_ updated here. Its value * contains the last updated 'net.*' property. */ property_set("net.change", name); } else if (persistent_properties_loaded && strncmp("persist.", name, strlen("persist.")) == 0) { /* * Don't write properties to disk until after we have read all default properties * to prevent them from being overwritten by default values. */ write_persistent_property(name, value); } else if (strcmp("selinux.reload_policy", name) == 0 && strcmp("1", value) == 0) { selinux_reload_policy(); } property_changed(name, value); return 0; }
int property_set_overwirte(const char *name, const char *value, int allow_overwirte_ro) ////Lenovo [EasyImage] { prop_info *pi; int ret; size_t namelen = strlen(name); size_t valuelen = strlen(value); if (!is_legal_property_name(name, namelen)) { ERROR("PropSet Error:[%s:%s] property name is illegal\n", name, value); return -1; } if (valuelen >= PROP_VALUE_MAX) { ERROR("PropSet Error:[%s:%s] valuelen %d >= %d\n", name, value, valuelen, PROP_VALUE_MAX); return -1; } #ifdef MTK_INIT INFO("PropSet [%s:%s] Start>>\n", name, value); #endif pi = (prop_info*) __system_property_find(name); if(pi != 0) { /* ro.* properties may NEVER be modified once set */ if(allow_overwirte_ro!= 1 && !strncmp(name, "ro.", 3)){ #ifdef MTK_INIT ERROR("PropSet Error:[%s:%s] ro.* properties may NEVER be modified once set\n", name, value); #endif return -1; } __system_property_update(pi, value, valuelen); } else { #ifdef INIT_ENG_BUILD prop_area *pa = __system_property_area__; if ((pa->bytes_used > PA_SIZE_ERR) && (0 == alarmed )) { alarmed = 1; ERROR("[Property Error]: Unable to set [%s:%s] property limit has arrived: %d\n", name, value, pa->bytes_used); #ifdef MTK_INIT property_show(); #endif } else if ((pa->bytes_used > PA_SIZE_WARN) && (0 == warned )) { warned = 1; NOTICE("[Property Warning]: limit would be arrived:%d (Max:%d). " "Use getprop to review your properties!\n", pa->bytes_used, PA_SIZE); #ifdef MTK_INIT property_show(); #endif } #endif ret = __system_property_add(name, namelen, value, valuelen); if (ret < 0) { #ifdef INIT_ENG_BUILD ERROR("Failed to set '%s'='%s' bytes_used=%u\n", name, value, pa->bytes_used); #else ERROR("Failed to set '%s'='%s'\n", name, value); #endif return ret; } } /* If name starts with "net." treat as a DNS property. */ if (strncmp("net.", name, strlen("net.")) == 0) { if (strcmp("net.change", name) == 0) { #ifdef MTK_INIT INFO("PropSet [%s:%s] Done\n", name, value); #endif return 0; } /* * The 'net.change' property is a special property used track when any * 'net.*' property name is updated. It is _ONLY_ updated here. Its value * contains the last updated 'net.*' property. */ property_set("net.change", name); } else if (persistent_properties_loaded && strncmp("persist.", name, strlen("persist.")) == 0) { /* * Don't write properties to disk until after we have read all default properties * to prevent them from being overwritten by default values. */ write_persistent_property(name, value); } else if (strcmp("selinux.reload_policy", name) == 0 && strcmp("1", value) == 0) { selinux_reload_policy(); } property_changed(name, value); #ifdef MTK_INIT INFO("PropSet [%s:%s] Done\n", name, value); #endif return 0; }