2009-03-04 04:28:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2014-02-19 18:59:05 +01:00
|
|
|
#include <new>
|
2014-08-01 00:53:22 +02:00
|
|
|
#include <stdatomic.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
#include <stdio.h>
|
2013-01-24 08:07:06 +01:00
|
|
|
#include <stdint.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <errno.h>
|
2011-03-30 22:10:04 +02:00
|
|
|
#include <poll.h>
|
2013-01-23 18:28:35 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdbool.h>
|
2013-06-20 20:27:56 +02:00
|
|
|
#include <string.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/select.h>
|
2013-01-23 18:28:35 +01:00
|
|
|
#include <sys/stat.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
|
|
|
#include <sys/_system_properties.h>
|
2014-02-19 18:59:05 +01:00
|
|
|
#include <sys/system_properties.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-05-22 03:27:40 +02:00
|
|
|
#include "private/bionic_futex.h"
|
2014-05-10 04:12:08 +02:00
|
|
|
#include "private/bionic_macros.h"
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
|
2013-01-24 08:07:06 +01:00
|
|
|
|
|
|
|
|
2013-06-20 20:27:56 +02:00
|
|
|
/*
|
|
|
|
* Properties are stored in a hybrid trie/binary tree structure.
|
|
|
|
* Each property's name is delimited at '.' characters, and the tokens are put
|
|
|
|
* into a trie structure. Siblings at each level of the trie are stored in a
|
|
|
|
* binary tree. For instance, "ro.secure"="1" could be stored as follows:
|
|
|
|
*
|
|
|
|
* +-----+ children +----+ children +--------+
|
|
|
|
* | |-------------->| ro |-------------->| secure |
|
|
|
|
* +-----+ +----+ +--------+
|
|
|
|
* / \ / |
|
|
|
|
* left / \ right left / | prop +===========+
|
|
|
|
* v v v +-------->| ro.secure |
|
|
|
|
* +-----+ +-----+ +-----+ +-----------+
|
|
|
|
* | net | | sys | | com | | 1 |
|
|
|
|
* +-----+ +-----+ +-----+ +===========+
|
|
|
|
*/
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
// Represents a node in the trie.
|
2013-06-20 20:27:56 +02:00
|
|
|
struct prop_bt {
|
|
|
|
uint8_t namelen;
|
|
|
|
uint8_t reserved[3];
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
// The property trie is updated only by the init process (single threaded) which provides
|
|
|
|
// property service. And it can be read by multiple threads at the same time.
|
|
|
|
// As the property trie is not protected by locks, we use atomic_uint_least32_t types for the
|
|
|
|
// left, right, children "pointers" in the trie node. To make sure readers who see the
|
|
|
|
// change of "pointers" can also notice the change of prop_bt structure contents pointed by
|
|
|
|
// the "pointers", we always use release-consume ordering pair when accessing these "pointers".
|
|
|
|
|
|
|
|
// prop "points" to prop_info structure if there is a propery associated with the trie node.
|
|
|
|
// Its situation is similar to the left, right, children "pointers". So we use
|
|
|
|
// atomic_uint_least32_t and release-consume ordering to protect it as well.
|
|
|
|
|
2014-08-01 00:53:22 +02:00
|
|
|
// We should also avoid rereading these fields redundantly, since not
|
|
|
|
// all processor implementations ensure that multiple loads from the
|
|
|
|
// same field are carried out in the right order.
|
2015-02-11 06:35:56 +01:00
|
|
|
atomic_uint_least32_t prop;
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
atomic_uint_least32_t left;
|
|
|
|
atomic_uint_least32_t right;
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
atomic_uint_least32_t children;
|
2013-06-21 22:02:38 +02:00
|
|
|
|
|
|
|
char name[0];
|
2014-02-19 18:59:05 +01:00
|
|
|
|
|
|
|
prop_bt(const char *name, const uint8_t name_length) {
|
|
|
|
this->namelen = name_length;
|
|
|
|
memcpy(this->name, name, name_length);
|
|
|
|
this->name[name_length] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-05-10 04:12:08 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(prop_bt);
|
2013-06-20 20:27:56 +02:00
|
|
|
};
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
struct prop_area {
|
|
|
|
uint32_t bytes_used;
|
2014-08-01 00:53:22 +02:00
|
|
|
atomic_uint_least32_t serial;
|
2014-02-19 18:59:05 +01:00
|
|
|
uint32_t magic;
|
|
|
|
uint32_t version;
|
|
|
|
uint32_t reserved[28];
|
|
|
|
char data[0];
|
|
|
|
|
|
|
|
prop_area(const uint32_t magic, const uint32_t version) :
|
2014-08-01 00:53:22 +02:00
|
|
|
magic(magic), version(version) {
|
|
|
|
atomic_init(&serial, 0);
|
2014-02-19 18:59:05 +01:00
|
|
|
memset(reserved, 0, sizeof(reserved));
|
|
|
|
// Allocate enough space for the root node.
|
|
|
|
bytes_used = sizeof(prop_bt);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-05-10 04:12:08 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(prop_area);
|
2014-02-19 18:59:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct prop_info {
|
2014-08-01 00:53:22 +02:00
|
|
|
atomic_uint_least32_t serial;
|
2014-02-19 18:59:05 +01:00
|
|
|
char value[PROP_VALUE_MAX];
|
|
|
|
char name[0];
|
|
|
|
|
|
|
|
prop_info(const char *name, const uint8_t namelen, const char *value,
|
|
|
|
const uint8_t valuelen) {
|
|
|
|
memcpy(this->name, name, namelen);
|
|
|
|
this->name[namelen] = '\0';
|
2014-08-01 00:53:22 +02:00
|
|
|
atomic_init(&this->serial, valuelen << 24);
|
2014-02-19 18:59:05 +01:00
|
|
|
memcpy(this->value, value, valuelen);
|
|
|
|
this->value[valuelen] = '\0';
|
|
|
|
}
|
|
|
|
private:
|
2014-05-10 04:12:08 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(prop_info);
|
2014-02-19 18:59:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct find_nth_cookie {
|
|
|
|
uint32_t count;
|
|
|
|
const uint32_t n;
|
|
|
|
const prop_info *pi;
|
|
|
|
|
|
|
|
find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
|
|
|
|
}
|
|
|
|
};
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2013-02-13 23:41:48 +01:00
|
|
|
static char property_filename[PATH_MAX] = PROP_FILENAME;
|
2013-06-25 03:36:39 +02:00
|
|
|
static bool compat_mode = false;
|
2014-02-19 18:59:05 +01:00
|
|
|
static size_t pa_data_size;
|
|
|
|
static size_t pa_size;
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
// NOTE: This isn't static because system_properties_compat.c
|
|
|
|
// requires it.
|
2013-06-19 22:31:21 +02:00
|
|
|
prop_area *__system_property_area__ = NULL;
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2013-01-23 18:28:35 +01:00
|
|
|
static int get_fd_from_env(void)
|
|
|
|
{
|
2014-02-19 18:59:05 +01:00
|
|
|
// This environment variable consistes of two decimal integer
|
|
|
|
// values separated by a ",". The first value is a file descriptor
|
|
|
|
// and the second is the size of the system properties area. The
|
|
|
|
// size is currently unused.
|
2013-01-23 18:28:35 +01:00
|
|
|
char *env = getenv("ANDROID_PROPERTY_WORKSPACE");
|
|
|
|
|
|
|
|
if (!env) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return atoi(env);
|
|
|
|
}
|
|
|
|
|
2013-06-19 22:31:21 +02:00
|
|
|
static int map_prop_area_rw()
|
2013-01-24 08:07:06 +01:00
|
|
|
{
|
2013-02-13 23:41:48 +01:00
|
|
|
/* dev is a tmpfs that we can use to carve a shared workspace
|
|
|
|
* out of, so let's do that...
|
|
|
|
*/
|
2014-02-19 18:59:05 +01:00
|
|
|
const int fd = open(property_filename,
|
|
|
|
O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC | O_EXCL, 0444);
|
|
|
|
|
2013-02-13 23:41:48 +01:00
|
|
|
if (fd < 0) {
|
|
|
|
if (errno == EACCES) {
|
|
|
|
/* for consistency with the case where the process has already
|
|
|
|
* mapped the page in and segfaults when trying to write to it
|
|
|
|
*/
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
if (ftruncate(fd, PA_SIZE) < 0) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
|
2013-06-25 03:42:21 +02:00
|
|
|
pa_size = PA_SIZE;
|
|
|
|
pa_data_size = pa_size - sizeof(prop_area);
|
2013-06-25 03:36:39 +02:00
|
|
|
compat_mode = false;
|
2013-06-25 03:42:21 +02:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
void *const memory_area = mmap(NULL, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
if (memory_area == MAP_FAILED) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
prop_area *pa = new(memory_area) prop_area(PROP_AREA_MAGIC, PROP_AREA_VERSION);
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2013-01-24 08:07:06 +01:00
|
|
|
/* plug into the lib property services */
|
2013-06-19 22:31:21 +02:00
|
|
|
__system_property_area__ = pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
static int map_fd_ro(const int fd) {
|
|
|
|
struct stat fd_stat;
|
|
|
|
if (fstat(fd, &fd_stat) < 0) {
|
2013-02-13 23:41:48 +01:00
|
|
|
return -1;
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
if ((fd_stat.st_uid != 0)
|
|
|
|
|| (fd_stat.st_gid != 0)
|
|
|
|
|| ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0)
|
2014-02-24 12:05:02 +01:00
|
|
|
|| (fd_stat.st_size < static_cast<off_t>(sizeof(prop_area))) ) {
|
2014-02-19 18:59:05 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
pa_size = fd_stat.st_size;
|
|
|
|
pa_data_size = pa_size - sizeof(prop_area);
|
|
|
|
|
|
|
|
void* const map_result = mmap(NULL, pa_size, PROT_READ, MAP_SHARED, fd, 0);
|
|
|
|
if (map_result == MAP_FAILED) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop_area* pa = reinterpret_cast<prop_area*>(map_result);
|
|
|
|
if ((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION &&
|
|
|
|
pa->version != PROP_AREA_VERSION_COMPAT)) {
|
|
|
|
munmap(pa, pa_size);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pa->version == PROP_AREA_VERSION_COMPAT) {
|
|
|
|
compat_mode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
__system_property_area__ = pa;
|
|
|
|
return 0;
|
2013-01-24 08:07:06 +01:00
|
|
|
}
|
|
|
|
|
2013-06-19 22:31:21 +02:00
|
|
|
static int map_prop_area()
|
2009-03-04 04:28:35 +01:00
|
|
|
{
|
2014-08-27 01:20:59 +02:00
|
|
|
int fd = open(property_filename, O_CLOEXEC | O_NOFOLLOW | O_RDONLY);
|
2014-02-19 18:59:05 +01:00
|
|
|
bool close_fd = true;
|
2014-08-27 01:20:59 +02:00
|
|
|
if (fd == -1 && errno == ENOENT) {
|
2013-01-23 18:28:35 +01:00
|
|
|
/*
|
|
|
|
* For backwards compatibility, if the file doesn't
|
|
|
|
* exist, we use the environment to get the file descriptor.
|
|
|
|
* For security reasons, we only use this backup if the kernel
|
|
|
|
* returns ENOENT. We don't want to use the backup if the kernel
|
|
|
|
* returns other errors such as ENOMEM or ENFILE, since it
|
|
|
|
* might be possible for an external program to trigger this
|
|
|
|
* condition.
|
|
|
|
*/
|
|
|
|
fd = get_fd_from_env();
|
2014-02-19 18:59:05 +01:00
|
|
|
close_fd = false;
|
2013-01-23 18:28:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fd < 0) {
|
2009-03-04 04:28:35 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2013-01-23 18:28:35 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
const int map_result = map_fd_ro(fd);
|
|
|
|
if (close_fd) {
|
2013-01-25 22:07:31 +01:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
return map_result;
|
2009-03-04 04:28:35 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
static void *allocate_obj(const size_t size, uint_least32_t *const off)
|
2013-02-13 01:39:31 +01:00
|
|
|
{
|
2013-06-19 22:31:21 +02:00
|
|
|
prop_area *pa = __system_property_area__;
|
2015-02-11 06:35:56 +01:00
|
|
|
const size_t aligned = BIONIC_ALIGN(size, sizeof(uint_least32_t));
|
2014-02-19 18:59:05 +01:00
|
|
|
if (pa->bytes_used + aligned > pa_data_size) {
|
2013-06-20 20:27:56 +02:00
|
|
|
return NULL;
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2013-06-19 22:31:21 +02:00
|
|
|
*off = pa->bytes_used;
|
2014-02-19 18:59:05 +01:00
|
|
|
pa->bytes_used += aligned;
|
|
|
|
return pa->data + *off;
|
2013-06-20 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
static prop_bt *new_prop_bt(const char *name, uint8_t namelen, uint_least32_t *const off)
|
2013-06-20 20:27:56 +02:00
|
|
|
{
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t new_offset;
|
|
|
|
void *const p = allocate_obj(sizeof(prop_bt) + namelen + 1, &new_offset);
|
|
|
|
if (p != NULL) {
|
|
|
|
prop_bt* bt = new(p) prop_bt(name, namelen);
|
2014-02-19 18:59:05 +01:00
|
|
|
*off = new_offset;
|
|
|
|
return bt;
|
2013-02-13 01:39:31 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
return NULL;
|
2013-02-13 01:39:31 +01:00
|
|
|
}
|
|
|
|
|
2013-06-20 20:27:56 +02:00
|
|
|
static prop_info *new_prop_info(const char *name, uint8_t namelen,
|
2015-02-11 06:35:56 +01:00
|
|
|
const char *value, uint8_t valuelen, uint_least32_t *const off)
|
2009-03-04 04:28:35 +01:00
|
|
|
{
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t new_offset;
|
|
|
|
void* const p = allocate_obj(sizeof(prop_info) + namelen + 1, &new_offset);
|
|
|
|
if (p != NULL) {
|
|
|
|
prop_info* info = new(p) prop_info(name, namelen, value, valuelen);
|
|
|
|
*off = new_offset;
|
2014-02-19 18:59:05 +01:00
|
|
|
return info;
|
2013-06-20 20:27:56 +02:00
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
return NULL;
|
2013-06-20 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
static void *to_prop_obj(uint_least32_t off)
|
2013-06-20 20:27:56 +02:00
|
|
|
{
|
2013-06-25 03:42:21 +02:00
|
|
|
if (off > pa_data_size)
|
2013-06-20 20:27:56 +02:00
|
|
|
return NULL;
|
2013-08-09 17:17:55 +02:00
|
|
|
if (!__system_property_area__)
|
|
|
|
return NULL;
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
return (__system_property_area__->data + off);
|
2009-03-04 04:28:35 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
static inline prop_bt *to_prop_bt(atomic_uint_least32_t* off_p) {
|
|
|
|
uint_least32_t off = atomic_load_explicit(off_p, memory_order_consume);
|
|
|
|
return reinterpret_cast<prop_bt*>(to_prop_obj(off));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline prop_info *to_prop_info(atomic_uint_least32_t* off_p) {
|
|
|
|
uint_least32_t off = atomic_load_explicit(off_p, memory_order_consume);
|
|
|
|
return reinterpret_cast<prop_info*>(to_prop_obj(off));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline prop_bt *root_node()
|
2009-03-04 04:28:35 +01:00
|
|
|
{
|
2014-02-19 18:59:05 +01:00
|
|
|
return reinterpret_cast<prop_bt*>(to_prop_obj(0));
|
2013-06-20 20:27:56 +02:00
|
|
|
}
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2013-06-20 20:27:56 +02:00
|
|
|
static int cmp_prop_name(const char *one, uint8_t one_len, const char *two,
|
|
|
|
uint8_t two_len)
|
|
|
|
{
|
|
|
|
if (one_len < two_len)
|
|
|
|
return -1;
|
|
|
|
else if (one_len > two_len)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return strncmp(one, two, one_len);
|
|
|
|
}
|
2013-01-24 08:07:06 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
static prop_bt *find_prop_bt(prop_bt *const bt, const char *name,
|
|
|
|
uint8_t namelen, bool alloc_if_needed)
|
2013-06-20 20:27:56 +02:00
|
|
|
{
|
2014-02-19 18:59:05 +01:00
|
|
|
|
|
|
|
prop_bt* current = bt;
|
2013-06-20 20:27:56 +02:00
|
|
|
while (true) {
|
2014-02-19 18:59:05 +01:00
|
|
|
if (!current) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
const int ret = cmp_prop_name(name, namelen, current->name, current->namelen);
|
2013-06-20 20:27:56 +02:00
|
|
|
if (ret == 0) {
|
2014-02-19 18:59:05 +01:00
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t left_offset = atomic_load_explicit(¤t->left, memory_order_relaxed);
|
|
|
|
if (left_offset != 0) {
|
|
|
|
current = to_prop_bt(¤t->left);
|
2013-06-20 20:27:56 +02:00
|
|
|
} else {
|
2014-02-19 18:59:05 +01:00
|
|
|
if (!alloc_if_needed) {
|
2013-06-20 20:27:56 +02:00
|
|
|
return NULL;
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t new_offset;
|
2014-02-19 18:59:05 +01:00
|
|
|
prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
|
|
|
|
if (new_bt) {
|
2015-02-11 06:35:56 +01:00
|
|
|
atomic_store_explicit(¤t->left, new_offset, memory_order_release);
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
|
|
|
return new_bt;
|
2013-06-20 20:27:56 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t right_offset = atomic_load_explicit(¤t->right, memory_order_relaxed);
|
|
|
|
if (right_offset != 0) {
|
|
|
|
current = to_prop_bt(¤t->right);
|
2013-06-20 20:27:56 +02:00
|
|
|
} else {
|
2014-02-19 18:59:05 +01:00
|
|
|
if (!alloc_if_needed) {
|
2013-06-20 20:27:56 +02:00
|
|
|
return NULL;
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t new_offset;
|
2014-02-19 18:59:05 +01:00
|
|
|
prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
|
|
|
|
if (new_bt) {
|
2015-02-11 06:35:56 +01:00
|
|
|
atomic_store_explicit(¤t->right, new_offset, memory_order_release);
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
|
|
|
return new_bt;
|
2013-06-20 20:27:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
static const prop_info *find_property(prop_bt *const trie, const char *name,
|
2013-06-20 20:27:56 +02:00
|
|
|
uint8_t namelen, const char *value, uint8_t valuelen,
|
|
|
|
bool alloc_if_needed)
|
|
|
|
{
|
2013-08-09 17:17:55 +02:00
|
|
|
if (!trie) return NULL;
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
const char *remaining_name = name;
|
|
|
|
prop_bt* current = trie;
|
2013-06-20 20:27:56 +02:00
|
|
|
while (true) {
|
2014-02-19 18:59:05 +01:00
|
|
|
const char *sep = strchr(remaining_name, '.');
|
|
|
|
const bool want_subtree = (sep != NULL);
|
|
|
|
const uint8_t substr_size = (want_subtree) ?
|
|
|
|
sep - remaining_name : strlen(remaining_name);
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
if (!substr_size) {
|
2013-06-20 20:27:56 +02:00
|
|
|
return NULL;
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
prop_bt* root = NULL;
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t children_offset = atomic_load_explicit(¤t->children, memory_order_relaxed);
|
|
|
|
if (children_offset != 0) {
|
|
|
|
root = to_prop_bt(¤t->children);
|
2013-06-20 20:27:56 +02:00
|
|
|
} else if (alloc_if_needed) {
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t new_offset;
|
|
|
|
root = new_prop_bt(remaining_name, substr_size, &new_offset);
|
2014-02-19 18:59:05 +01:00
|
|
|
if (root) {
|
2015-02-11 06:35:56 +01:00
|
|
|
atomic_store_explicit(¤t->children, new_offset, memory_order_release);
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
}
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
if (!root) {
|
2013-06-20 20:27:56 +02:00
|
|
|
return NULL;
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
current = find_prop_bt(root, remaining_name, substr_size, alloc_if_needed);
|
|
|
|
if (!current) {
|
2013-06-20 20:27:56 +02:00
|
|
|
return NULL;
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
2013-06-20 20:27:56 +02:00
|
|
|
|
|
|
|
if (!want_subtree)
|
|
|
|
break;
|
|
|
|
|
|
|
|
remaining_name = sep + 1;
|
2009-03-04 04:28:35 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t prop_offset = atomic_load_explicit(¤t->prop, memory_order_relaxed);
|
|
|
|
if (prop_offset != 0) {
|
|
|
|
return to_prop_info(¤t->prop);
|
2013-06-20 20:27:56 +02:00
|
|
|
} else if (alloc_if_needed) {
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t new_offset;
|
|
|
|
prop_info* new_info = new_prop_info(name, namelen, value, valuelen, &new_offset);
|
2014-02-19 18:59:05 +01:00
|
|
|
if (new_info) {
|
2015-02-11 06:35:56 +01:00
|
|
|
atomic_store_explicit(¤t->prop, new_offset, memory_order_release);
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new_info;
|
2013-06-20 20:27:56 +02:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
static int send_prop_msg(const prop_msg *msg)
|
|
|
|
{
|
2014-09-23 02:43:09 +02:00
|
|
|
const int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
|
|
|
if (fd == -1) {
|
2014-02-19 18:59:05 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t namelen = strlen(property_service_socket);
|
|
|
|
|
|
|
|
sockaddr_un addr;
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
strlcpy(addr.sun_path, property_service_socket, sizeof(addr.sun_path));
|
|
|
|
addr.sun_family = AF_LOCAL;
|
|
|
|
socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
|
|
|
|
if (TEMP_FAILURE_RETRY(connect(fd, reinterpret_cast<sockaddr*>(&addr), alen)) < 0) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int num_bytes = TEMP_FAILURE_RETRY(send(fd, msg, sizeof(prop_msg), 0));
|
|
|
|
|
|
|
|
int result = -1;
|
|
|
|
if (num_bytes == sizeof(prop_msg)) {
|
|
|
|
// We successfully wrote to the property server but now we
|
|
|
|
// wait for the property server to finish its work. It
|
|
|
|
// acknowledges its completion by closing the socket so we
|
|
|
|
// poll here (on nothing), waiting for the socket to close.
|
|
|
|
// If you 'adb shell setprop foo bar' you'll see the POLLHUP
|
|
|
|
// once the socket closes. Out of paranoia we cap our poll
|
|
|
|
// at 250 ms.
|
|
|
|
pollfd pollfds[1];
|
|
|
|
pollfds[0].fd = fd;
|
|
|
|
pollfds[0].events = 0;
|
|
|
|
const int poll_result = TEMP_FAILURE_RETRY(poll(pollfds, 1, 250 /* ms */));
|
|
|
|
if (poll_result == 1 && (pollfds[0].revents & POLLHUP) != 0) {
|
|
|
|
result = 0;
|
|
|
|
} else {
|
|
|
|
// Ignore the timeout and treat it like a success anyway.
|
|
|
|
// The init process is single-threaded and its property
|
|
|
|
// service is sometimes slow to respond (perhaps it's off
|
|
|
|
// starting a child process or something) and thus this
|
|
|
|
// times out and the caller thinks it failed, even though
|
|
|
|
// it's still getting around to it. So we fake it here,
|
|
|
|
// mostly for ctl.* properties, but we do try and wait 250
|
|
|
|
// ms so callers who do read-after-write can reliably see
|
|
|
|
// what they've written. Most of the time.
|
|
|
|
// TODO: fix the system properties design.
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void find_nth_fn(const prop_info *pi, void *ptr)
|
|
|
|
{
|
|
|
|
find_nth_cookie *cookie = reinterpret_cast<find_nth_cookie*>(ptr);
|
|
|
|
|
|
|
|
if (cookie->n == cookie->count)
|
|
|
|
cookie->pi = pi;
|
|
|
|
|
|
|
|
cookie->count++;
|
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
static int foreach_property(prop_bt *const trie,
|
2014-02-19 18:59:05 +01:00
|
|
|
void (*propfn)(const prop_info *pi, void *cookie), void *cookie)
|
|
|
|
{
|
|
|
|
if (!trie)
|
|
|
|
return -1;
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t left_offset = atomic_load_explicit(&trie->left, memory_order_relaxed);
|
|
|
|
if (left_offset != 0) {
|
|
|
|
const int err = foreach_property(to_prop_bt(&trie->left), propfn, cookie);
|
2014-02-19 18:59:05 +01:00
|
|
|
if (err < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t prop_offset = atomic_load_explicit(&trie->prop, memory_order_relaxed);
|
|
|
|
if (prop_offset != 0) {
|
|
|
|
prop_info *info = to_prop_info(&trie->prop);
|
2014-02-19 18:59:05 +01:00
|
|
|
if (!info)
|
|
|
|
return -1;
|
|
|
|
propfn(info, cookie);
|
|
|
|
}
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t children_offset = atomic_load_explicit(&trie->children, memory_order_relaxed);
|
|
|
|
if (children_offset != 0) {
|
|
|
|
const int err = foreach_property(to_prop_bt(&trie->children), propfn, cookie);
|
2014-02-19 18:59:05 +01:00
|
|
|
if (err < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-11 06:35:56 +01:00
|
|
|
uint_least32_t right_offset = atomic_load_explicit(&trie->right, memory_order_relaxed);
|
|
|
|
if (right_offset != 0) {
|
|
|
|
const int err = foreach_property(to_prop_bt(&trie->right), propfn, cookie);
|
2014-02-19 18:59:05 +01:00
|
|
|
if (err < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __system_properties_init()
|
|
|
|
{
|
|
|
|
return map_prop_area();
|
|
|
|
}
|
|
|
|
|
|
|
|
int __system_property_set_filename(const char *filename)
|
|
|
|
{
|
|
|
|
size_t len = strlen(filename);
|
|
|
|
if (len >= sizeof(property_filename))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
strcpy(property_filename, filename);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __system_property_area_init()
|
|
|
|
{
|
|
|
|
return map_prop_area_rw();
|
|
|
|
}
|
|
|
|
|
2015-04-24 18:31:32 +02:00
|
|
|
unsigned int __system_property_area_serial()
|
|
|
|
{
|
|
|
|
prop_area *pa = __system_property_area__;
|
|
|
|
if (!pa) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
// Make sure this read fulfilled before __system_property_serial
|
|
|
|
return atomic_load_explicit(&(pa->serial), memory_order_acquire);
|
|
|
|
}
|
|
|
|
|
2013-06-20 20:27:56 +02:00
|
|
|
const prop_info *__system_property_find(const char *name)
|
|
|
|
{
|
2013-06-25 03:36:39 +02:00
|
|
|
if (__predict_false(compat_mode)) {
|
|
|
|
return __system_property_find_compat(name);
|
|
|
|
}
|
2013-06-20 20:27:56 +02:00
|
|
|
return find_property(root_node(), name, strlen(name), NULL, 0, false);
|
2009-03-04 04:28:35 +01:00
|
|
|
}
|
|
|
|
|
2014-08-19 23:07:55 +02:00
|
|
|
// The C11 standard doesn't allow atomic loads from const fields,
|
|
|
|
// though C++11 does. Fudge it until standards get straightened out.
|
|
|
|
static inline uint_least32_t load_const_atomic(const atomic_uint_least32_t* s,
|
|
|
|
memory_order mo) {
|
|
|
|
atomic_uint_least32_t* non_const_s = const_cast<atomic_uint_least32_t*>(s);
|
|
|
|
return atomic_load_explicit(non_const_s, mo);
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
int __system_property_read(const prop_info *pi, char *name, char *value)
|
|
|
|
{
|
2013-06-25 03:36:39 +02:00
|
|
|
if (__predict_false(compat_mode)) {
|
|
|
|
return __system_property_read_compat(pi, name, value);
|
|
|
|
}
|
|
|
|
|
2014-03-13 10:39:58 +01:00
|
|
|
while (true) {
|
2014-08-01 00:53:22 +02:00
|
|
|
uint32_t serial = __system_property_serial(pi); // acquire semantics
|
2014-03-13 10:39:58 +01:00
|
|
|
size_t len = SERIAL_VALUE_LEN(serial);
|
2009-03-04 04:28:35 +01:00
|
|
|
memcpy(value, pi->value, len + 1);
|
2014-08-01 00:53:22 +02:00
|
|
|
// TODO: Fix the synchronization scheme here.
|
|
|
|
// There is no fully supported way to implement this kind
|
|
|
|
// of synchronization in C++11, since the memcpy races with
|
|
|
|
// updates to pi, and the data being accessed is not atomic.
|
|
|
|
// The following fence is unintuitive, but would be the
|
|
|
|
// correct one if memcpy used memory_order_relaxed atomic accesses.
|
|
|
|
// In practice it seems unlikely that the generated code would
|
|
|
|
// would be any different, so this should be OK.
|
|
|
|
atomic_thread_fence(memory_order_acquire);
|
|
|
|
if (serial ==
|
2014-08-19 23:07:55 +02:00
|
|
|
load_const_atomic(&(pi->serial), memory_order_relaxed)) {
|
2014-03-13 10:39:58 +01:00
|
|
|
if (name != 0) {
|
2009-03-04 04:28:35 +01:00
|
|
|
strcpy(name, pi->name);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int __system_property_get(const char *name, char *value)
|
|
|
|
{
|
|
|
|
const prop_info *pi = __system_property_find(name);
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
if (pi != 0) {
|
2009-03-04 04:28:35 +01:00
|
|
|
return __system_property_read(pi, 0, value);
|
|
|
|
} else {
|
|
|
|
value[0] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-15 03:02:26 +01:00
|
|
|
int __system_property_set(const char *key, const char *value)
|
|
|
|
{
|
2014-02-19 18:59:05 +01:00
|
|
|
if (key == 0) return -1;
|
|
|
|
if (value == 0) value = "";
|
|
|
|
if (strlen(key) >= PROP_NAME_MAX) return -1;
|
|
|
|
if (strlen(value) >= PROP_VALUE_MAX) return -1;
|
2011-03-15 03:02:26 +01:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
prop_msg msg;
|
2011-03-15 03:02:26 +01:00
|
|
|
memset(&msg, 0, sizeof msg);
|
|
|
|
msg.cmd = PROP_MSG_SETPROP;
|
|
|
|
strlcpy(msg.name, key, sizeof msg.name);
|
|
|
|
strlcpy(msg.value, value, sizeof msg.value);
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
const int err = send_prop_msg(&msg);
|
|
|
|
if (err < 0) {
|
2011-03-15 03:02:26 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-24 08:07:06 +01:00
|
|
|
int __system_property_update(prop_info *pi, const char *value, unsigned int len)
|
|
|
|
{
|
2013-06-19 22:31:21 +02:00
|
|
|
prop_area *pa = __system_property_area__;
|
2013-01-24 08:07:06 +01:00
|
|
|
|
|
|
|
if (len >= PROP_VALUE_MAX)
|
|
|
|
return -1;
|
|
|
|
|
2014-08-01 00:53:22 +02:00
|
|
|
uint32_t serial = atomic_load_explicit(&pi->serial, memory_order_relaxed);
|
|
|
|
serial |= 1;
|
|
|
|
atomic_store_explicit(&pi->serial, serial, memory_order_relaxed);
|
|
|
|
// The memcpy call here also races. Again pretend it
|
|
|
|
// used memory_order_relaxed atomics, and use the analogous
|
|
|
|
// counterintuitive fence.
|
|
|
|
atomic_thread_fence(memory_order_release);
|
2013-01-24 08:07:06 +01:00
|
|
|
memcpy(pi->value, value, len + 1);
|
2014-08-01 00:53:22 +02:00
|
|
|
atomic_store_explicit(
|
|
|
|
&pi->serial,
|
|
|
|
(len << 24) | ((serial + 1) & 0xffffff),
|
|
|
|
memory_order_release);
|
2013-01-24 08:07:06 +01:00
|
|
|
__futex_wake(&pi->serial, INT32_MAX);
|
|
|
|
|
2014-08-01 00:53:22 +02:00
|
|
|
atomic_store_explicit(
|
|
|
|
&pa->serial,
|
|
|
|
atomic_load_explicit(&pa->serial, memory_order_relaxed) + 1,
|
|
|
|
memory_order_release);
|
2013-01-24 08:07:06 +01:00
|
|
|
__futex_wake(&pa->serial, INT32_MAX);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-03-13 10:39:58 +01:00
|
|
|
|
2013-01-24 08:07:06 +01:00
|
|
|
int __system_property_add(const char *name, unsigned int namelen,
|
|
|
|
const char *value, unsigned int valuelen)
|
|
|
|
{
|
2013-06-19 22:31:21 +02:00
|
|
|
prop_area *pa = __system_property_area__;
|
2013-06-20 20:27:56 +02:00
|
|
|
const prop_info *pi;
|
2013-01-24 08:07:06 +01:00
|
|
|
|
|
|
|
if (namelen >= PROP_NAME_MAX)
|
|
|
|
return -1;
|
|
|
|
if (valuelen >= PROP_VALUE_MAX)
|
|
|
|
return -1;
|
|
|
|
if (namelen < 1)
|
|
|
|
return -1;
|
|
|
|
|
2013-06-20 20:27:56 +02:00
|
|
|
pi = find_property(root_node(), name, namelen, value, valuelen, true);
|
|
|
|
if (!pi)
|
2013-02-13 23:41:48 +01:00
|
|
|
return -1;
|
|
|
|
|
2014-08-01 00:53:22 +02:00
|
|
|
// There is only a single mutator, but we want to make sure that
|
|
|
|
// updates are visible to a reader waiting for the update.
|
|
|
|
atomic_store_explicit(
|
|
|
|
&pa->serial,
|
|
|
|
atomic_load_explicit(&pa->serial, memory_order_relaxed) + 1,
|
|
|
|
memory_order_release);
|
2013-01-24 08:07:06 +01:00
|
|
|
__futex_wake(&pa->serial, INT32_MAX);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-01 00:53:22 +02:00
|
|
|
// Wait for non-locked serial, and retrieve it with acquire semantics.
|
2013-01-24 08:07:06 +01:00
|
|
|
unsigned int __system_property_serial(const prop_info *pi)
|
|
|
|
{
|
2014-08-19 23:07:55 +02:00
|
|
|
uint32_t serial = load_const_atomic(&pi->serial, memory_order_acquire);
|
2014-03-13 10:39:58 +01:00
|
|
|
while (SERIAL_DIRTY(serial)) {
|
2014-08-01 00:53:22 +02:00
|
|
|
__futex_wait(const_cast<volatile void *>(
|
|
|
|
reinterpret_cast<const void *>(&pi->serial)),
|
|
|
|
serial, NULL);
|
2014-08-19 23:07:55 +02:00
|
|
|
serial = load_const_atomic(&pi->serial, memory_order_acquire);
|
2014-03-13 10:39:58 +01:00
|
|
|
}
|
|
|
|
return serial;
|
2013-01-24 08:07:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int __system_property_wait_any(unsigned int serial)
|
|
|
|
{
|
2013-06-19 22:31:21 +02:00
|
|
|
prop_area *pa = __system_property_area__;
|
2014-08-01 00:53:22 +02:00
|
|
|
uint32_t my_serial;
|
2013-01-24 08:07:06 +01:00
|
|
|
|
|
|
|
do {
|
2013-12-21 01:58:06 +01:00
|
|
|
__futex_wait(&pa->serial, serial, NULL);
|
2014-08-01 00:53:22 +02:00
|
|
|
my_serial = atomic_load_explicit(&pa->serial, memory_order_acquire);
|
|
|
|
} while (my_serial == serial);
|
2013-01-24 08:07:06 +01:00
|
|
|
|
2014-08-01 00:53:22 +02:00
|
|
|
return my_serial;
|
2013-01-24 08:07:06 +01:00
|
|
|
}
|
2013-06-20 20:27:56 +02:00
|
|
|
|
|
|
|
const prop_info *__system_property_find_nth(unsigned n)
|
|
|
|
{
|
2014-02-19 18:59:05 +01:00
|
|
|
find_nth_cookie cookie(n);
|
2013-06-20 20:27:56 +02:00
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
const int err = __system_property_foreach(find_nth_fn, &cookie);
|
|
|
|
if (err < 0) {
|
2013-06-20 20:27:56 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-19 18:59:05 +01:00
|
|
|
return cookie.pi;
|
2013-06-20 20:27:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie),
|
|
|
|
void *cookie)
|
|
|
|
{
|
2013-06-25 03:36:39 +02:00
|
|
|
if (__predict_false(compat_mode)) {
|
|
|
|
return __system_property_foreach_compat(propfn, cookie);
|
2014-02-19 18:59:05 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 06:35:56 +01:00
|
|
|
return foreach_property(root_node(), propfn, cookie);
|
2013-06-20 20:27:56 +02:00
|
|
|
}
|