blob: 3418d62932cca68b89c323c5040ba706b4bd4ae4 [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
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080012typedef struct pwatch pwatch;
13
14struct pwatch
15{
16 const prop_info *pi;
17 unsigned serial;
18};
19
20static pwatch watchlist[1024];
21
22static void announce(const prop_info *pi)
23{
24 char name[PROP_NAME_MAX];
25 char value[PROP_VALUE_MAX];
26 char *x;
27
28 __system_property_read(pi, name, value);
29
30 for(x = value; *x; x++) {
31 if((*x < 32) || (*x > 127)) *x = '.';
32 }
33
34 fprintf(stderr,"%10d %s = '%s'\n", (int) time(0), name, value);
35}
36
37int watchprops_main(int argc, char *argv[])
38{
Colin Cross91779632013-01-28 17:14:04 -080039 unsigned serial = 0;
40 unsigned count;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080041 unsigned n;
42
Colin Cross91779632013-01-28 17:14:04 -080043 for(n = 0; n < 1024; n++) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080044 watchlist[n].pi = __system_property_find_nth(n);
Colin Cross91779632013-01-28 17:14:04 -080045 if (watchlist[n].pi == 0)
46 break;
47 watchlist[n].serial = __system_property_serial(watchlist[n].pi);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080048 }
49
Colin Cross91779632013-01-28 17:14:04 -080050 count = n;
51 if (count == 1024)
52 exit(1);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080053
Colin Cross91779632013-01-28 17:14:04 -080054 for(;;) {
55 serial = __system_property_wait_any(serial);
56 while(count < 1024){
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080057 watchlist[count].pi = __system_property_find_nth(count);
Colin Cross91779632013-01-28 17:14:04 -080058 if (watchlist[count].pi == 0)
59 break;
60 watchlist[count].serial = __system_property_serial(watchlist[n].pi);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080061 announce(watchlist[count].pi);
62 count++;
63 if(count == 1024) exit(1);
64 }
65
66 for(n = 0; n < count; n++){
Colin Cross91779632013-01-28 17:14:04 -080067 unsigned tmp = __system_property_serial(watchlist[n].pi);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080068 if(watchlist[n].serial != tmp) {
69 announce(watchlist[n].pi);
70 watchlist[n].serial = tmp;
71 }
72 }
73 }
74 return 0;
75}