Commit f4c93b22 authored by topjohnwu's avatar topjohnwu

Update resetprop for Android O support

Updated to upstream https://android.googlesource.com/platform/bionic.git
parent c079c598
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ERRNO_RESTORER_H
#define ERRNO_RESTORER_H
#include <errno.h>
#include "bionic_macros.h"
class ErrnoRestorer {
public:
explicit ErrnoRestorer() : saved_errno_(errno) {
}
~ErrnoRestorer() {
errno = saved_errno_;
}
void override(int new_errno) {
saved_errno_ = new_errno;
}
private:
int saved_errno_;
DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer);
};
#endif // ERRNO_RESTORER_H
This diff is collapsed.
...@@ -29,61 +29,34 @@ ...@@ -29,61 +29,34 @@
#ifndef _INCLUDE_SYS__SYSTEM_PROPERTIES_H #ifndef _INCLUDE_SYS__SYSTEM_PROPERTIES_H
#define _INCLUDE_SYS__SYSTEM_PROPERTIES_H #define _INCLUDE_SYS__SYSTEM_PROPERTIES_H
#include <sys/cdefs.h>
#include <stdint.h>
#ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#error you should #include <sys/system_properties.h> instead #error you should #include <sys/system_properties.h> instead
#else #endif
#include <sys/system_properties.h>
typedef struct prop_msg prop_msg; // #include <sys/system_properties.h>
#include "system_properties.h"
#define PROP_AREA_MAGIC 0x504f5250 __BEGIN_DECLS
#define PROP_AREA_VERSION 0xfc6ed0ab
#define PROP_AREA_VERSION_COMPAT 0x45434f76
#define PROP_SERVICE_NAME "property_service" #define PROP_SERVICE_NAME "property_service"
#define PROP_FILENAME_MAX 1024
#define PROP_FILENAME "/dev/__properties__" #define PROP_FILENAME "/dev/__properties__"
#define PA_SIZE (128 * 1024)
#define SERIAL_VALUE_LEN(serial) ((serial) >> 24)
#define SERIAL_DIRTY(serial) ((serial) & 1)
__BEGIN_DECLS
struct prop_msg
{
unsigned cmd;
char name[PROP_NAME_MAX];
char value[PROP_VALUE_MAX];
};
#define PROP_MSG_SETPROP 1 #define PROP_MSG_SETPROP 1
#define PROP_MSG_SETPROP2 0x00020001
/*
** Rules: #define PROP_SUCCESS 0
** #define PROP_ERROR_READ_CMD 0x0004
** - there is only one writer, but many readers #define PROP_ERROR_READ_DATA 0x0008
** - prop_area.count will never decrease in value #define PROP_ERROR_READ_ONLY_PROPERTY 0x000B
** - once allocated, a prop_info's name will not change #define PROP_ERROR_INVALID_NAME 0x0010
** - once allocated, a prop_info's offset will not change #define PROP_ERROR_INVALID_VALUE 0x0014
** - reading a value requires the following steps #define PROP_ERROR_PERMISSION_DENIED 0x0018
** 1. serial = pi->serial #define PROP_ERROR_INVALID_CMD 0x001B
** 2. if SERIAL_DIRTY(serial), wait*, then goto 1 #define PROP_ERROR_HANDLE_CONTROL_MESSAGE 0x0020
** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1) #define PROP_ERROR_SET_FAILED 0x0024
** 4. if pi->serial != serial, goto 2
**
** - writing a value requires the following steps
** 1. pi->serial = pi->serial | 1
** 2. memcpy(pi->value, local_value, value_len)
** 3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff)
*/
#define PROP_PATH_RAMDISK_DEFAULT "/default.prop"
#define PROP_PATH_SYSTEM_BUILD "/system/build.prop"
#define PROP_PATH_VENDOR_BUILD "/vendor/build.prop"
#define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop"
#define PROP_PATH_FACTORY "/factory/factory.prop"
/* /*
** Map the property area from the specified filename. This ** Map the property area from the specified filename. This
...@@ -120,7 +93,7 @@ int __system_property_area_init(); ...@@ -120,7 +93,7 @@ int __system_property_area_init();
** **
** Returns the serial number on success, -1 on error. ** Returns the serial number on success, -1 on error.
*/ */
unsigned int __system_property_area_serial(); uint32_t __system_property_area_serial();
/* Add a new system property. Can only be done by a single /* Add a new system property. Can only be done by a single
** process that has write access to the property area, and ** process that has write access to the property area, and
...@@ -130,9 +103,12 @@ unsigned int __system_property_area_serial(); ...@@ -130,9 +103,12 @@ unsigned int __system_property_area_serial();
** **
** Returns 0 on success, -1 if the property area is full. ** Returns 0 on success, -1 if the property area is full.
*/ */
int __system_property_add(const char *name, unsigned int namelen, int __system_property_add(const char *name, unsigned int namelen, const char *value, unsigned int valuelen);
const char *value, unsigned int valuelen);
/* Delete a new system property. Added in resetprop
**
** Returns 0 on success, -1 if the property area is full.
*/
int __system_property_del(const char *name); int __system_property_del(const char *name);
/* Update the value of a system property returned by /* Update the value of a system property returned by
...@@ -150,21 +126,7 @@ int __system_property_update(prop_info *pi, const char *value, unsigned int len) ...@@ -150,21 +126,7 @@ int __system_property_update(prop_info *pi, const char *value, unsigned int len)
** **
** Returns the serial number on success, -1 on error. ** Returns the serial number on success, -1 on error.
*/ */
unsigned int __system_property_serial(const prop_info *pi); uint32_t __system_property_serial(const prop_info* pi);
/* Wait for any system property to be updated. Caller must pass
** in 0 the first time, and the previous return value on each
** successive call. */
unsigned int __system_property_wait_any(unsigned int serial);
/* Compatibility functions to support using an old init with a new libc,
** mostly for the OTA updater binary. These can be deleted once OTAs from
** a pre-K release no longer needed to be supported. */
// const prop_info *__system_property_find_compat(const char *name);
// int __system_property_read_compat(const prop_info *pi, char *name, char *value);
// int __system_property_foreach_compat(
// void (*propfn)(const prop_info *pi, void *cookie),
// void *cookie);
/* Initialize the system properties area in read only mode. /* Initialize the system properties area in read only mode.
* Should be done by all processes that need to read system * Should be done by all processes that need to read system
...@@ -174,7 +136,9 @@ unsigned int __system_property_wait_any(unsigned int serial); ...@@ -174,7 +136,9 @@ unsigned int __system_property_wait_any(unsigned int serial);
*/ */
int __system_properties_init(); int __system_properties_init();
/* Deprecated: use __system_property_wait instead. */
uint32_t __system_property_wait_any(uint32_t old_serial);
__END_DECLS __END_DECLS
#endif #endif
#endif
This diff is collapsed.
/*
* 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.
*/
#ifndef _INCLUDE_SYS_SYSTEM_PROPERTIES_H
#define _INCLUDE_SYS_SYSTEM_PROPERTIES_H
#include <sys/cdefs.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
__BEGIN_DECLS
typedef struct prop_info prop_info;
#define PROP_VALUE_MAX 92
/*
* Sets system property `key` to `value`, creating the system property if it doesn't already exist.
*/
int __system_property_set(const char* key, const char* value) __INTRODUCED_IN(12);
/*
* Returns a `prop_info` corresponding system property `name`, or nullptr if it doesn't exist.
* Use __system_property_read_callback to query the current value.
*
* Property lookup is expensive, so it can be useful to cache the result of this function.
*/
const prop_info* __system_property_find(const char* name);
/*
* Calls `callback` with a consistent trio of name, value, and serial number for property `pi`.
*/
void __system_property_read_callback(const prop_info *pi,
void (*callback)(void* cookie, const char *name, const char *value, uint32_t serial),
void* cookie) __INTRODUCED_IN_FUTURE;
/*
* Passes a `prop_info` for each system property to the provided
* callback. Use __system_property_read_callback() to read the value.
*
* This method is for inspecting and debugging the property system, and not generally useful.
*/
int __system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie)
__INTRODUCED_IN(19);
/*
* Waits for the specific system property identified by `pi` to be updated
* past `old_serial`. Waits no longer than `relative_timeout`, or forever
* if `relaive_timeout` is null.
*
* If `pi` is null, waits for the global serial number instead.
*
* If you don't know the current serial, use 0.
*
* Returns true and updates `*new_serial_ptr` on success, or false if the call
* timed out.
*/
struct timespec;
bool __system_property_wait(const prop_info* pi,
uint32_t old_serial,
uint32_t* new_serial_ptr,
const struct timespec* relative_timeout)
__INTRODUCED_IN_FUTURE;
/* Deprecated. In Android O and above, there's no limit on property name length. */
#define PROP_NAME_MAX 32
/* Deprecated. Use __system_property_read_callback instead. */
int __system_property_read(const prop_info *pi, char *name, char *value);
/* Deprecated. Use __system_property_read_callback instead. */
int __system_property_get(const char *name, char *value);
/* Deprecated. Use __system_property_foreach instead. Aborts in Android O and above. */
const prop_info *__system_property_find_nth(unsigned n) __REMOVED_IN(26);
__END_DECLS
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment