The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | #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 Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 12 | typedef struct pwatch pwatch; |
| 13 | |
| 14 | struct pwatch |
| 15 | { |
| 16 | const prop_info *pi; |
| 17 | unsigned serial; |
| 18 | }; |
| 19 | |
| 20 | static pwatch watchlist[1024]; |
| 21 | |
| 22 | static 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 | |
| 37 | int watchprops_main(int argc, char *argv[]) |
| 38 | { |
Colin Cross | 9177963 | 2013-01-28 17:14:04 -0800 | [diff] [blame^] | 39 | unsigned serial = 0; |
| 40 | unsigned count; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 41 | unsigned n; |
| 42 | |
Colin Cross | 9177963 | 2013-01-28 17:14:04 -0800 | [diff] [blame^] | 43 | for(n = 0; n < 1024; n++) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 44 | watchlist[n].pi = __system_property_find_nth(n); |
Colin Cross | 9177963 | 2013-01-28 17:14:04 -0800 | [diff] [blame^] | 45 | if (watchlist[n].pi == 0) |
| 46 | break; |
| 47 | watchlist[n].serial = __system_property_serial(watchlist[n].pi); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Colin Cross | 9177963 | 2013-01-28 17:14:04 -0800 | [diff] [blame^] | 50 | count = n; |
| 51 | if (count == 1024) |
| 52 | exit(1); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 53 | |
Colin Cross | 9177963 | 2013-01-28 17:14:04 -0800 | [diff] [blame^] | 54 | for(;;) { |
| 55 | serial = __system_property_wait_any(serial); |
| 56 | while(count < 1024){ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 57 | watchlist[count].pi = __system_property_find_nth(count); |
Colin Cross | 9177963 | 2013-01-28 17:14:04 -0800 | [diff] [blame^] | 58 | if (watchlist[count].pi == 0) |
| 59 | break; |
| 60 | watchlist[count].serial = __system_property_serial(watchlist[n].pi); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 61 | announce(watchlist[count].pi); |
| 62 | count++; |
| 63 | if(count == 1024) exit(1); |
| 64 | } |
| 65 | |
| 66 | for(n = 0; n < count; n++){ |
Colin Cross | 9177963 | 2013-01-28 17:14:04 -0800 | [diff] [blame^] | 67 | unsigned tmp = __system_property_serial(watchlist[n].pi); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 68 | if(watchlist[n].serial != tmp) { |
| 69 | announce(watchlist[n].pi); |
| 70 | watchlist[n].serial = tmp; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | return 0; |
| 75 | } |