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