blob: 5017375fc1f2eec8e1d49489577eeff56c412502 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
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>
27
28#include <cutils/misc.h>
29#include <cutils/sockets.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080030
31#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
32#include <sys/_system_properties.h>
33
34#include <sys/socket.h>
35#include <sys/un.h>
36#include <sys/select.h>
37#include <sys/types.h>
38#include <netinet/in.h>
39#include <sys/mman.h>
40#include <sys/atomics.h>
41#include <private/android_filesystem_config.h>
42
rpcraig63207cd2012-08-09 10:05:49 -040043#ifdef HAVE_SELINUX
44#include <selinux/selinux.h>
45#include <selinux/label.h>
46#endif
47
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080048#include "property_service.h"
49#include "init.h"
Colin Cross3899e9f2010-04-13 20:35:46 -070050#include "util.h"
Colin Crossed8a7d82010-04-19 17:05:34 -070051#include "log.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080052
53#define PERSISTENT_PROPERTY_DIR "/data/property"
54
55static int persistent_properties_loaded = 0;
Colin Cross3294bbb2010-04-19 17:11:33 -070056static int property_area_inited = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080057
Colin Crossd11beb22010-04-13 19:33:37 -070058static int property_set_fd = -1;
59
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080060/* White list of permissions for setting property services. */
61struct {
62 const char *prefix;
63 unsigned int uid;
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -040064 unsigned int gid;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080065} property_perms[] = {
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -040066 { "net.rmnet0.", AID_RADIO, 0 },
67 { "net.gprs.", AID_RADIO, 0 },
68 { "net.ppp", AID_RADIO, 0 },
Amol Bhatkarcf015972011-02-18 17:54:17 -060069 { "net.qmi", AID_RADIO, 0 },
Benoit Goby7100f642011-07-25 18:02:06 -070070 { "net.lte", AID_RADIO, 0 },
Benoit Goby22bfc4c2011-07-28 18:09:55 -070071 { "net.cdma", AID_RADIO, 0 },
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -040072 { "ril.", AID_RADIO, 0 },
73 { "gsm.", AID_RADIO, 0 },
74 { "persist.radio", AID_RADIO, 0 },
75 { "net.dns", AID_RADIO, 0 },
Benoit Goby5da93582011-08-22 12:12:37 -070076 { "sys.usb.config", AID_RADIO, 0 },
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -040077 { "net.", AID_SYSTEM, 0 },
78 { "dev.", AID_SYSTEM, 0 },
79 { "runtime.", AID_SYSTEM, 0 },
80 { "hw.", AID_SYSTEM, 0 },
81 { "sys.", AID_SYSTEM, 0 },
82 { "service.", AID_SYSTEM, 0 },
83 { "wlan.", AID_SYSTEM, 0 },
84 { "dhcp.", AID_SYSTEM, 0 },
85 { "dhcp.", AID_DHCP, 0 },
Romain Guy45fa13f2012-04-27 15:19:30 -070086 { "debug.", AID_SYSTEM, 0 },
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -040087 { "debug.", AID_SHELL, 0 },
88 { "log.", AID_SHELL, 0 },
89 { "service.adb.root", AID_SHELL, 0 },
Mike Lockwood58aa5b02010-12-10 09:48:41 -080090 { "service.adb.tcp.port", AID_SHELL, 0 },
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -040091 { "persist.sys.", AID_SYSTEM, 0 },
92 { "persist.service.", AID_SYSTEM, 0 },
Oscar Montemayoref4e2152009-11-12 12:02:24 -080093 { "persist.security.", AID_SYSTEM, 0 },
Stephen Smalleyae6f3d72012-05-01 15:02:53 -040094 { "selinux." , AID_SYSTEM, 0 },
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -040095 { NULL, 0, 0 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080096};
97
98/*
99 * White list of UID that are allowed to start/stop services.
100 * Currently there are no user apps that require.
101 */
102struct {
103 const char *service;
104 unsigned int uid;
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -0400105 unsigned int gid;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800106} control_perms[] = {
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -0400107 { "dumpstate",AID_SHELL, AID_LOG },
Wink Savillecfa0d842010-10-03 13:30:11 -0700108 { "ril-daemon",AID_RADIO, AID_RADIO },
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -0400109 {NULL, 0, 0 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800110};
111
112typedef struct {
113 void *data;
114 size_t size;
115 int fd;
116} workspace;
117
118static int init_workspace(workspace *w, size_t size)
119{
120 void *data;
121 int fd;
122
Brian Swetland25b15be2010-07-13 16:43:56 -0700123 /* dev is a tmpfs that we can use to carve a shared workspace
124 * out of, so let's do that...
125 */
126 fd = open("/dev/__properties__", O_RDWR | O_CREAT, 0600);
127 if (fd < 0)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800128 return -1;
129
Brian Swetland25b15be2010-07-13 16:43:56 -0700130 if (ftruncate(fd, size) < 0)
131 goto out;
132
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800133 data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
134 if(data == MAP_FAILED)
135 goto out;
136
Brian Swetland25b15be2010-07-13 16:43:56 -0700137 close(fd);
138
139 fd = open("/dev/__properties__", O_RDONLY);
140 if (fd < 0)
141 return -1;
142
143 unlink("/dev/__properties__");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800144
145 w->data = data;
146 w->size = size;
147 w->fd = fd;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800148 return 0;
149
150out:
151 close(fd);
152 return -1;
153}
154
155/* (8 header words + 247 toc words) = 1020 bytes */
156/* 1024 bytes header and toc + 247 prop_infos @ 128 bytes = 32640 bytes */
157
158#define PA_COUNT_MAX 247
159#define PA_INFO_START 1024
160#define PA_SIZE 32768
161
162static workspace pa_workspace;
163static prop_info *pa_info_array;
164
165extern prop_area *__system_property_area__;
166
167static int init_property_area(void)
168{
169 prop_area *pa;
170
171 if(pa_info_array)
172 return -1;
173
174 if(init_workspace(&pa_workspace, PA_SIZE))
175 return -1;
176
177 fcntl(pa_workspace.fd, F_SETFD, FD_CLOEXEC);
178
179 pa_info_array = (void*) (((char*) pa_workspace.data) + PA_INFO_START);
180
181 pa = pa_workspace.data;
182 memset(pa, 0, PA_SIZE);
183 pa->magic = PROP_AREA_MAGIC;
184 pa->version = PROP_AREA_VERSION;
185
186 /* plug into the lib property services */
187 __system_property_area__ = pa;
Colin Cross3294bbb2010-04-19 17:11:33 -0700188 property_area_inited = 1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800189 return 0;
190}
191
192static void update_prop_info(prop_info *pi, const char *value, unsigned len)
193{
194 pi->serial = pi->serial | 1;
195 memcpy(pi->value, value, len + 1);
196 pi->serial = (len << 24) | ((pi->serial + 1) & 0xffffff);
197 __futex_wake(&pi->serial, INT32_MAX);
198}
199
rpcraig63207cd2012-08-09 10:05:49 -0400200static int check_mac_perms(const char *name, char *sctx)
201{
202#ifdef HAVE_SELINUX
203 if (is_selinux_enabled() <= 0)
204 return 1;
205
206 char *tctx = NULL;
207 const char *class = "property_service";
208 const char *perm = "set";
209 int result = 0;
210
211 if (!sctx)
212 goto err;
213
214 if (!sehandle_prop)
215 goto err;
216
217 if (selabel_lookup(sehandle_prop, &tctx, name, 1) != 0)
218 goto err;
219
220 if (selinux_check_access(sctx, tctx, class, perm, name) == 0)
221 result = 1;
222
223 freecon(tctx);
224 err:
225 return result;
226
227#endif
228 return 1;
229}
230
231static int check_control_mac_perms(const char *name, char *sctx)
232{
233#ifdef HAVE_SELINUX
234
235 /*
236 * Create a name prefix out of ctl.<service name>
237 * The new prefix allows the use of the existing
238 * property service backend labeling while avoiding
239 * mislabels based on true property prefixes.
240 */
241 char ctl_name[PROP_VALUE_MAX+4];
242 int ret = snprintf(ctl_name, sizeof(ctl_name), "ctl.%s", name);
243
244 if (ret < 0 || (size_t) ret >= sizeof(ctl_name))
245 return 0;
246
247 return check_mac_perms(ctl_name, sctx);
248
249#endif
250 return 1;
251}
252
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800253/*
254 * Checks permissions for starting/stoping system services.
255 * AID_SYSTEM and AID_ROOT are always allowed.
256 *
257 * Returns 1 if uid allowed, 0 otherwise.
258 */
rpcraig63207cd2012-08-09 10:05:49 -0400259static int check_control_perms(const char *name, unsigned int uid, unsigned int gid, char *sctx) {
260
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800261 int i;
262 if (uid == AID_SYSTEM || uid == AID_ROOT)
rpcraig63207cd2012-08-09 10:05:49 -0400263 return check_control_mac_perms(name, sctx);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800264
265 /* Search the ACL */
266 for (i = 0; control_perms[i].service; i++) {
267 if (strcmp(control_perms[i].service, name) == 0) {
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -0400268 if ((uid && control_perms[i].uid == uid) ||
269 (gid && control_perms[i].gid == gid)) {
rpcraig63207cd2012-08-09 10:05:49 -0400270 return check_control_mac_perms(name, sctx);
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -0400271 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800272 }
273 }
274 return 0;
275}
276
277/*
278 * Checks permissions for setting system properties.
279 * Returns 1 if uid allowed, 0 otherwise.
280 */
rpcraig63207cd2012-08-09 10:05:49 -0400281static int check_perms(const char *name, unsigned int uid, unsigned int gid, char *sctx)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800282{
283 int i;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800284 if(!strncmp(name, "ro.", 3))
285 name +=3;
286
rpcraig63207cd2012-08-09 10:05:49 -0400287 if (uid == 0)
288 return check_mac_perms(name, sctx);
289
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800290 for (i = 0; property_perms[i].prefix; i++) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800291 if (strncmp(property_perms[i].prefix, name,
292 strlen(property_perms[i].prefix)) == 0) {
Mike Lockwoodc5e7ef22009-09-02 18:08:52 -0400293 if ((uid && property_perms[i].uid == uid) ||
294 (gid && property_perms[i].gid == gid)) {
rpcraig63207cd2012-08-09 10:05:49 -0400295
296 return check_mac_perms(name, sctx);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800297 }
298 }
299 }
300
301 return 0;
302}
303
304const char* property_get(const char *name)
305{
306 prop_info *pi;
307
308 if(strlen(name) >= PROP_NAME_MAX) return 0;
309
310 pi = (prop_info*) __system_property_find(name);
311
312 if(pi != 0) {
313 return pi->value;
314 } else {
315 return 0;
316 }
317}
318
Tammo Spalink3dfe6c62009-08-26 10:13:20 +0800319static void write_persistent_property(const char *name, const char *value)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800320{
321 const char *tempPath = PERSISTENT_PROPERTY_DIR "/.temp";
322 char path[PATH_MAX];
323 int fd, length;
324
325 snprintf(path, sizeof(path), "%s/%s", PERSISTENT_PROPERTY_DIR, name);
326
327 fd = open(tempPath, O_WRONLY|O_CREAT|O_TRUNC, 0600);
328 if (fd < 0) {
329 ERROR("Unable to write persistent property to temp file %s errno: %d\n", tempPath, errno);
Tammo Spalink3dfe6c62009-08-26 10:13:20 +0800330 return;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800331 }
332 write(fd, value, strlen(value));
333 close(fd);
334
335 if (rename(tempPath, path)) {
336 unlink(tempPath);
337 ERROR("Unable to rename persistent property file %s to %s\n", tempPath, path);
338 }
339}
340
341int property_set(const char *name, const char *value)
342{
343 prop_area *pa;
344 prop_info *pi;
345
346 int namelen = strlen(name);
347 int valuelen = strlen(value);
348
349 if(namelen >= PROP_NAME_MAX) return -1;
350 if(valuelen >= PROP_VALUE_MAX) return -1;
351 if(namelen < 1) return -1;
352
353 pi = (prop_info*) __system_property_find(name);
354
355 if(pi != 0) {
356 /* ro.* properties may NEVER be modified once set */
357 if(!strncmp(name, "ro.", 3)) return -1;
358
359 pa = __system_property_area__;
360 update_prop_info(pi, value, valuelen);
361 pa->serial++;
362 __futex_wake(&pa->serial, INT32_MAX);
363 } else {
364 pa = __system_property_area__;
365 if(pa->count == PA_COUNT_MAX) return -1;
366
367 pi = pa_info_array + pa->count;
368 pi->serial = (valuelen << 24);
369 memcpy(pi->name, name, namelen + 1);
370 memcpy(pi->value, value, valuelen + 1);
371
372 pa->toc[pa->count] =
373 (namelen << 24) | (((unsigned) pi) - ((unsigned) pa));
374
375 pa->count++;
376 pa->serial++;
377 __futex_wake(&pa->serial, INT32_MAX);
378 }
379 /* If name starts with "net." treat as a DNS property. */
Mike Lockwoodb3779552009-05-08 14:27:42 -0400380 if (strncmp("net.", name, strlen("net.")) == 0) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800381 if (strcmp("net.change", name) == 0) {
382 return 0;
383 }
Tammo Spalink3dfe6c62009-08-26 10:13:20 +0800384 /*
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800385 * The 'net.change' property is a special property used track when any
386 * 'net.*' property name is updated. It is _ONLY_ updated here. Its value
387 * contains the last updated 'net.*' property.
388 */
389 property_set("net.change", name);
390 } else if (persistent_properties_loaded &&
Mike Lockwoodb3779552009-05-08 14:27:42 -0400391 strncmp("persist.", name, strlen("persist.")) == 0) {
Tammo Spalink3dfe6c62009-08-26 10:13:20 +0800392 /*
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800393 * Don't write properties to disk until after we have read all default properties
394 * to prevent them from being overwritten by default values.
395 */
Tammo Spalink3dfe6c62009-08-26 10:13:20 +0800396 write_persistent_property(name, value);
Stephen Smalleyae6f3d72012-05-01 15:02:53 -0400397#ifdef HAVE_SELINUX
398 } else if (strcmp("selinux.reload_policy", name) == 0 &&
399 strcmp("1", value) == 0) {
400 selinux_reload_policy();
401#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800402 }
403 property_changed(name, value);
404 return 0;
405}
406
Colin Crossd11beb22010-04-13 19:33:37 -0700407void handle_property_set_fd()
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800408{
409 prop_msg msg;
410 int s;
411 int r;
412 int res;
413 struct ucred cr;
414 struct sockaddr_un addr;
415 socklen_t addr_size = sizeof(addr);
416 socklen_t cr_size = sizeof(cr);
rpcraig63207cd2012-08-09 10:05:49 -0400417 char * source_ctx = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800418
Colin Crossd11beb22010-04-13 19:33:37 -0700419 if ((s = accept(property_set_fd, (struct sockaddr *) &addr, &addr_size)) < 0) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800420 return;
421 }
422
423 /* Check socket options here */
424 if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &cr_size) < 0) {
425 close(s);
426 ERROR("Unable to recieve socket options\n");
427 return;
428 }
429
Mike Lockwoodd18678f2011-07-01 14:48:50 -0400430 r = TEMP_FAILURE_RETRY(recv(s, &msg, sizeof(msg), 0));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800431 if(r != sizeof(prop_msg)) {
Mike Lockwoodd18678f2011-07-01 14:48:50 -0400432 ERROR("sys_prop: mis-match msg size recieved: %d expected: %d errno: %d\n",
433 r, sizeof(prop_msg), errno);
Brad Fitzpatrick9f1e0e32011-03-30 12:39:56 -0700434 close(s);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800435 return;
436 }
437
438 switch(msg.cmd) {
439 case PROP_MSG_SETPROP:
440 msg.name[PROP_NAME_MAX-1] = 0;
441 msg.value[PROP_VALUE_MAX-1] = 0;
442
rpcraig63207cd2012-08-09 10:05:49 -0400443#ifdef HAVE_SELINUX
444 getpeercon(s, &source_ctx);
445#endif
446
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800447 if(memcmp(msg.name,"ctl.",4) == 0) {
Brad Fitzpatrick71ead182011-04-01 08:24:13 -0700448 // Keep the old close-socket-early behavior when handling
449 // ctl.* properties.
450 close(s);
rpcraig63207cd2012-08-09 10:05:49 -0400451 if (check_control_perms(msg.value, cr.uid, cr.gid, source_ctx)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800452 handle_control_message((char*) msg.name + 4, (char*) msg.value);
453 } else {
Wink Savillecfa0d842010-10-03 13:30:11 -0700454 ERROR("sys_prop: Unable to %s service ctl [%s] uid:%d gid:%d pid:%d\n",
455 msg.name + 4, msg.value, cr.uid, cr.gid, cr.pid);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800456 }
457 } else {
rpcraig63207cd2012-08-09 10:05:49 -0400458 if (check_perms(msg.name, cr.uid, cr.gid, source_ctx)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800459 property_set((char*) msg.name, (char*) msg.value);
460 } else {
461 ERROR("sys_prop: permission denied uid:%d name:%s\n",
462 cr.uid, msg.name);
463 }
Brad Fitzpatrick71ead182011-04-01 08:24:13 -0700464
465 // Note: bionic's property client code assumes that the
466 // property server will not close the socket until *AFTER*
467 // the property is written to memory.
468 close(s);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800469 }
rpcraig63207cd2012-08-09 10:05:49 -0400470#ifdef HAVE_SELINUX
471 freecon(source_ctx);
472#endif
473
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800474 break;
475
476 default:
Brad Fitzpatrick71ead182011-04-01 08:24:13 -0700477 close(s);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800478 break;
479 }
480}
481
482void get_property_workspace(int *fd, int *sz)
483{
484 *fd = pa_workspace.fd;
485 *sz = pa_workspace.size;
486}
487
488static void load_properties(char *data)
489{
490 char *key, *value, *eol, *sol, *tmp;
491
492 sol = data;
493 while((eol = strchr(sol, '\n'))) {
494 key = sol;
495 *eol++ = 0;
496 sol = eol;
497
498 value = strchr(key, '=');
499 if(value == 0) continue;
500 *value++ = 0;
501
502 while(isspace(*key)) key++;
503 if(*key == '#') continue;
504 tmp = value - 2;
505 while((tmp > key) && isspace(*tmp)) *tmp-- = 0;
506
507 while(isspace(*value)) value++;
508 tmp = eol - 2;
509 while((tmp > value) && isspace(*tmp)) *tmp-- = 0;
510
511 property_set(key, value);
512 }
513}
514
515static void load_properties_from_file(const char *fn)
516{
517 char *data;
518 unsigned sz;
519
520 data = read_file(fn, &sz);
521
522 if(data != 0) {
523 load_properties(data);
524 free(data);
525 }
526}
527
528static void load_persistent_properties()
529{
530 DIR* dir = opendir(PERSISTENT_PROPERTY_DIR);
531 struct dirent* entry;
532 char path[PATH_MAX];
533 char value[PROP_VALUE_MAX];
534 int fd, length;
535
536 if (dir) {
537 while ((entry = readdir(dir)) != NULL) {
Mike Lockwoodb3779552009-05-08 14:27:42 -0400538 if (strncmp("persist.", entry->d_name, strlen("persist.")))
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800539 continue;
540#if HAVE_DIRENT_D_TYPE
541 if (entry->d_type != DT_REG)
542 continue;
543#endif
544 /* open the file and read the property value */
545 snprintf(path, sizeof(path), "%s/%s", PERSISTENT_PROPERTY_DIR, entry->d_name);
546 fd = open(path, O_RDONLY);
547 if (fd >= 0) {
548 length = read(fd, value, sizeof(value) - 1);
549 if (length >= 0) {
550 value[length] = 0;
551 property_set(entry->d_name, value);
552 } else {
553 ERROR("Unable to read persistent property file %s errno: %d\n", path, errno);
554 }
555 close(fd);
556 } else {
557 ERROR("Unable to open persistent property file %s errno: %d\n", path, errno);
558 }
559 }
560 closedir(dir);
561 } else {
562 ERROR("Unable to open persistent property directory %s errno: %d\n", PERSISTENT_PROPERTY_DIR, errno);
563 }
Tammo Spalink3dfe6c62009-08-26 10:13:20 +0800564
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800565 persistent_properties_loaded = 1;
566}
567
Dima Zavin88861122011-12-19 11:21:32 -0800568void property_init(void)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800569{
570 init_property_area();
Dima Zavin88861122011-12-19 11:21:32 -0800571}
572
573void property_load_boot_defaults(void)
574{
575 load_properties_from_file(PROP_PATH_RAMDISK_DEFAULT);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800576}
577
Colin Cross3294bbb2010-04-19 17:11:33 -0700578int properties_inited(void)
579{
580 return property_area_inited;
581}
582
Ken Sumrallc5c51032011-03-08 17:01:29 -0800583/* When booting an encrypted system, /data is not mounted when the
584 * property service is started, so any properties stored there are
585 * not loaded. Vold triggers init to load these properties once it
586 * has mounted /data.
587 */
588void load_persist_props(void)
589{
Nick Kralevich0dbda7e2012-01-18 13:38:34 -0800590#ifdef ALLOW_LOCAL_PROP_OVERRIDE
Ken Sumrallc5c51032011-03-08 17:01:29 -0800591 load_properties_from_file(PROP_PATH_LOCAL_OVERRIDE);
Nick Kralevich0dbda7e2012-01-18 13:38:34 -0800592#endif /* ALLOW_LOCAL_PROP_OVERRIDE */
Ken Sumrallc5c51032011-03-08 17:01:29 -0800593 /* Read persistent properties after all default values have been loaded. */
594 load_persistent_properties();
595}
596
Colin Crossd11beb22010-04-13 19:33:37 -0700597void start_property_service(void)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800598{
599 int fd;
600
601 load_properties_from_file(PROP_PATH_SYSTEM_BUILD);
602 load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT);
Nick Kralevich0dbda7e2012-01-18 13:38:34 -0800603#ifdef ALLOW_LOCAL_PROP_OVERRIDE
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800604 load_properties_from_file(PROP_PATH_LOCAL_OVERRIDE);
Nick Kralevich0dbda7e2012-01-18 13:38:34 -0800605#endif /* ALLOW_LOCAL_PROP_OVERRIDE */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800606 /* Read persistent properties after all default values have been loaded. */
607 load_persistent_properties();
608
609 fd = create_socket(PROP_SERVICE_NAME, SOCK_STREAM, 0666, 0, 0);
Colin Crossd11beb22010-04-13 19:33:37 -0700610 if(fd < 0) return;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800611 fcntl(fd, F_SETFD, FD_CLOEXEC);
612 fcntl(fd, F_SETFL, O_NONBLOCK);
613
614 listen(fd, 8);
Colin Crossd11beb22010-04-13 19:33:37 -0700615 property_set_fd = fd;
616}
617
618int get_property_set_fd()
619{
620 return property_set_fd;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800621}