Пример #1
0
static int init_property_area(void)
{
    if (property_area_inited)
        return -1;

    if(__system_property_area_init())
        return -1;

    if(init_workspace(&pa_workspace, 0))
        return -1;

    fcntl(pa_workspace.fd, F_SETFD, FD_CLOEXEC);

    property_area_inited = 1;
    return 0;
}
Пример #2
0
void property_init() {
    if (property_area_initialized) {
        return;
    }

    property_area_initialized = true;

    if (__system_property_area_init()) {
        return;
    }

    pa_workspace.size = 0;
    pa_workspace.fd = open(PROP_FILENAME, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
    if (pa_workspace.fd == -1) {
        ERROR("Failed to open %s: %s\n", PROP_FILENAME, strerror(errno));
        return;
    }
}
Пример #3
0
static int init_property_area(void)
{
    // 如果已经初始化了就直接返回
    if (property_area_inited)
        return -1;

    if(__system_property_area_init())
        return -1;

    // 初始化workspace,得到shared memory的fd, size, data
    if(init_workspace(&pa_workspace, 0))
        return -1;

    // pa指向shared memory的头,实际就是头信息,并初始化
    fcntl(pa_workspace.fd, F_SETFD, FD_CLOEXEC);

    property_area_inited = 1;
    return 0;
}
    LocalPropertyTestState() : valid(false) {
        const char* ANDROID_DATA = getenv("ANDROID_DATA");
        char dir_template[PATH_MAX];
        snprintf(dir_template, sizeof(dir_template), "%s/local/tmp/prop-XXXXXX", ANDROID_DATA);
        char* dirname = mkdtemp(dir_template);
        if (!dirname) {
            fprintf(stderr, "making temp file for test state failed (is %s writable?): %s",
                    dir_template, strerror(errno));
            return;
        }

        old_pa = __system_property_area__;
        __system_property_area__ = NULL;

        pa_dirname = dirname;
        pa_filename = pa_dirname + "/__properties__";

        __system_property_set_filename(pa_filename.c_str());
        __system_property_area_init();
        valid = true;
    }
    LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
        static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";

        const char* android_data = getenv("ANDROID_DATA");
        if (android_data == NULL) {
          printf("ANDROID_DATA environment variable not set\n");
          return;
        }
        char dir_template[PATH_MAX];
        snprintf(dir_template, sizeof(dir_template), "%s/local/tmp/prop-XXXXXX", android_data);
        char *dirname = mkdtemp(dir_template);
        if (!dirname) {
            printf("making temp file for test state failed (is %s/local/tmp writable?): %s\n",
                   android_data, strerror(errno));
            return;
        }

        old_pa = __system_property_area__;
        __system_property_area__ = NULL;

        pa_dirname = dirname;
        pa_filename = pa_dirname + "/__properties__";

        __system_property_set_filename(pa_filename.c_str());
        __system_property_area_init();

        names = new char* [nprops];
        name_lens = new int[nprops];
        values = new char* [nprops];
        value_lens = new int[nprops];

        srandom(nprops);

        for (int i = 0; i < nprops; i++) {
            // Make sure the name has at least 10 characters to make
            // it very unlikely to generate the same random name.
            name_lens[i] = (random() % (PROP_NAME_MAX - 10)) + 10;
            names[i] = new char[PROP_NAME_MAX + 1];
            size_t prop_name_len = sizeof(prop_name_chars) - 1;
            for (int j = 0; j < name_lens[i]; j++) {
                if (j == 0 || names[i][j-1] == '.' || j == name_lens[i] - 1) {
                    // Certain values are not allowed:
                    // - Don't start name with '.'
                    // - Don't allow '.' to appear twice in a row
                    // - Don't allow the name to end with '.'
                    // This assumes that '.' is the last character in the
                    // array so that decrementing the length by one removes
                    // the value from the possible values.
                    prop_name_len--;
                }
                names[i][j] = prop_name_chars[random() % prop_name_len];
            }
            names[i][name_lens[i]] = 0;

            // Make sure the value contains at least 1 character.
            value_lens[i] = (random() % (PROP_VALUE_MAX - 1)) + 1;
            values[i] = new char[PROP_VALUE_MAX];
            for (int j = 0; j < value_lens[i]; j++) {
                values[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)];
            }

            if (__system_property_add(names[i], name_lens[i], values[i], value_lens[i]) < 0) {
                printf("Failed to add a property, terminating...\n");
                printf("%s = %.*s\n", names[i], value_lens[i], values[i]);
                exit(1);
            }
        }

        valid = true;
    }
void property_init() {
    if (__system_property_area_init()) {
        ERROR("Failed to initialize property area\n");
        exit(1);
    }
}
void property_init() {
    if (__system_property_area_init()) {
        LOG(ERROR) << "Failed to initialize property area";
        exit(1);
    }
}