init进程会启动一个属性服务器,而客户端只能通过与属性服务器的交互来设置属性。
启动属性服务器
先来看一下属性服务器的内容,它由property_service_init_action函数启动,源码如下(/system/core/init/init.c&&property_service.c):
- static int property_service_init_action(int nargs, char **args) {
- start_property_service(); return 0;
- }
- static void load_override_properties() {
- #ifdef ALLOW_LOCAL_PROP_OVERRIDE char debuggable[PROP_VALUE_MAX];
- int ret;
- ret = property_get("ro.debuggable", debuggable); if (ret && (strcmp(debuggable, "1") == 0)) {
- load_properties_from_file(PROP_PATH_LOCAL_OVERRIDE); }
- #endif }
- static void load_properties(char *data)
- { char *key, *value, *eol, *sol, *tmp;
- sol = data;
- while ((eol = strchr(sol, 'n'))) { key = sol;
- // 赋值下一行的指针给sol *eol ++ = 0;
- sol = eol;
- value = strchr(key, '='); if (value == 0) continue;
- *value++ = 0;
- while (isspace(*key)) key ++; if (*key == '#') continue;
- tmp = value - 2; while ((tmp > key) && isspace(*tmp)) *tmp-- = 0;
- while (isspace(*value)) value ++;
- tmp = eol - 2; while ((tmp > value) && isspace(*tmp)) *tmp-- = 0;
- property_set(key, value);
- } }
- int create_socket(const char *name, int type, mode_t perm, uid_t uid, gid_t gid)
- { struct sockaddr_un addr;
- int fd, ret; char *secon;
- fd = socket(PF_UNIX, type, 0);










