Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4eab296e4d
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 77 lines (58 sloc) 1.727 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <cutils/properties.h>

#include <sys/atomics.h>

#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>


extern prop_area *__system_property_area__;

typedef struct pwatch pwatch;

struct pwatch
{
    const prop_info *pi;
    unsigned serial;
};

static pwatch watchlist[1024];

static void announce(const prop_info *pi)
{
    char name[PROP_NAME_MAX];
    char value[PROP_VALUE_MAX];
    char *x;
    
    __system_property_read(pi, name, value);

    for(x = value; *x; x++) {
        if((*x < 32) || (*x > 127)) *x = '.';
    }

    fprintf(stderr,"%10d %s = '%s'\n", (int) time(0), name, value);
}

int watchprops_main(int argc, char *argv[])
{
    prop_area *pa = __system_property_area__;
    unsigned serial = pa->serial;
    unsigned count = pa->count;
    unsigned n;
    
    if(count >= 1024) exit(1);

    for(n = 0; n < count; n++) {
        watchlist[n].pi = __system_property_find_nth(n);
        watchlist[n].serial = watchlist[n].pi->serial;
    }

    for(;;) {
        do {
            __futex_wait(&pa->serial, serial, 0);
        } while(pa->serial == serial);

        while(count < pa->count){
            watchlist[count].pi = __system_property_find_nth(count);
            watchlist[count].serial = watchlist[n].pi->serial;
            announce(watchlist[count].pi);
            count++;
            if(count == 1024) exit(1);
        }

        for(n = 0; n < count; n++){
            unsigned tmp = watchlist[n].pi->serial;
            if(watchlist[n].serial != tmp) {
                announce(watchlist[n].pi);
                watchlist[n].serial = tmp;
            }
        }
    }
    return 0;
}
Something went wrong with that request. Please try again.