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