blob: d3119924b03a20d57cb35613d80bad0fb6ac72e5 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001#include <stdio.h>
2#include <stdlib.h>
3#include <time.h>
4
5#include <cutils/properties.h>
6
7#include <sys/atomics.h>
8
9#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
10#include <sys/_system_properties.h>
11
12
13extern prop_area *__system_property_area__;
14
15typedef struct pwatch pwatch;
16
17struct pwatch
18{
19 const prop_info *pi;
20 unsigned serial;
21};
22
23static pwatch watchlist[1024];
24
25static void announce(const prop_info *pi)
26{
27 char name[PROP_NAME_MAX];
28 char value[PROP_VALUE_MAX];
29 char *x;
30
31 __system_property_read(pi, name, value);
32
33 for(x = value; *x; x++) {
34 if((*x < 32) || (*x > 127)) *x = '.';
35 }
36
37 fprintf(stderr,"%10d %s = '%s'\n", (int) time(0), name, value);
38}
39
40int watchprops_main(int argc, char *argv[])
41{
42 prop_area *pa = __system_property_area__;
43 unsigned serial = pa->serial;
44 unsigned count = pa->count;
45 unsigned n;
46
47 if(count >= 1024) exit(1);
48
49 for(n = 0; n < count; n++) {
50 watchlist[n].pi = __system_property_find_nth(n);
51 watchlist[n].serial = watchlist[n].pi->serial;
52 }
53
54 for(;;) {
55 do {
56 __futex_wait(&pa->serial, serial, 0);
57 } while(pa->serial == serial);
58
59 while(count < pa->count){
60 watchlist[count].pi = __system_property_find_nth(count);
61 watchlist[count].serial = watchlist[n].pi->serial;
62 announce(watchlist[count].pi);
63 count++;
64 if(count == 1024) exit(1);
65 }
66
67 for(n = 0; n < count; n++){
68 unsigned tmp = watchlist[n].pi->serial;
69 if(watchlist[n].serial != tmp) {
70 announce(watchlist[n].pi);
71 watchlist[n].serial = tmp;
72 }
73 }
74 }
75 return 0;
76}