The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame^] | 17 | #include "property_service.h" |
| 18 | |
| 19 | #include <ctype.h> |
| 20 | #include <dirent.h> |
| 21 | #include <errno.h> |
| 22 | #include <fcntl.h> |
Keun-young Park | 7d32026 | 2017-02-17 17:48:56 -0800 | [diff] [blame] | 23 | #include <inttypes.h> |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame^] | 24 | #include <limits.h> |
| 25 | #include <netinet/in.h> |
| 26 | #include <stdarg.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 29 | #include <string.h> |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame^] | 30 | #include <sys/mman.h> |
JP Abgrall | 4515d81 | 2014-01-31 14:37:07 -0800 | [diff] [blame] | 31 | #include <sys/poll.h> |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame^] | 32 | #include <sys/select.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/un.h> |
| 35 | #include <unistd.h> |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 36 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 37 | #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ |
| 38 | #include <sys/_system_properties.h> |
| 39 | |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame^] | 40 | #include <memory> |
| 41 | #include <vector> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 42 | |
Elliott Hughes | 4f71319 | 2015-12-04 22:00:26 -0800 | [diff] [blame] | 43 | #include <android-base/file.h> |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame^] | 44 | #include <android-base/logging.h> |
Keun-young Park | 7d32026 | 2017-02-17 17:48:56 -0800 | [diff] [blame] | 45 | #include <android-base/stringprintf.h> |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 46 | #include <android-base/strings.h> |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame^] | 47 | #include <bootimg.h> |
| 48 | #include <fs_mgr.h> |
| 49 | #include <selinux/android.h> |
| 50 | #include <selinux/label.h> |
| 51 | #include <selinux/selinux.h> |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 52 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 53 | #include "init.h" |
Colin Cross | 3899e9f | 2010-04-13 20:35:46 -0700 | [diff] [blame] | 54 | #include "util.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 55 | |
Keun-young Park | 7d32026 | 2017-02-17 17:48:56 -0800 | [diff] [blame] | 56 | using android::base::StringPrintf; |
| 57 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 58 | #define PERSISTENT_PROPERTY_DIR "/data/property" |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 59 | #define RECOVERY_MOUNT_POINT "/recovery" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 60 | |
| 61 | static int persistent_properties_loaded = 0; |
| 62 | |
Colin Cross | d11beb2 | 2010-04-13 19:33:37 -0700 | [diff] [blame] | 63 | static int property_set_fd = -1; |
| 64 | |
Elliott Hughes | da40c00 | 2015-03-27 23:20:44 -0700 | [diff] [blame] | 65 | void property_init() { |
Elliott Hughes | da40c00 | 2015-03-27 23:20:44 -0700 | [diff] [blame] | 66 | if (__system_property_area_init()) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 67 | LOG(ERROR) << "Failed to initialize property area"; |
Tom Cherry | 6036114 | 2015-12-01 17:16:53 -0800 | [diff] [blame] | 68 | exit(1); |
Elliott Hughes | da40c00 | 2015-03-27 23:20:44 -0700 | [diff] [blame] | 69 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 72 | static bool check_mac_perms(const std::string& name, char* sctx, struct ucred* cr) { |
| 73 | |
| 74 | if (!sctx) { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | if (!sehandle_prop) { |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | char* tctx = nullptr; |
| 83 | if (selabel_lookup(sehandle_prop, &tctx, name.c_str(), 1) != 0) { |
| 84 | return false; |
| 85 | } |
| 86 | |
William Roberts | d7aea44 | 2015-10-01 16:03:47 -0700 | [diff] [blame] | 87 | property_audit_data audit_data; |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 88 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 89 | audit_data.name = name.c_str(); |
William Roberts | d7aea44 | 2015-10-01 16:03:47 -0700 | [diff] [blame] | 90 | audit_data.cr = cr; |
| 91 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 92 | bool has_access = (selinux_check_access(sctx, tctx, "property_service", "set", &audit_data) == 0); |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 93 | |
| 94 | freecon(tctx); |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 95 | return has_access; |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 96 | } |
| 97 | |
William Roberts | d7aea44 | 2015-10-01 16:03:47 -0700 | [diff] [blame] | 98 | static int check_control_mac_perms(const char *name, char *sctx, struct ucred *cr) |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 99 | { |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 100 | /* |
| 101 | * Create a name prefix out of ctl.<service name> |
| 102 | * The new prefix allows the use of the existing |
| 103 | * property service backend labeling while avoiding |
| 104 | * mislabels based on true property prefixes. |
| 105 | */ |
| 106 | char ctl_name[PROP_VALUE_MAX+4]; |
| 107 | int ret = snprintf(ctl_name, sizeof(ctl_name), "ctl.%s", name); |
| 108 | |
| 109 | if (ret < 0 || (size_t) ret >= sizeof(ctl_name)) |
| 110 | return 0; |
| 111 | |
William Roberts | d7aea44 | 2015-10-01 16:03:47 -0700 | [diff] [blame] | 112 | return check_mac_perms(ctl_name, sctx, cr); |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Tammo Spalink | 3dfe6c6 | 2009-08-26 10:13:20 +0800 | [diff] [blame] | 115 | static void write_persistent_property(const char *name, const char *value) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 116 | { |
Nick Kralevich | 7ecfe6a | 2012-10-02 14:59:59 -0700 | [diff] [blame] | 117 | char tempPath[PATH_MAX]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 118 | char path[PATH_MAX]; |
Nick Kralevich | 7ecfe6a | 2012-10-02 14:59:59 -0700 | [diff] [blame] | 119 | int fd; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 120 | |
Nick Kralevich | 7ecfe6a | 2012-10-02 14:59:59 -0700 | [diff] [blame] | 121 | snprintf(tempPath, sizeof(tempPath), "%s/.temp.XXXXXX", PERSISTENT_PROPERTY_DIR); |
| 122 | fd = mkstemp(tempPath); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 123 | if (fd < 0) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 124 | PLOG(ERROR) << "Unable to write persistent property to temp file " << tempPath; |
Tammo Spalink | 3dfe6c6 | 2009-08-26 10:13:20 +0800 | [diff] [blame] | 125 | return; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 126 | } |
| 127 | write(fd, value, strlen(value)); |
OPPO | de73a0c | 2014-03-28 19:12:47 +0800 | [diff] [blame] | 128 | fsync(fd); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 129 | close(fd); |
| 130 | |
Nick Kralevich | 7ecfe6a | 2012-10-02 14:59:59 -0700 | [diff] [blame] | 131 | snprintf(path, sizeof(path), "%s/%s", PERSISTENT_PROPERTY_DIR, name); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 132 | if (rename(tempPath, path)) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 133 | PLOG(ERROR) << "Unable to rename persistent property file " << tempPath << " to " << path; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 134 | unlink(tempPath); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 138 | bool is_legal_property_name(const std::string& name) { |
Iliyan Malchev | f655480 | 2016-09-19 20:58:20 -0700 | [diff] [blame] | 139 | size_t namelen = name.size(); |
| 140 | |
Nick Kralevich | 6946361 | 2013-09-13 17:21:28 -0700 | [diff] [blame] | 141 | if (namelen < 1) return false; |
| 142 | if (name[0] == '.') return false; |
| 143 | if (name[namelen - 1] == '.') return false; |
| 144 | |
Iliyan Malchev | f655480 | 2016-09-19 20:58:20 -0700 | [diff] [blame] | 145 | /* Only allow alphanumeric, plus '.', '-', '@', or '_' */ |
Nick Kralevich | 6946361 | 2013-09-13 17:21:28 -0700 | [diff] [blame] | 146 | /* Don't allow ".." to appear in a property name */ |
Iliyan Malchev | f655480 | 2016-09-19 20:58:20 -0700 | [diff] [blame] | 147 | for (size_t i = 0; i < namelen; i++) { |
Nick Kralevich | 6946361 | 2013-09-13 17:21:28 -0700 | [diff] [blame] | 148 | if (name[i] == '.') { |
Nick Kralevich | c2c5a24 | 2013-09-16 11:30:48 -0700 | [diff] [blame] | 149 | // i=0 is guaranteed to never have a dot. See above. |
| 150 | if (name[i-1] == '.') return false; |
Nick Kralevich | 6946361 | 2013-09-13 17:21:28 -0700 | [diff] [blame] | 151 | continue; |
| 152 | } |
Iliyan Malchev | f655480 | 2016-09-19 20:58:20 -0700 | [diff] [blame] | 153 | if (name[i] == '_' || name[i] == '-' || name[i] == '@') continue; |
Nick Kralevich | 6946361 | 2013-09-13 17:21:28 -0700 | [diff] [blame] | 154 | if (name[i] >= 'a' && name[i] <= 'z') continue; |
| 155 | if (name[i] >= 'A' && name[i] <= 'Z') continue; |
| 156 | if (name[i] >= '0' && name[i] <= '9') continue; |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | return true; |
| 161 | } |
| 162 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 163 | uint32_t property_set(const std::string& name, const std::string& value) { |
| 164 | size_t valuelen = value.size(); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 165 | |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 166 | if (!is_legal_property_name(name)) { |
| 167 | LOG(ERROR) << "property_set(\"" << name << "\", \"" << value << "\") failed: bad name"; |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 168 | return PROP_ERROR_INVALID_NAME; |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 169 | } |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 170 | |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 171 | if (valuelen >= PROP_VALUE_MAX) { |
| 172 | LOG(ERROR) << "property_set(\"" << name << "\", \"" << value << "\") failed: " |
| 173 | << "value too long"; |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 174 | return PROP_ERROR_INVALID_VALUE; |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 175 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 176 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 177 | if (name == "selinux.restorecon_recursive" && valuelen > 0) { |
| 178 | if (restorecon(value.c_str(), SELINUX_ANDROID_RESTORECON_RECURSE) != 0) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 179 | LOG(ERROR) << "Failed to restorecon_recursive " << value; |
Jeff Sharkey | 7641751 | 2015-06-09 11:02:55 -0700 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 183 | prop_info* pi = (prop_info*) __system_property_find(name.c_str()); |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 184 | if (pi != nullptr) { |
| 185 | // ro.* properties are actually "write-once". |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 186 | if (android::base::StartsWith(name, "ro.")) { |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 187 | LOG(ERROR) << "property_set(\"" << name << "\", \"" << value << "\") failed: " |
| 188 | << "property already set"; |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 189 | return PROP_ERROR_READ_ONLY_PROPERTY; |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 190 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 191 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 192 | __system_property_update(pi, value.c_str(), valuelen); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 193 | } else { |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 194 | int rc = __system_property_add(name.c_str(), name.size(), value.c_str(), valuelen); |
Elliott Hughes | db3f267 | 2015-03-20 09:45:18 -0700 | [diff] [blame] | 195 | if (rc < 0) { |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 196 | LOG(ERROR) << "property_set(\"" << name << "\", \"" << value << "\") failed: " |
| 197 | << "__system_property_add failed"; |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 198 | return PROP_ERROR_SET_FAILED; |
Johan Redestig | fd7ffb1 | 2013-04-29 09:11:57 +0200 | [diff] [blame] | 199 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 200 | } |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 201 | |
Elliott Hughes | 4f91581 | 2016-12-05 13:12:48 -0800 | [diff] [blame] | 202 | // Don't write properties to disk until after we have read all default |
| 203 | // properties to prevent them from being overwritten by default values. |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 204 | if (persistent_properties_loaded && android::base::StartsWith(name, "persist.")) { |
| 205 | write_persistent_property(name.c_str(), value.c_str()); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 206 | } |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 207 | property_changed(name.c_str(), value.c_str()); |
| 208 | return PROP_SUCCESS; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 211 | class SocketConnection { |
| 212 | public: |
| 213 | SocketConnection(int socket, const struct ucred& cred) |
| 214 | : socket_(socket), cred_(cred) {} |
| 215 | |
| 216 | ~SocketConnection() { |
| 217 | close(socket_); |
| 218 | } |
| 219 | |
| 220 | bool RecvUint32(uint32_t* value, uint32_t* timeout_ms) { |
| 221 | return RecvFully(value, sizeof(*value), timeout_ms); |
| 222 | } |
| 223 | |
| 224 | bool RecvChars(char* chars, size_t size, uint32_t* timeout_ms) { |
| 225 | return RecvFully(chars, size, timeout_ms); |
| 226 | } |
| 227 | |
| 228 | bool RecvString(std::string* value, uint32_t* timeout_ms) { |
| 229 | uint32_t len = 0; |
| 230 | if (!RecvUint32(&len, timeout_ms)) { |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | if (len == 0) { |
| 235 | *value = ""; |
| 236 | return true; |
| 237 | } |
| 238 | |
Elliott Hughes | b005d90 | 2017-02-22 14:54:15 -0800 | [diff] [blame] | 239 | // http://b/35166374: don't allow init to make arbitrarily large allocations. |
| 240 | if (len > 0xffff) { |
| 241 | LOG(ERROR) << "sys_prop: RecvString asked to read huge string: " << len; |
| 242 | errno = ENOMEM; |
| 243 | return false; |
| 244 | } |
| 245 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 246 | std::vector<char> chars(len); |
| 247 | if (!RecvChars(&chars[0], len, timeout_ms)) { |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | *value = std::string(&chars[0], len); |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | bool SendUint32(uint32_t value) { |
| 256 | int result = TEMP_FAILURE_RETRY(send(socket_, &value, sizeof(value), 0)); |
| 257 | return result == sizeof(value); |
| 258 | } |
| 259 | |
| 260 | int socket() { |
| 261 | return socket_; |
| 262 | } |
| 263 | |
| 264 | const struct ucred& cred() { |
| 265 | return cred_; |
| 266 | } |
| 267 | |
| 268 | private: |
| 269 | bool PollIn(uint32_t* timeout_ms) { |
| 270 | struct pollfd ufds[1]; |
| 271 | ufds[0].fd = socket_; |
| 272 | ufds[0].events = POLLIN; |
| 273 | ufds[0].revents = 0; |
| 274 | while (*timeout_ms > 0) { |
| 275 | Timer timer; |
| 276 | int nr = poll(ufds, 1, *timeout_ms); |
James Hawkins | 27c0522 | 2017-01-26 11:55:44 -0800 | [diff] [blame] | 277 | uint64_t millis = timer.duration_ms(); |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 278 | *timeout_ms = (millis > *timeout_ms) ? 0 : *timeout_ms - millis; |
| 279 | |
| 280 | if (nr > 0) { |
| 281 | return true; |
| 282 | } |
| 283 | |
| 284 | if (nr == 0) { |
| 285 | // Timeout |
| 286 | break; |
| 287 | } |
| 288 | |
| 289 | if (nr < 0 && errno != EINTR) { |
| 290 | PLOG(ERROR) << "sys_prop: error waiting for uid " << cred_.uid << " to send property message"; |
| 291 | return false; |
| 292 | } else { // errno == EINTR |
| 293 | // Timer rounds milliseconds down in case of EINTR we want it to be rounded up |
| 294 | // to avoid slowing init down by causing EINTR with under millisecond timeout. |
| 295 | if (*timeout_ms > 0) { |
| 296 | --(*timeout_ms); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | LOG(ERROR) << "sys_prop: timeout waiting for uid " << cred_.uid << " to send property message."; |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | bool RecvFully(void* data_ptr, size_t size, uint32_t* timeout_ms) { |
| 306 | size_t bytes_left = size; |
| 307 | char* data = static_cast<char*>(data_ptr); |
| 308 | while (*timeout_ms > 0 && bytes_left > 0) { |
| 309 | if (!PollIn(timeout_ms)) { |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | int result = TEMP_FAILURE_RETRY(recv(socket_, data, bytes_left, MSG_DONTWAIT)); |
| 314 | if (result <= 0) { |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | bytes_left -= result; |
| 319 | data += result; |
| 320 | } |
| 321 | |
| 322 | return bytes_left == 0; |
| 323 | } |
| 324 | |
| 325 | int socket_; |
| 326 | struct ucred cred_; |
| 327 | |
| 328 | DISALLOW_IMPLICIT_CONSTRUCTORS(SocketConnection); |
| 329 | }; |
| 330 | |
| 331 | static void handle_property_set(SocketConnection& socket, |
| 332 | const std::string& name, |
| 333 | const std::string& value, |
| 334 | bool legacy_protocol) { |
| 335 | const char* cmd_name = legacy_protocol ? "PROP_MSG_SETPROP" : "PROP_MSG_SETPROP2"; |
| 336 | if (!is_legal_property_name(name)) { |
| 337 | LOG(ERROR) << "sys_prop(" << cmd_name << "): illegal property name \"" << name << "\""; |
| 338 | socket.SendUint32(PROP_ERROR_INVALID_NAME); |
| 339 | return; |
| 340 | } |
| 341 | |
| 342 | struct ucred cr = socket.cred(); |
| 343 | char* source_ctx = nullptr; |
| 344 | getpeercon(socket.socket(), &source_ctx); |
| 345 | |
| 346 | if (android::base::StartsWith(name, "ctl.")) { |
| 347 | if (check_control_mac_perms(value.c_str(), source_ctx, &cr)) { |
| 348 | handle_control_message(name.c_str() + 4, value.c_str()); |
| 349 | if (!legacy_protocol) { |
| 350 | socket.SendUint32(PROP_SUCCESS); |
| 351 | } |
| 352 | } else { |
| 353 | LOG(ERROR) << "sys_prop(" << cmd_name << "): Unable to " << (name.c_str() + 4) |
| 354 | << " service ctl [" << value << "]" |
| 355 | << " uid:" << cr.uid |
| 356 | << " gid:" << cr.gid |
| 357 | << " pid:" << cr.pid; |
| 358 | if (!legacy_protocol) { |
| 359 | socket.SendUint32(PROP_ERROR_HANDLE_CONTROL_MESSAGE); |
| 360 | } |
| 361 | } |
| 362 | } else { |
| 363 | if (check_mac_perms(name, source_ctx, &cr)) { |
| 364 | uint32_t result = property_set(name, value); |
| 365 | if (!legacy_protocol) { |
| 366 | socket.SendUint32(result); |
| 367 | } |
| 368 | } else { |
| 369 | LOG(ERROR) << "sys_prop(" << cmd_name << "): permission denied uid:" << cr.uid << " name:" << name; |
| 370 | if (!legacy_protocol) { |
| 371 | socket.SendUint32(PROP_ERROR_PERMISSION_DENIED); |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | freecon(source_ctx); |
| 377 | } |
| 378 | |
| 379 | static void handle_property_set_fd() { |
| 380 | static constexpr uint32_t kDefaultSocketTimeout = 2000; /* ms */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 381 | |
Robert Sesek | ca2da60 | 2017-01-25 08:08:51 -0500 | [diff] [blame] | 382 | int s = accept4(property_set_fd, nullptr, nullptr, SOCK_CLOEXEC); |
Elliott Hughes | 3dcfa3f | 2016-08-23 12:50:00 -0700 | [diff] [blame] | 383 | if (s == -1) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 384 | return; |
| 385 | } |
| 386 | |
Elliott Hughes | 3dcfa3f | 2016-08-23 12:50:00 -0700 | [diff] [blame] | 387 | struct ucred cr; |
| 388 | socklen_t cr_size = sizeof(cr); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 389 | if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &cr_size) < 0) { |
| 390 | close(s); |
Elliott Hughes | b005d90 | 2017-02-22 14:54:15 -0800 | [diff] [blame] | 391 | PLOG(ERROR) << "sys_prop: unable to get SO_PEERCRED"; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 392 | return; |
| 393 | } |
| 394 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 395 | SocketConnection socket(s, cr); |
| 396 | uint32_t timeout_ms = kDefaultSocketTimeout; |
| 397 | |
| 398 | uint32_t cmd = 0; |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 399 | if (!socket.RecvUint32(&cmd, &timeout_ms)) { |
| 400 | PLOG(ERROR) << "sys_prop: error while reading command from the socket"; |
| 401 | socket.SendUint32(PROP_ERROR_READ_CMD); |
JP Abgrall | 4515d81 | 2014-01-31 14:37:07 -0800 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | |
Elliott Hughes | b005d90 | 2017-02-22 14:54:15 -0800 | [diff] [blame] | 405 | switch (cmd) { |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 406 | case PROP_MSG_SETPROP: { |
| 407 | char prop_name[PROP_NAME_MAX]; |
| 408 | char prop_value[PROP_VALUE_MAX]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 409 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 410 | if (!socket.RecvChars(prop_name, PROP_NAME_MAX, &timeout_ms) || |
| 411 | !socket.RecvChars(prop_value, PROP_VALUE_MAX, &timeout_ms)) { |
| 412 | PLOG(ERROR) << "sys_prop(PROP_MSG_SETPROP): error while reading name/value from the socket"; |
| 413 | return; |
Nick Kralevich | 6946361 | 2013-09-13 17:21:28 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 416 | prop_name[PROP_NAME_MAX-1] = 0; |
| 417 | prop_value[PROP_VALUE_MAX-1] = 0; |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 418 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 419 | handle_property_set(socket, prop_value, prop_value, true); |
Dimitry Ivanov | dee4bd2 | 2017-01-19 14:53:00 -0800 | [diff] [blame] | 420 | break; |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 421 | } |
Dimitry Ivanov | 70c4ecf | 2017-01-24 18:38:09 +0000 | [diff] [blame] | 422 | |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 423 | case PROP_MSG_SETPROP2: { |
| 424 | std::string name; |
| 425 | std::string value; |
| 426 | if (!socket.RecvString(&name, &timeout_ms) || |
| 427 | !socket.RecvString(&value, &timeout_ms)) { |
| 428 | PLOG(ERROR) << "sys_prop(PROP_MSG_SETPROP2): error while reading name/value from the socket"; |
| 429 | socket.SendUint32(PROP_ERROR_READ_DATA); |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | handle_property_set(socket, name, value, false); |
| 434 | break; |
| 435 | } |
Elliott Hughes | b005d90 | 2017-02-22 14:54:15 -0800 | [diff] [blame] | 436 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 437 | default: |
Elliott Hughes | b005d90 | 2017-02-22 14:54:15 -0800 | [diff] [blame] | 438 | LOG(ERROR) << "sys_prop: invalid command " << cmd; |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 439 | socket.SendUint32(PROP_ERROR_INVALID_CMD); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 440 | break; |
| 441 | } |
| 442 | } |
| 443 | |
Jeff Sharkey | f96b044 | 2014-03-06 14:26:36 -0800 | [diff] [blame] | 444 | static void load_properties_from_file(const char *, const char *); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 445 | |
Jeff Sharkey | f96b044 | 2014-03-06 14:26:36 -0800 | [diff] [blame] | 446 | /* |
| 447 | * Filter is used to decide which properties to load: NULL loads all keys, |
| 448 | * "ro.foo.*" is a prefix match, and "ro.foo.bar" is an exact match. |
| 449 | */ |
| 450 | static void load_properties(char *data, const char *filter) |
| 451 | { |
| 452 | char *key, *value, *eol, *sol, *tmp, *fn; |
| 453 | size_t flen = 0; |
| 454 | |
| 455 | if (filter) { |
| 456 | flen = strlen(filter); |
| 457 | } |
| 458 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 459 | sol = data; |
Jeff Sharkey | f96b044 | 2014-03-06 14:26:36 -0800 | [diff] [blame] | 460 | while ((eol = strchr(sol, '\n'))) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 461 | key = sol; |
| 462 | *eol++ = 0; |
| 463 | sol = eol; |
| 464 | |
Jeff Sharkey | f96b044 | 2014-03-06 14:26:36 -0800 | [diff] [blame] | 465 | while (isspace(*key)) key++; |
| 466 | if (*key == '#') continue; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 467 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 468 | tmp = eol - 2; |
Jeff Sharkey | f96b044 | 2014-03-06 14:26:36 -0800 | [diff] [blame] | 469 | while ((tmp > key) && isspace(*tmp)) *tmp-- = 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 470 | |
Jeff Sharkey | f96b044 | 2014-03-06 14:26:36 -0800 | [diff] [blame] | 471 | if (!strncmp(key, "import ", 7) && flen == 0) { |
| 472 | fn = key + 7; |
| 473 | while (isspace(*fn)) fn++; |
| 474 | |
| 475 | key = strchr(fn, ' '); |
| 476 | if (key) { |
| 477 | *key++ = 0; |
| 478 | while (isspace(*key)) key++; |
| 479 | } |
| 480 | |
| 481 | load_properties_from_file(fn, key); |
| 482 | |
| 483 | } else { |
| 484 | value = strchr(key, '='); |
| 485 | if (!value) continue; |
| 486 | *value++ = 0; |
| 487 | |
| 488 | tmp = value - 2; |
| 489 | while ((tmp > key) && isspace(*tmp)) *tmp-- = 0; |
| 490 | |
| 491 | while (isspace(*value)) value++; |
| 492 | |
| 493 | if (flen > 0) { |
| 494 | if (filter[flen - 1] == '*') { |
| 495 | if (strncmp(key, filter, flen - 1)) continue; |
| 496 | } else { |
| 497 | if (strcmp(key, filter)) continue; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | property_set(key, value); |
| 502 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
Elliott Hughes | 5a7ad84 | 2016-09-30 14:12:33 -0700 | [diff] [blame] | 506 | // Filter is used to decide which properties to load: NULL loads all keys, |
| 507 | // "ro.foo.*" is a prefix match, and "ro.foo.bar" is an exact match. |
Elliott Hughes | da40c00 | 2015-03-27 23:20:44 -0700 | [diff] [blame] | 508 | static void load_properties_from_file(const char* filename, const char* filter) { |
| 509 | Timer t; |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 510 | std::string data; |
Elliott Hughes | 5a7ad84 | 2016-09-30 14:12:33 -0700 | [diff] [blame] | 511 | if (!read_file(filename, &data)) { |
| 512 | PLOG(WARNING) << "Couldn't load properties from " << filename; |
| 513 | return; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 514 | } |
Elliott Hughes | 5a7ad84 | 2016-09-30 14:12:33 -0700 | [diff] [blame] | 515 | data.push_back('\n'); |
| 516 | load_properties(&data[0], filter); |
Elliott Hughes | 331cf2f | 2016-11-29 19:20:58 +0000 | [diff] [blame] | 517 | LOG(VERBOSE) << "(Loading properties from " << filename << " took " << t << ".)"; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 520 | static void load_persistent_properties() { |
| 521 | persistent_properties_loaded = 1; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 522 | |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 523 | std::unique_ptr<DIR, int(*)(DIR*)> dir(opendir(PERSISTENT_PROPERTY_DIR), closedir); |
| 524 | if (!dir) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 525 | PLOG(ERROR) << "Unable to open persistent property directory \"" |
| 526 | << PERSISTENT_PROPERTY_DIR << "\""; |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 527 | return; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 528 | } |
Tammo Spalink | 3dfe6c6 | 2009-08-26 10:13:20 +0800 | [diff] [blame] | 529 | |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 530 | struct dirent* entry; |
| 531 | while ((entry = readdir(dir.get())) != NULL) { |
| 532 | if (strncmp("persist.", entry->d_name, strlen("persist."))) { |
| 533 | continue; |
| 534 | } |
| 535 | if (entry->d_type != DT_REG) { |
| 536 | continue; |
| 537 | } |
| 538 | |
| 539 | // Open the file and read the property value. |
| 540 | int fd = openat(dirfd(dir.get()), entry->d_name, O_RDONLY | O_NOFOLLOW); |
| 541 | if (fd == -1) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 542 | PLOG(ERROR) << "Unable to open persistent property file \"" << entry->d_name << "\""; |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 543 | continue; |
| 544 | } |
| 545 | |
| 546 | struct stat sb; |
| 547 | if (fstat(fd, &sb) == -1) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 548 | PLOG(ERROR) << "fstat on property file \"" << entry->d_name << "\" failed"; |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 549 | close(fd); |
| 550 | continue; |
| 551 | } |
| 552 | |
| 553 | // File must not be accessible to others, be owned by root/root, and |
| 554 | // not be a hard link to any other file. |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 555 | if (((sb.st_mode & (S_IRWXG | S_IRWXO)) != 0) || sb.st_uid != 0 || sb.st_gid != 0 || sb.st_nlink != 1) { |
| 556 | PLOG(ERROR) << "skipping insecure property file " << entry->d_name |
| 557 | << " (uid=" << sb.st_uid << " gid=" << sb.st_gid |
| 558 | << " nlink=" << sb.st_nlink << " mode=" << std::oct << sb.st_mode << ")"; |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 559 | close(fd); |
| 560 | continue; |
| 561 | } |
| 562 | |
| 563 | char value[PROP_VALUE_MAX]; |
| 564 | int length = read(fd, value, sizeof(value) - 1); |
| 565 | if (length >= 0) { |
| 566 | value[length] = 0; |
| 567 | property_set(entry->d_name, value); |
| 568 | } else { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 569 | PLOG(ERROR) << "Unable to read persistent property file " << entry->d_name; |
Elliott Hughes | 81399e1 | 2015-03-10 08:39:45 -0700 | [diff] [blame] | 570 | } |
| 571 | close(fd); |
| 572 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Elliott Hughes | da40c00 | 2015-03-27 23:20:44 -0700 | [diff] [blame] | 575 | void property_load_boot_defaults() { |
Elliott Hughes | 795798d | 2017-01-27 16:21:55 -0800 | [diff] [blame] | 576 | load_properties_from_file("/default.prop", NULL); |
| 577 | load_properties_from_file("/odm/default.prop", NULL); |
| 578 | load_properties_from_file("/vendor/default.prop", NULL); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 579 | } |
| 580 | |
Nick Kralevich | 32b9023 | 2012-09-19 11:15:24 -0700 | [diff] [blame] | 581 | static void load_override_properties() { |
Elliott Hughes | c0e919c | 2015-02-04 14:46:36 -0800 | [diff] [blame] | 582 | if (ALLOW_LOCAL_PROP_OVERRIDE) { |
Tom Cherry | ccf2353 | 2017-03-28 16:40:41 -0700 | [diff] [blame] | 583 | load_properties_from_file("/data/local.prop", NULL); |
Nick Kralevich | 32b9023 | 2012-09-19 11:15:24 -0700 | [diff] [blame] | 584 | } |
Nick Kralevich | 32b9023 | 2012-09-19 11:15:24 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Ken Sumrall | c5c5103 | 2011-03-08 17:01:29 -0800 | [diff] [blame] | 587 | /* When booting an encrypted system, /data is not mounted when the |
| 588 | * property service is started, so any properties stored there are |
| 589 | * not loaded. Vold triggers init to load these properties once it |
| 590 | * has mounted /data. |
| 591 | */ |
Elliott Hughes | da40c00 | 2015-03-27 23:20:44 -0700 | [diff] [blame] | 592 | void load_persist_props(void) { |
Nick Kralevich | 32b9023 | 2012-09-19 11:15:24 -0700 | [diff] [blame] | 593 | load_override_properties(); |
Ken Sumrall | c5c5103 | 2011-03-08 17:01:29 -0800 | [diff] [blame] | 594 | /* Read persistent properties after all default values have been loaded. */ |
| 595 | load_persistent_properties(); |
Keun-young Park | 404906d | 2017-02-28 19:20:38 -0800 | [diff] [blame] | 596 | property_set("ro.persistent_properties.ready", "true"); |
Ken Sumrall | c5c5103 | 2011-03-08 17:01:29 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 599 | void load_recovery_id_prop() { |
Bowgo Tsai | c9a1842 | 2017-03-09 22:36:34 +0800 | [diff] [blame] | 600 | std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(), |
| 601 | fs_mgr_free_fstab); |
| 602 | if (!fstab) { |
| 603 | PLOG(ERROR) << "unable to read default fstab"; |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 604 | return; |
| 605 | } |
| 606 | |
Bowgo Tsai | c9a1842 | 2017-03-09 22:36:34 +0800 | [diff] [blame] | 607 | fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab.get(), RECOVERY_MOUNT_POINT); |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 608 | if (rec == NULL) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 609 | LOG(ERROR) << "/recovery not specified in fstab"; |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 610 | return; |
| 611 | } |
| 612 | |
| 613 | int fd = open(rec->blk_device, O_RDONLY); |
| 614 | if (fd == -1) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 615 | PLOG(ERROR) << "error opening block device " << rec->blk_device; |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 616 | return; |
| 617 | } |
| 618 | |
| 619 | boot_img_hdr hdr; |
| 620 | if (android::base::ReadFully(fd, &hdr, sizeof(hdr))) { |
| 621 | std::string hex = bytes_to_hex(reinterpret_cast<uint8_t*>(hdr.id), sizeof(hdr.id)); |
| 622 | property_set("ro.recovery_id", hex.c_str()); |
| 623 | } else { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 624 | PLOG(ERROR) << "error reading /recovery"; |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | close(fd); |
| 628 | } |
| 629 | |
Paul Lawrence | 948410a | 2015-07-01 14:40:56 -0700 | [diff] [blame] | 630 | void load_system_props() { |
Elliott Hughes | 795798d | 2017-01-27 16:21:55 -0800 | [diff] [blame] | 631 | load_properties_from_file("/system/build.prop", NULL); |
| 632 | load_properties_from_file("/odm/build.prop", NULL); |
| 633 | load_properties_from_file("/vendor/build.prop", NULL); |
| 634 | load_properties_from_file("/factory/factory.prop", "ro.*"); |
Andres Morales | db5f5d4 | 2015-05-08 08:30:33 -0700 | [diff] [blame] | 635 | load_recovery_id_prop(); |
Riley Andrews | e4b7b29 | 2014-06-16 15:06:21 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Elliott Hughes | da40c00 | 2015-03-27 23:20:44 -0700 | [diff] [blame] | 638 | void start_property_service() { |
Dimitry Ivanov | c9bb033 | 2017-01-24 20:43:58 +0000 | [diff] [blame] | 639 | property_set("ro.property_service.version", "2"); |
| 640 | |
Elliott Hughes | c6c26ed | 2015-04-24 18:50:30 -0700 | [diff] [blame] | 641 | property_set_fd = create_socket(PROP_SERVICE_NAME, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, |
| 642 | 0666, 0, 0, NULL); |
| 643 | if (property_set_fd == -1) { |
Elliott Hughes | f86b5a6 | 2016-06-24 15:12:21 -0700 | [diff] [blame] | 644 | PLOG(ERROR) << "start_property_service socket creation failed"; |
Elliott Hughes | c6c26ed | 2015-04-24 18:50:30 -0700 | [diff] [blame] | 645 | exit(1); |
| 646 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 647 | |
Elliott Hughes | c6c26ed | 2015-04-24 18:50:30 -0700 | [diff] [blame] | 648 | listen(property_set_fd, 8); |
Colin Cross | d11beb2 | 2010-04-13 19:33:37 -0700 | [diff] [blame] | 649 | |
Elliott Hughes | 929f407 | 2015-04-24 21:13:44 -0700 | [diff] [blame] | 650 | register_epoll_handler(property_set_fd, handle_property_set_fd); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 651 | } |