Skip to content

Commit 620eec1

Browse files
committed
Merge <sys/system_properties.h> and <sys/_system_properties.h>.
You could argue that some of this stuff (such as the constants used for communication between init and libc that _aren't_ passed on to callers) should be moved to a new <platform/system_properties.h> instead, but in the sense of "exposed to the NDK" rather than "useful to NDK users", all of this is already technically public API. We can worry about how to make the platform-only implementation details less visible in documentation if/when we ever actually have the bionic docs generated and published on the web... Change-Id: I1a6456cf7d301753ec8f541a2046538cd59ed58a
1 parent 7b2c6d4 commit 620eec1

8 files changed

+132
-187
lines changed

benchmarks/property_benchmark.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ using namespace std::literals;
2828

2929
#if defined(__BIONIC__)
3030

31-
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
32-
#include <sys/_system_properties.h>
31+
#include <sys/system_properties.h>
3332

3433
#include <benchmark/benchmark.h>
3534
#include <system_properties/system_properties.h>

libc/bionic/system_property_api.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
* SUCH DAMAGE.
2727
*/
2828

29-
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
30-
#include <sys/_system_properties.h>
29+
#include <sys/system_properties.h>
3130

3231
#include <async_safe/CHECK.h>
3332
#include <system_properties/prop_area.h>

libc/bionic/system_property_set.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@
3434
#include <stdlib.h>
3535
#include <string.h>
3636
#include <sys/socket.h>
37+
#include <sys/system_properties.h>
3738
#include <sys/types.h>
3839
#include <sys/uio.h>
3940
#include <sys/un.h>
40-
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
41-
#include <sys/_system_properties.h>
4241
#include <unistd.h>
4342

4443
#include <async_safe/log.h>

libc/include/sys/_system_properties.h

-171
Original file line numberDiff line numberDiff line change
@@ -1,172 +1 @@
1-
/*
2-
* Copyright (C) 2008 The Android Open Source Project
3-
* All rights reserved.
4-
*
5-
* Redistribution and use in source and binary forms, with or without
6-
* modification, are permitted provided that the following conditions
7-
* are met:
8-
* * Redistributions of source code must retain the above copyright
9-
* notice, this list of conditions and the following disclaimer.
10-
* * Redistributions in binary form must reproduce the above copyright
11-
* notice, this list of conditions and the following disclaimer in
12-
* the documentation and/or other materials provided with the
13-
* distribution.
14-
*
15-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16-
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17-
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18-
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19-
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20-
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21-
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22-
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23-
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25-
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26-
* SUCH DAMAGE.
27-
*/
28-
29-
#pragma once
30-
31-
#include <sys/cdefs.h>
32-
#include <stdint.h>
33-
34-
#ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
35-
#error you should #include <sys/system_properties.h> instead
36-
#endif
37-
381
#include <sys/system_properties.h>
39-
40-
__BEGIN_DECLS
41-
42-
/**
43-
* Reads the global serial number of the system properties _area_.
44-
*
45-
* Called to predict if a series of cached __system_property_find()
46-
* objects will have seen __system_property_serial() values change.
47-
* Also aids the converse, as changes in the global serial can
48-
* also be used to predict if a failed __system_property_find()
49-
* could in turn now find a new object; thus preventing the
50-
* cycles of effort to poll __system_property_find().
51-
*
52-
* Typically called at beginning of a cache cycle to signal if _any_ possible
53-
* changes have occurred since last. If there is, one may check each individual
54-
* __system_property_serial() to confirm dirty, or __system_property_find()
55-
* to check if the property now exists. If a call to __system_property_add()
56-
* or __system_property_update() has completed between two calls to
57-
* __system_property_area_serial() then the second call will return a larger
58-
* value than the first call. Beware of race conditions as changes to the
59-
* properties are not atomic, the main value of this call is to determine
60-
* whether the expensive __system_property_find() is worth retrying to see if
61-
* a property now exists.
62-
*
63-
* Returns the serial number on success, -1 on error.
64-
*/
65-
uint32_t __system_property_area_serial(void);
66-
67-
/**
68-
* Reads the serial number of a specific system property previously returned by
69-
* __system_property_find(). This is a cheap way to check whether a system
70-
* property has changed or not.
71-
*
72-
* Returns the serial number on success, -1 on error.
73-
*/
74-
uint32_t __system_property_serial(const prop_info* _Nonnull __pi);
75-
76-
//
77-
// libc implementation detail.
78-
//
79-
80-
/**
81-
* Initializes the system properties area in read-only mode.
82-
*
83-
* This is called automatically during libc initialization,
84-
* so user code should never need to call this.
85-
*
86-
* Returns 0 on success, -1 otherwise.
87-
*/
88-
int __system_properties_init(void);
89-
90-
//
91-
// init implementation details.
92-
//
93-
94-
#define PROP_SERVICE_NAME "property_service"
95-
#define PROP_SERVICE_FOR_SYSTEM_NAME "property_service_for_system"
96-
#define PROP_DIRNAME "/dev/__properties__"
97-
98-
// Messages sent to init.
99-
#define PROP_MSG_SETPROP 1
100-
#define PROP_MSG_SETPROP2 0x00020001
101-
102-
// Status codes returned by init (but not passed from libc to the caller).
103-
#define PROP_SUCCESS 0
104-
#define PROP_ERROR_READ_CMD 0x0004
105-
#define PROP_ERROR_READ_DATA 0x0008
106-
#define PROP_ERROR_READ_ONLY_PROPERTY 0x000B
107-
#define PROP_ERROR_INVALID_NAME 0x0010
108-
#define PROP_ERROR_INVALID_VALUE 0x0014
109-
#define PROP_ERROR_PERMISSION_DENIED 0x0018
110-
#define PROP_ERROR_INVALID_CMD 0x001B
111-
#define PROP_ERROR_HANDLE_CONTROL_MESSAGE 0x0020
112-
#define PROP_ERROR_SET_FAILED 0x0024
113-
114-
/**
115-
* Initializes the area to be used to store properties.
116-
*
117-
* Can only be done by the process that has write access to the property area,
118-
* typically init.
119-
*
120-
* See __system_properties_init() for the equivalent for all other processes.
121-
*/
122-
int __system_property_area_init(void);
123-
124-
/**
125-
* Adds a new system property.
126-
* Can only be done by the process that has write access to the property area --
127-
* typically init -- which must handle sequencing to ensure that only one property is
128-
* updated at a time.
129-
*
130-
* Returns 0 on success, -1 if the property area is full.
131-
*/
132-
int __system_property_add(const char* _Nonnull __name, unsigned int __name_length, const char* _Nonnull __value, unsigned int __value_length);
133-
134-
/**
135-
* Updates the value of a system property returned by __system_property_find().
136-
* Can only be done by the process that has write access to the property area --
137-
* typically init -- which must handle sequencing to ensure that only one property is
138-
* updated at a time.
139-
*
140-
* Returns 0 on success, -1 if the parameters are incorrect.
141-
*/
142-
int __system_property_update(prop_info* _Nonnull __pi, const char* _Nonnull __value, unsigned int __value_length);
143-
144-
/**
145-
* Reloads the system properties from disk.
146-
* Not intended for use by any apps except the Zygote.
147-
* Should only be called from the main thread.
148-
*
149-
* Pointers received from functions such as __system_property_find()
150-
* may be invalidated by calls to this function.
151-
*
152-
* Returns 0 on success, -1 otherwise.
153-
*
154-
* Available since API level 35.
155-
*/
156-
int __system_properties_zygote_reload(void) __INTRODUCED_IN(35);
157-
158-
//
159-
// Deprecated functions.
160-
//
161-
162-
/** Deprecated: use __system_property_wait instead. */
163-
uint32_t __system_property_wait_any(uint32_t __old_serial);
164-
165-
/**
166-
* Deprecated: previously for testing, but now that SystemProperties is its own
167-
* testable class, there is never a reason to call this function and its
168-
* implementation simply returns -1.
169-
*/
170-
int __system_property_set_filename(const char* __unused __filename);
171-
172-
__END_DECLS

libc/include/sys/system_properties.h

+127-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,136 @@ bool __system_property_wait(const prop_info* _Nullable __pi, uint32_t __old_seri
110110
*/
111111
#define PROP_NAME_MAX 32
112112

113+
/** Deprecated. Use __system_property_foreach() instead. */
114+
const prop_info* _Nullable __system_property_find_nth(unsigned __n);
113115
/** Deprecated. Use __system_property_read_callback() instead. */
114116
int __system_property_read(const prop_info* _Nonnull __pi, char* _Nullable __name, char* _Nonnull __value);
115117
/** Deprecated. Use __system_property_read_callback() instead. */
116118
int __system_property_get(const char* _Nonnull __name, char* _Nonnull __value);
117-
/** Deprecated. Use __system_property_foreach() instead. */
118-
const prop_info* _Nullable __system_property_find_nth(unsigned __n);
119+
/** Deprecated: use __system_property_wait() instead. */
120+
uint32_t __system_property_wait_any(uint32_t __old_serial);
121+
122+
/**
123+
* Reads the global serial number of the system properties _area_.
124+
*
125+
* Called to predict if a series of cached __system_property_find()
126+
* objects will have seen __system_property_serial() values change.
127+
* Also aids the converse, as changes in the global serial can
128+
* also be used to predict if a failed __system_property_find()
129+
* could in turn now find a new object; thus preventing the
130+
* cycles of effort to poll __system_property_find().
131+
*
132+
* Typically called at beginning of a cache cycle to signal if _any_ possible
133+
* changes have occurred since last. If there is, one may check each individual
134+
* __system_property_serial() to confirm dirty, or __system_property_find()
135+
* to check if the property now exists. If a call to __system_property_add()
136+
* or __system_property_update() has completed between two calls to
137+
* __system_property_area_serial() then the second call will return a larger
138+
* value than the first call. Beware of race conditions as changes to the
139+
* properties are not atomic, the main value of this call is to determine
140+
* whether the expensive __system_property_find() is worth retrying to see if
141+
* a property now exists.
142+
*
143+
* Returns the serial number on success, -1 on error.
144+
*/
145+
uint32_t __system_property_area_serial(void);
146+
147+
/**
148+
* Reads the serial number of a specific system property previously returned by
149+
* __system_property_find(). This is a cheap way to check whether a system
150+
* property has changed or not.
151+
*
152+
* Returns the serial number on success, -1 on error.
153+
*/
154+
uint32_t __system_property_serial(const prop_info* _Nonnull __pi);
155+
156+
//
157+
// libc implementation detail.
158+
//
159+
160+
/**
161+
* Initializes the system properties area in read-only mode.
162+
*
163+
* This is called automatically during libc initialization,
164+
* so user code should never need to call this.
165+
*
166+
* Returns 0 on success, -1 otherwise.
167+
*/
168+
int __system_properties_init(void);
169+
170+
//
171+
// init implementation details.
172+
//
173+
174+
#define PROP_SERVICE_NAME "property_service"
175+
#define PROP_SERVICE_FOR_SYSTEM_NAME "property_service_for_system"
176+
#define PROP_DIRNAME "/dev/__properties__"
177+
178+
// Messages sent to init.
179+
#define PROP_MSG_SETPROP 1
180+
#define PROP_MSG_SETPROP2 0x00020001
181+
182+
// Status codes returned by init (but not passed from libc to the caller).
183+
#define PROP_SUCCESS 0
184+
#define PROP_ERROR_READ_CMD 0x0004
185+
#define PROP_ERROR_READ_DATA 0x0008
186+
#define PROP_ERROR_READ_ONLY_PROPERTY 0x000B
187+
#define PROP_ERROR_INVALID_NAME 0x0010
188+
#define PROP_ERROR_INVALID_VALUE 0x0014
189+
#define PROP_ERROR_PERMISSION_DENIED 0x0018
190+
#define PROP_ERROR_INVALID_CMD 0x001B
191+
#define PROP_ERROR_HANDLE_CONTROL_MESSAGE 0x0020
192+
#define PROP_ERROR_SET_FAILED 0x0024
193+
194+
/**
195+
* Initializes the area to be used to store properties.
196+
*
197+
* Can only be done by the process that has write access to the property area,
198+
* typically init.
199+
*
200+
* See __system_properties_init() for the equivalent for all other processes.
201+
*/
202+
int __system_property_area_init(void);
203+
204+
/**
205+
* Adds a new system property.
206+
* Can only be done by the process that has write access to the property area --
207+
* typically init -- which must handle sequencing to ensure that only one property is
208+
* updated at a time.
209+
*
210+
* Returns 0 on success, -1 if the property area is full.
211+
*/
212+
int __system_property_add(const char* _Nonnull __name, unsigned int __name_length, const char* _Nonnull __value, unsigned int __value_length);
213+
214+
/**
215+
* Updates the value of a system property returned by __system_property_find().
216+
* Can only be done by the process that has write access to the property area --
217+
* typically init -- which must handle sequencing to ensure that only one property is
218+
* updated at a time.
219+
*
220+
* Returns 0 on success, -1 if the parameters are incorrect.
221+
*/
222+
int __system_property_update(prop_info* _Nonnull __pi, const char* _Nonnull __value, unsigned int __value_length);
223+
224+
/**
225+
* Reloads the system properties from disk.
226+
* Not intended for use by any apps except the Zygote.
227+
* Should only be called from the main thread.
228+
*
229+
* Pointers received from functions such as __system_property_find()
230+
* may be invalidated by calls to this function.
231+
*
232+
* Returns 0 on success, -1 otherwise.
233+
*
234+
* Available since API level 35.
235+
*/
236+
int __system_properties_zygote_reload(void) __INTRODUCED_IN(35);
237+
238+
/**
239+
* Deprecated: previously for testing, but now that SystemProperties is its own
240+
* testable class, there is never a reason to call this function and its
241+
* implementation simply returns -1.
242+
*/
243+
int __system_property_set_filename(const char* _Nullable __unused __filename);
119244

120245
__END_DECLS

libc/private/CachedProperty.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
#pragma once
3030

3131
#include <string.h>
32-
33-
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
34-
#include <sys/_system_properties.h>
32+
#include <sys/system_properties.h>
3533

3634
// Cached system property lookup. For code that needs to read the same property multiple times,
3735
// this class helps optimize those lookups.

linker/linker_config.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
#include <string>
4747
#include <unordered_map>
4848

49-
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
50-
#include <sys/_system_properties.h>
51-
5249
class ConfigParser {
5350
public:
5451
enum {

tests/system_properties_test.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ using namespace std::literals;
3333

3434
#if defined(__BIONIC__)
3535

36-
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
3736
#include <stdlib.h>
38-
#include <sys/_system_properties.h>
3937
#include <sys/mount.h>
38+
#include <sys/system_properties.h>
4039

4140
#include <system_properties/system_properties.h>
4241

0 commit comments

Comments
 (0)