int property_set(const char *name, const char *value) { prop_area *pa; prop_info *pi; int namelen = strlen(name); int 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); } property_changed(name, value); return 0; }
static void refresh_cache(struct cache *cache, const char *key) { uint32_t serial; char buf[PROP_VALUE_MAX]; if (!cache->pinfo) { cache->pinfo = __system_property_find(key); if (!cache->pinfo) { return; } cache->serial = -1; } serial = __system_property_serial(cache->pinfo); if (serial == cache->serial) { return; } cache->serial = serial; __system_property_read(cache->pinfo, 0, buf); switch(buf[0]) { case 't': case 'T': cache->c = strcasecmp(buf + 1, "rue") ? buf[0] : BOOLEAN_TRUE; break; case 'f': case 'F': cache->c = strcasecmp(buf + 1, "alse") ? buf[0] : BOOLEAN_FALSE; break; default: cache->c = buf[0]; } }
/* first, set it in our memory, then in init'd memory */ static int property_set_ex(const char *name, const char *value, int mem, mapinfo *mi) { void *pi; int namelen = strlen(name); int valuelen = strlen(value); if(namelen >= PROP_NAME_MAX) { LOGE("name too long!"); return -1; } if(valuelen >= PROP_VALUE_MAX) { LOGE("value too long!"); return -1; } if(namelen < 1) { LOGE("name too short!"); return -1; } pi = (void *)__system_property_find(name); if(pi != 0) { char *pa = (char *)__system_property_area__; if (compat_mode) update_prop_info_compat(mi, pa, pi, value, valuelen); else update_prop_info(mi, pa, pi, value, valuelen); return 0; } return -1; }
static void BM_property_serial(int iters, int nprops) { StopBenchmarkTiming(); LocalPropertyTestState pa(nprops); if (!pa.valid) return; srandom(iters * nprops); const prop_info** pinfo = new const prop_info*[iters]; for (int i = 0; i < iters; i++) { pinfo[i] = __system_property_find(pa.names[random() % nprops]); } // StartBenchmarkTiming(); for (int i = 0; i < iters; i++) { StartBenchmarkTiming(); __system_property_serial(pinfo[i]); StopBenchmarkTimingWithStd(); } // StopBenchmarkTiming(); delete[] pinfo; }
TEST(properties, wait) { #if defined(__BIONIC__) LocalPropertyTestState pa; ASSERT_TRUE(pa.valid); unsigned int serial; prop_info *pi; pthread_t t; int flag = 0; ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); serial = __system_property_wait_any(0); pi = (prop_info *)__system_property_find("property"); ASSERT_NE((prop_info *)NULL, pi); __system_property_update(pi, "value2", 6); serial = __system_property_wait_any(serial); ASSERT_EQ(0, pthread_create(&t, NULL, PropertyWaitHelperFn, &flag)); ASSERT_EQ(flag, 0); serial = __system_property_wait_any(serial); ASSERT_EQ(flag, 1); void* result; ASSERT_EQ(0, pthread_join(t, &result)); #else // __BIONIC__ GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif // __BIONIC__ }
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; }
int __system_property_get(const char *name, char *value) { const prop_info *pi = __system_property_find(name); if (pi != 0) { return __system_property_read(pi, 0, value); } else { value[0] = 0; return 0; } }
static void *PropertyWaitHelperFn(void *arg) { int *flag = (int *)arg; prop_info *pi; pi = (prop_info *)__system_property_find("property"); usleep(100000); *flag = 1; __system_property_update(pi, "value3", 6); return NULL; }
static void refresh_cache_property(struct cache_property* cache, const char* key) { if (!cache->cache.pinfo) { cache->cache.pinfo = __system_property_find(key); if (!cache->cache.pinfo) { return; } } cache->cache.serial = __system_property_serial(cache->cache.pinfo); __system_property_read(cache->cache.pinfo, 0, cache->property); }
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, char *value) { prop_area *pa; prop_info *pi; int namelen = strlen(name); int 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 (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); } return 0; }
const char* property_get(const char *name) { prop_area *pa; const prop_info *pi; int len = 0; pi =__system_property_find(name); if(pi != 0) { return pi->value; } else { return 0; } }
const char* property_get(const char *name) { prop_info *pi; if(strlen(name) >= PROP_NAME_MAX) return 0; pi = (prop_info*) __system_property_find(name); if(pi != 0) { return pi->value; } else { return 0; } }
TEST(properties, update) { #if defined(__BIONIC__) LocalPropertyTestState pa; ASSERT_TRUE(pa.valid); char propvalue[PROP_VALUE_MAX]; prop_info *pi; ASSERT_EQ(0, __system_property_add("property", 8, "oldvalue1", 9)); ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); pi = (prop_info *)__system_property_find("property"); ASSERT_NE((prop_info *)NULL, pi); __system_property_update(pi, "value4", 6); pi = (prop_info *)__system_property_find("other_property"); ASSERT_NE((prop_info *)NULL, pi); __system_property_update(pi, "newvalue5", 9); pi = (prop_info *)__system_property_find("property_other"); ASSERT_NE((prop_info *)NULL, pi); __system_property_update(pi, "value6", 6); ASSERT_EQ(6, __system_property_get("property", propvalue)); ASSERT_STREQ(propvalue, "value4"); ASSERT_EQ(9, __system_property_get("other_property", propvalue)); ASSERT_STREQ(propvalue, "newvalue5"); ASSERT_EQ(6, __system_property_get("property_other", propvalue)); ASSERT_STREQ(propvalue, "value6"); #else // __BIONIC__ GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif // __BIONIC__ }
TEST(properties, serial) { #if defined(__BIONIC__) LocalPropertyTestState pa; ASSERT_TRUE(pa.valid); const prop_info *pi; unsigned int serial; ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); ASSERT_NE((const prop_info *)NULL, pi = __system_property_find("property")); serial = __system_property_serial(pi); ASSERT_EQ(0, __system_property_update((prop_info *)pi, "value2", 6)); ASSERT_NE(serial, __system_property_serial(pi)); #else // __BIONIC__ GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif // __BIONIC__ }
static _res_thread* _res_thread_alloc(void) { _res_thread* rt = calloc(1, sizeof(*rt)); if (rt) { rt->_h_errno = 0; /* Special system property which tracks any changes to 'net.*'. */ rt->_serial = 0; rt->_pi = (struct prop_info*) __system_property_find("net.change"); if (rt->_pi) { rt->_serial = rt->_pi->serial; } memset(rt->_rstatic, 0, sizeof rt->_rstatic); } return rt; }
int wifi_stop_supplicant() { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 50; /* wait at most 5 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES char supp_rdy_status[PROPERTY_VALUE_MAX] = ""; const prop_info *rdy_pi = NULL; int rdy_loop_count = 0; #endif /* Check whether supplicant already stopped */ if (property_get(supplicant_prop_name, supp_status, NULL) && strcmp(supp_status, "stopped") == 0) { return 0; } #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* Wait for the supplicant to deinitialize and set the property (SUPP_RDY_PROP_NAME) to 0 before killing the supplicant */ for (rdy_loop_count = 0; rdy_loop_count < 15000/RDY_WAIT_MS; rdy_loop_count ++) { if (rdy_pi == NULL) { rdy_pi = __system_property_find(SUPP_RDY_PROP_NAME); } else { __system_property_read(rdy_pi, NULL, supp_rdy_status); if (strcmp(supp_rdy_status, "0") == 0) { break; } } usleep (RDY_WAIT_MS * 1000); } #endif property_set("ctl.stop", supplicant_name); sched_yield(); while (count-- > 0) { if (property_get(supplicant_prop_name, supp_status, NULL)) { if (strcmp(supp_status, "stopped") == 0) return 0; } usleep(100000); } return -1; }
static void refresh_cache(struct cache *cache, const char *key) { uint32_t serial; char buf[PROP_VALUE_MAX]; if (!cache->pinfo) { cache->pinfo = __system_property_find(key); if (!cache->pinfo) { return; } } serial = __system_property_serial(cache->pinfo); if (serial == cache->serial) { return; } cache->serial = serial; __system_property_read(cache->pinfo, 0, buf); cache->c = buf[0]; }
static _res_thread* _res_thread_alloc(void) { _res_thread* rt = calloc(1, sizeof(*rt)); if (rt) { rt->_h_errno = 0; /* Special system property which tracks any changes to 'net.*'. */ rt->_serial = 0; #if defined(PROPERTY_SYSTEM_SUPPORT) rt->_pi = (struct prop_info*) __system_property_find("net.change"); if (rt->_pi) { rt->_serial = __system_property_serial(rt->_pi); } #endif memset(rt->_rstatic, 0, sizeof rt->_rstatic); } return rt; }
TEST(properties, errors) { #if defined(__BIONIC__) LocalPropertyTestState pa; ASSERT_TRUE(pa.valid); char prop_value[PROP_NAME_MAX]; ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); ASSERT_EQ(0, __system_property_find("property1")); ASSERT_EQ(0, __system_property_get("property1", prop_value)); ASSERT_EQ(-1, __system_property_add("name", PROP_NAME_MAX, "value", 5)); ASSERT_EQ(-1, __system_property_add("name", 4, "value", PROP_VALUE_MAX)); ASSERT_EQ(-1, __system_property_update(NULL, "value", PROP_VALUE_MAX)); #else // __BIONIC__ GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif // __BIONIC__ }
static void BM_property_find(int iters, int nprops) { StopBenchmarkTiming(); LocalPropertyTestState pa(nprops); if (!pa.valid) return; srandom(iters * nprops); // StartBenchmarkTiming(); for (int i = 0; i < iters; i++) { StartBenchmarkTiming(); __system_property_find(pa.names[random() % nprops]); StopBenchmarkTimingWithStd(); } // StopBenchmarkTiming(); }
int __system_properties_init(void) { prop_area *pa; int fd; unsigned sz; char *env; if(__system_property_area__ != ((void*) &dummy_props)) { return 0; } env = getenv("ANDROID_PROPERTY_WORKSPACE"); if (!env) { return -1; } fd = atoi(env); env = strchr(env, ','); if (!env) { return -1; } sz = atoi(env + 1); pa = mmap(0, sz, PROT_READ, MAP_SHARED, fd, 0); if(pa == MAP_FAILED) { return -1; } if((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION)) { munmap(pa, sz); return -1; } __system_property_area__ = pa; if (0 < pa->count) { /* * Yes - this is C. I like it, but it may have bugs :) * Search the longest value in the /system/build.prop * and /system/default.prop files with a name that starts * with "ro." in order to search this read-only property to * determine PROP_NAME_MAX later on. */ int prop; int minlen = 8; char name[PROP_NAME_LIMIT]; char value[PROP_VALUE_MAX]; for (prop = 0; prop < 2; prop++) { FILE* f = fopen(prop ? PROP_PATH_SYSTEM_BUILD : PROP_PATH_SYSTEM_DEFAULT, "r"); if (f) { char s[32 + PROP_NAME_LIMIT + PROP_VALUE_MAX]; while (fgets(s, sizeof(s), f)) { char* p = s; while (sizeof(s) > p - s && (' ' == *p || '\t' == *p)) p++; if (sizeof(s) > p - s && 0 == strncmp(p, "ro.", 3)) { char* n = p; while (sizeof(s) > p - s && 0 != *p && '=' != *p && ' ' != *p && '\t' != *p) p++; if (sizeof(s) > p - s && 0 != *p) { char* nend = p; while (sizeof(s) > p - s && 0 != *p && '=' != *p) p++; if (sizeof(s) > p - s && '=' == *p) { char *v; *nend = 0; p++; while (sizeof(s) > p - s && (' ' == *p || '\t' == *p)) p++; v = p; while (sizeof(s) > p - s && (' ' <= *p)) p++; if (sizeof(s) > p - s) { char *vend = p; *vend = 0; if (sizeof(name) > nend - n && sizeof(value) > vend - v && minlen < vend - v) { minlen = vend - v; strcpy(name, n); strcpy(value, v); } } } } } } fclose(f); } } if (8 < minlen) { const prop_info *pi = __system_property_find(name); if (0 != pi) { int m = PROP_NAME_MAX; while(m <= PROP_NAME_LIMIT) { if (0 == strcmp(pi->value + (m - PROP_NAME_MAX), value)) { prop_name_max = m; break; } m++; } } } } return 0; }
int start_supplicant(const struct _SUPPLICANT_PARA_T * prTar, const char *pcIface) { char daemon_cmd[PROPERTY_VALUE_MAX]; char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES const prop_info *pi; unsigned serial = 0; #endif /* Check whether already running */ if (property_get(prTar->acSuppPropName, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists(prTar->acSuppConfigFile, prTar->acSuppConfigTemplate) < 0) { LOGE("[%s] %s will not be enabled", pcIface, prTar->acSuppName); return -1; } /*Set interface UP (ifconfig "iface" up)*/ if(set_iface(pcIface, 1) < 0 ) { /*If interface up failed, skip the following actions*/ return -1; } /* Clear out any stale socket files that might be left over. */ LOGD("[%s] clear out stale sockets with prefix \"%s\" in %s", pcIface, prTar->acSuppCtrlPrefix, CONFIG_CTRL_IFACE_CLIENT_DIR); ctrl_cleanup(prTar->acSuppCtrlPrefix); LOGI("[%s] start %s", pcIface, prTar->acSuppName); #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* * Get a reference to the status property, so we can distinguish * the case where it goes stopped => running => stopped (i.e., * it start up, but fails right away) from the case in which * it starts in the stopped state and never manages to start * running at all. */ pi = __system_property_find(prTar->acSuppPropName); if (pi != NULL) { serial = pi->serial; } #endif property_get(prTar->acIfPropName, (char *)pcIface, prTar->acIfDefName); snprintf(daemon_cmd, PROPERTY_VALUE_MAX, prTar->acSuppDeamonCmd, prTar->acSuppName, pcIface, prTar->acSuppConfigFile); property_set("ctl.start", daemon_cmd); LOGD("[%s] supplicant start command: \"%s\"", pcIface, daemon_cmd); //property_set("ctl.start", prTar->acSuppName); sched_yield(); while (count-- > 0) { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES if (pi == NULL) { pi = __system_property_find(prTar->acSuppPropName); } if (pi != NULL) { __system_property_read(pi, NULL, supp_status); if (strcmp(supp_status, "running") == 0) { return 0; } else if (pi->serial != serial && strcmp(supp_status, "stopped") == 0) { return -1; } } #else if (property_get(prTar->acSuppPropName, supp_status, NULL)) { if (strcmp(supp_status, "running") == 0) return 0; } #endif usleep(100000); } return -1; }
static _res_thread* _res_thread_get(void) { _res_thread* rt; pthread_once( &_res_once, _res_init_key ); rt = pthread_getspecific( _res_key ); if (rt != NULL) { /* We already have one thread-specific DNS state object. * Check the serial value for any changes to net.* properties */ D("%s: Called for tid=%d rt=%p rt->pi=%p rt->serial=%d", __FUNCTION__, gettid(), rt, rt->_pi, rt->_serial); if (rt->_pi == NULL) { /* The property wasn't created when _res_thread_get() was * called the last time. This should only happen very * early during the boot sequence. First, let's try to see if it * is here now. */ rt->_pi = (struct prop_info*) __system_property_find("net.change"); if (rt->_pi == NULL) { /* Still nothing, return current state */ D("%s: exiting for tid=%d rt=%d since system property not found", __FUNCTION__, gettid(), rt); return rt; } } if (rt->_serial == rt->_pi->serial) { /* Nothing changed, so return the current state */ D("%s: tid=%d rt=%p nothing changed, returning", __FUNCTION__, gettid(), rt); return rt; } /* Update the recorded serial number, and go reset the state */ rt->_serial = rt->_pi->serial; goto RESET_STATE; } /* It is the first time this function is called in this thread, * we need to create a new thread-specific DNS resolver state. */ rt = _res_thread_alloc(); if (rt == NULL) { return NULL; } pthread_setspecific( _res_key, rt ); D("%s: tid=%d Created new DNS state rt=%p", __FUNCTION__, gettid(), rt); RESET_STATE: /* Reset the state, note that res_ninit() can now properly reset * an existing state without leaking memory. */ D("%s: tid=%d, rt=%p, resetting DNS state (options RES_INIT=%d)", __FUNCTION__, gettid(), rt, (rt->_nres->options & RES_INIT) != 0); if ( res_ninit( rt->_nres ) < 0 ) { /* This should not happen */ D("%s: tid=%d rt=%p, woot, res_ninit() returned < 0", __FUNCTION__, gettid(), rt); _res_thread_free(rt); pthread_setspecific( _res_key, NULL ); return NULL; } return rt; }
int getprop_main(const struct cmd_getprop_info* info) { const char* format = info->getprop.format; const char* format_not_found = info->getprop.format_not_found; bool null = info->getprop.null; if (null && format == NULL && format_not_found == NULL) usage_error("must supply --format or " "--format-not-found or both if using -0"); find_symbol_in_libc("__system_property_foreach", &property_foreach); if (property_foreach == NULL) property_foreach = compat_property_foreach; dbg("using %s for property enumeration", property_foreach == compat_property_foreach ? "compat_property_foreach" : "__system_property_foreach"); int exit_status = 0; struct json_writer* writer = NULL; if (format == NULL && format_not_found == NULL) { writer = json_writer_create(xstdout); json_begin_object(writer); } const char** properties = ARGV_CONCAT(info->properties); bool first = true; char sep = null ? '\0' : '\n'; if (*properties == NULL) { struct property_vector* pv = find_all_properties(); char prev_name[PROP_NAME_MAX]; for (size_t i = 0; i < pv->size; ++i) { char name[PROP_NAME_MAX]; char value[PROP_VALUE_MAX]; (void) __system_property_read(pv->props[i], name, value); if (i > 0 && strcmp(name, prev_name) == 0) continue; if (writer != NULL) { json_begin_field(writer, name); json_emit_string(writer, value); } else { output_property(&first, sep, format, name, value); } strcpy(prev_name, name); } } else { size_t nproperties = argv_count(properties); qsort(properties, nproperties, sizeof (properties[0]), property_argv_compare); const char* property; const char* prev_property = NULL; while ((property = *properties++)) { if (prev_property != NULL && !strcmp(prev_property, property)) continue; if (writer != NULL) json_begin_field(writer, property); const prop_info* pi = __system_property_find(property); if (pi) { char value[PROP_VALUE_MAX]; __system_property_read(pi, NULL, value); if (writer != NULL) json_emit_string(writer, value); else if (format != NULL) output_property(&first, sep, format, property, value); } else { if (writer != NULL) json_emit_null(writer); else if (format_not_found != NULL) output_property(&first, sep, format_not_found, property, NULL); exit_status = 4; } prev_property = property; } } if (writer == NULL && !first && !null) xputc(sep, xstdout); if (writer != NULL) json_end_object(writer); xflush(xstdout); return exit_status; }
int wifi_start_supplicant() { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES const prop_info *pi; unsigned serial = 0; #endif /* Check whether already running */ if (property_get(SUPP_PROP_NAME, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists() < 0) { LOGE("Wi-Fi will not be enabled"); return -1; } /* Clear out any stale socket files that might be left over. */ wpa_ctrl_cleanup(); #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* * Get a reference to the status property, so we can distinguish * the case where it goes stopped => running => stopped (i.e., * it start up, but fails right away) from the case in which * it starts in the stopped state and never manages to start * running at all. */ pi = __system_property_find(SUPP_PROP_NAME); if (pi != NULL) { serial = pi->serial; } #endif /* The ar6k driver needs the interface up in order to scan! */ if (!strncmp(DRIVER_MODULE_NAME, "ar6000", 6)) { ifc_init(); ifc_up("wlan0"); sleep(1); } property_set("ctl.start", SUPPLICANT_NAME); sched_yield(); while (count-- > 0) { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES if (pi == NULL) { pi = __system_property_find(SUPP_PROP_NAME); } if (pi != NULL) { __system_property_read(pi, NULL, supp_status); if (strcmp(supp_status, "running") == 0) { return 0; } else if (pi->serial != serial && strcmp(supp_status, "stopped") == 0) { return -1; } } #else if (property_get(SUPP_PROP_NAME, supp_status, NULL)) { if (strcmp(supp_status, "running") == 0) return 0; } #endif usleep(100000); } return -1; }
int wifi_start_supplicant(int p2p_supported) { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES const prop_info *pi; unsigned serial = 0, i; #endif if (p2p_supported) { strcpy(supplicant_name, P2P_SUPPLICANT_NAME); strcpy(supplicant_prop_name, P2P_PROP_NAME); /* Ensure p2p config file is created */ if (ensure_config_file_exists(P2P_CONFIG_FILE) < 0) { ALOGE("Failed to create a p2p config file"); return -1; } } else { strcpy(supplicant_name, SUPPLICANT_NAME); strcpy(supplicant_prop_name, SUPP_PROP_NAME); } /* Check whether already running */ if (property_get(supplicant_prop_name, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists(SUPP_CONFIG_FILE) < 0) { ALOGE("Wi-Fi will not be enabled"); return -1; } if (ensure_entropy_file_exists() < 0) { ALOGE("Wi-Fi entropy file was not created"); } /* Clear out any stale socket files that might be left over. */ wpa_ctrl_cleanup(); /* Reset sockets used for exiting from hung state */ exit_sockets[0] = exit_sockets[1] = -1; #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* * Get a reference to the status property, so we can distinguish * the case where it goes stopped => running => stopped (i.e., * it start up, but fails right away) from the case in which * it starts in the stopped state and never manages to start * running at all. */ pi = __system_property_find(supplicant_prop_name); if (pi != NULL) { serial = __system_property_serial(pi); } #endif property_get("wifi.interface", primary_iface, WIFI_TEST_INTERFACE); property_set("ctl.start", supplicant_name); sched_yield(); while (count-- > 0) { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES if (pi == NULL) { pi = __system_property_find(supplicant_prop_name); } if (pi != NULL) { /* * property serial updated means that init process is scheduled * after we sched_yield, further property status checking is based on this */ if (__system_property_serial(pi) != serial) { __system_property_read(pi, NULL, supp_status); if (strcmp(supp_status, "running") == 0) { return 0; } else if (strcmp(supp_status, "stopped") == 0) { return -1; } } } #else if (property_get(supplicant_prop_name, supp_status, NULL)) { if (strcmp(supp_status, "running") == 0) return 0; } #endif usleep(100000); } return -1; }
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; }
int wifi_start_supplicant_common(const char *config_file) { char daemon_cmd[PROPERTY_VALUE_MAX]; char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES const prop_info *pi; unsigned serial = 0; #endif /* Check whether already running */ if (property_get(SUPP_PROP_NAME, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists(config_file) < 0) { LOGE("Wi-Fi will not be enabled"); return -1; } if (ensure_entropy_file_exists() < 0) { LOGE("Wi-Fi entropy file was not created"); } /* Clear out any stale socket files that might be left over. */ wifi_wpa_ctrl_cleanup(); #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* * Get a reference to the status property, so we can distinguish * the case where it goes stopped => running => stopped (i.e., * it start up, but fails right away) from the case in which * it starts in the stopped state and never manages to start * running at all. */ pi = __system_property_find(SUPP_PROP_NAME); if (pi != NULL) { serial = pi->serial; } #endif property_get("wifi.interface", iface, WIFI_TEST_INTERFACE); snprintf(daemon_cmd, PROPERTY_VALUE_MAX, "%s:-i%s -c%s", SUPPLICANT_NAME, iface, config_file); property_set("ctl.start", daemon_cmd); sched_yield(); while (count-- > 0) { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES if (pi == NULL) { pi = __system_property_find(SUPP_PROP_NAME); } if (pi != NULL) { __system_property_read(pi, NULL, supp_status); if (strcmp(supp_status, "running") == 0) { return 0; } else if (pi->serial != serial && strcmp(supp_status, "stopped") == 0) { return -1; } } #else if (property_get(SUPP_PROP_NAME, supp_status, NULL)) { if (strcmp(supp_status, "running") == 0) return 0; } #endif usleep(100000); } return -1; }