2009-03-04 04:32:55 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-01-25 05:03:09 +01:00
|
|
|
#include <string.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <time.h>
|
2013-02-13 19:49:50 +01:00
|
|
|
#include <errno.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
#include <cutils/properties.h>
|
2013-02-13 19:49:50 +01:00
|
|
|
#include <cutils/hashmap.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
|
|
|
#include <sys/_system_properties.h>
|
|
|
|
|
2013-02-13 19:49:50 +01:00
|
|
|
static int str_hash(void *key)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
2013-02-13 19:49:50 +01:00
|
|
|
return hashmapHash(key, strlen(key));
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2013-02-13 19:49:50 +01:00
|
|
|
static bool str_equals(void *keyA, void *keyB)
|
|
|
|
{
|
|
|
|
return strcmp(keyA, keyB) == 0;
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2013-02-13 19:49:50 +01:00
|
|
|
static void announce(char *name, char *value)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
2014-05-21 19:39:44 +02:00
|
|
|
unsigned char *x;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2014-05-21 19:39:44 +02:00
|
|
|
for(x = (unsigned char *)value; *x; x++) {
|
2009-03-04 04:32:55 +01:00
|
|
|
if((*x < 32) || (*x > 127)) *x = '.';
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr,"%10d %s = '%s'\n", (int) time(0), name, value);
|
|
|
|
}
|
|
|
|
|
2013-02-13 19:49:50 +01:00
|
|
|
static void add_to_watchlist(Hashmap *watchlist, const char *name,
|
|
|
|
const prop_info *pi)
|
|
|
|
{
|
|
|
|
char *key = strdup(name);
|
|
|
|
unsigned *value = malloc(sizeof(unsigned));
|
|
|
|
if (!key || !value)
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
*value = __system_property_serial(pi);
|
|
|
|
hashmapPut(watchlist, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void populate_watchlist(const prop_info *pi, void *cookie)
|
|
|
|
{
|
|
|
|
Hashmap *watchlist = cookie;
|
|
|
|
char name[PROP_NAME_MAX];
|
|
|
|
char value_unused[PROP_VALUE_MAX];
|
|
|
|
|
|
|
|
__system_property_read(pi, name, value_unused);
|
|
|
|
add_to_watchlist(watchlist, name, pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_watchlist(const prop_info *pi, void *cookie)
|
|
|
|
{
|
|
|
|
Hashmap *watchlist = cookie;
|
|
|
|
char name[PROP_NAME_MAX];
|
|
|
|
char value[PROP_VALUE_MAX];
|
|
|
|
unsigned *serial;
|
|
|
|
|
|
|
|
__system_property_read(pi, name, value);
|
|
|
|
serial = hashmapGet(watchlist, name);
|
|
|
|
if (!serial) {
|
|
|
|
add_to_watchlist(watchlist, name, pi);
|
|
|
|
announce(name, value);
|
|
|
|
} else {
|
|
|
|
unsigned tmp = __system_property_serial(pi);
|
|
|
|
if (*serial != tmp) {
|
|
|
|
*serial = tmp;
|
|
|
|
announce(name, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
int watchprops_main(int argc, char *argv[])
|
|
|
|
{
|
2014-05-08 18:31:43 +02:00
|
|
|
unsigned serial;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2013-02-13 19:49:50 +01:00
|
|
|
Hashmap *watchlist = hashmapCreate(1024, str_hash, str_equals);
|
|
|
|
if (!watchlist)
|
2013-01-29 02:14:04 +01:00
|
|
|
exit(1);
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2013-02-13 19:49:50 +01:00
|
|
|
__system_property_foreach(populate_watchlist, watchlist);
|
|
|
|
|
2014-05-08 18:31:43 +02:00
|
|
|
for(serial = 0;;) {
|
2013-01-29 02:14:04 +01:00
|
|
|
serial = __system_property_wait_any(serial);
|
2013-02-13 19:49:50 +01:00
|
|
|
__system_property_foreach(update_watchlist, watchlist);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|