mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-15 18:20:21 +00:00
Generalize logging interface
This commit is contained in:
@@ -10,9 +10,6 @@
|
||||
|
||||
extern int prop_verbose;
|
||||
|
||||
#define PRINT_D(...) { LOGD(__VA_ARGS__); if (prop_verbose) fprintf(stderr, __VA_ARGS__); }
|
||||
#define PRINT_E(...) { LOGE(__VA_ARGS__); fprintf(stderr, __VA_ARGS__); }
|
||||
|
||||
struct prop_t {
|
||||
char *name;
|
||||
char value[PROP_VALUE_MAX];
|
||||
|
@@ -153,7 +153,7 @@ static void pb_getprop_cb(const char *name, const char *value, void *v) {
|
||||
|
||||
void persist_getprop_all(struct read_cb_t *read_cb) {
|
||||
if (access(PERSISTENT_PROPERTY_DIR "/persistent_properties", R_OK) == 0) {
|
||||
PRINT_D("resetprop: decode with protobuf from [" PERSISTENT_PROPERTY_DIR "/persistent_properties]\n");
|
||||
LOGD("resetprop: decode with protobuf from [" PERSISTENT_PROPERTY_DIR "/persistent_properties]\n");
|
||||
PersistentProperties props = PersistentProperties_init_zero;
|
||||
props.properties.funcs.decode = prop_decode;
|
||||
props.properties.arg = read_cb;
|
||||
@@ -196,7 +196,7 @@ char *persist_getprop(const char *name) {
|
||||
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
PRINT_D("resetprop: read prop from [%s]\n", path);
|
||||
LOGD("resetprop: read prop from [%s]\n", path);
|
||||
prop.value[read(fd, prop.value, sizeof(PROP_VALUE_MAX))] = '\0'; // Null terminate the read value
|
||||
close(fd);
|
||||
}
|
||||
@@ -231,7 +231,7 @@ bool persist_deleteprop(const char *name) {
|
||||
pb_ostream_t ostream = create_ostream(PERSISTENT_PROPERTY_DIR "/persistent_properties.tmp");
|
||||
props.properties.funcs.encode = prop_encode;
|
||||
props.properties.arg = &v;
|
||||
PRINT_D("resetprop: encode with protobuf to [" PERSISTENT_PROPERTY_DIR "/persistent_properties.tmp]\n");
|
||||
LOGD("resetprop: encode with protobuf to [" PERSISTENT_PROPERTY_DIR "/persistent_properties.tmp]\n");
|
||||
if (!pb_encode(&ostream, PersistentProperties_fields, &props))
|
||||
return false;
|
||||
clone_attr(PERSISTENT_PROPERTY_DIR "/persistent_properties", PERSISTENT_PROPERTY_DIR "/persistent_properties.tmp");
|
||||
@@ -244,7 +244,7 @@ bool persist_deleteprop(const char *name) {
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, sizeof(path), PERSISTENT_PROPERTY_DIR "/%s", name);
|
||||
if (unlink(path) == 0) {
|
||||
PRINT_D("resetprop: unlink [%s]\n", path);
|
||||
LOGD("resetprop: unlink [%s]\n", path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ static int check_legal_property_name(const char *name) {
|
||||
return 0;
|
||||
|
||||
illegal:
|
||||
PRINT_E("Illegal property name: [%s]\n", name);
|
||||
LOGE("Illegal property name: [%s]\n", name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ static int prop_cmp(const void *p1, const void *p2) {
|
||||
|
||||
static int init_resetprop() {
|
||||
if (__system_properties_init()) {
|
||||
PRINT_E("resetprop: Initialize error\n");
|
||||
LOGE("resetprop: Initialize error\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -176,7 +176,7 @@ char *getprop2(const char *name, int persist) {
|
||||
if (value)
|
||||
return value;
|
||||
}
|
||||
PRINT_D("resetprop: prop [%s] does not exist\n", name);
|
||||
LOGD("resetprop: prop [%s] does not exist\n", name);
|
||||
return NULL;
|
||||
} else {
|
||||
char value[PROP_VALUE_MAX];
|
||||
@@ -185,7 +185,7 @@ char *getprop2(const char *name, int persist) {
|
||||
.cookie = value
|
||||
};
|
||||
__system_property_read_callback(pi, callback_wrapper, &read_cb);
|
||||
PRINT_D("resetprop: getprop [%s]: [%s]\n", name, value);
|
||||
LOGD("resetprop: getprop [%s]: [%s]\n", name, value);
|
||||
return strdup(value);
|
||||
}
|
||||
}
|
||||
@@ -218,7 +218,7 @@ int setprop2(const char *name, const char *value, const int trigger) {
|
||||
ret = __system_property_update(pi, value, strlen(value));
|
||||
}
|
||||
} else {
|
||||
PRINT_D("resetprop: New prop [%s]\n", name);
|
||||
LOGD("resetprop: New prop [%s]\n", name);
|
||||
if (trigger) {
|
||||
ret = __system_property_set(name, value);
|
||||
} else {
|
||||
@@ -226,11 +226,11 @@ int setprop2(const char *name, const char *value, const int trigger) {
|
||||
}
|
||||
}
|
||||
|
||||
PRINT_D("resetprop: setprop [%s]: [%s] by %s\n", name, value,
|
||||
LOGD("resetprop: setprop [%s]: [%s] by %s\n", name, value,
|
||||
trigger ? "property_service" : "modifing prop data structure");
|
||||
|
||||
if (ret)
|
||||
PRINT_E("resetprop: setprop error\n");
|
||||
LOGE("resetprop: setprop error\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -245,7 +245,7 @@ int deleteprop2(const char *name, int persist) {
|
||||
if (init_resetprop()) return -1;
|
||||
char path[PATH_MAX];
|
||||
path[0] = '\0';
|
||||
PRINT_D("resetprop: deleteprop [%s]\n", name);
|
||||
LOGD("resetprop: deleteprop [%s]\n", name);
|
||||
if (persist && strncmp(name, "persist.", 8) == 0)
|
||||
persist = persist_deleteprop(name);
|
||||
return __system_property_del(name) && !(persist && strncmp(name, "persist.", 8) == 0);
|
||||
@@ -253,10 +253,10 @@ int deleteprop2(const char *name, int persist) {
|
||||
|
||||
int read_prop_file(const char* filename, const int trigger) {
|
||||
if (init_resetprop()) return -1;
|
||||
PRINT_D("resetprop: Load prop file [%s]\n", filename);
|
||||
LOGD("resetprop: Load prop file [%s]\n", filename);
|
||||
FILE *fp = fopen(filename, "r");
|
||||
if (fp == NULL) {
|
||||
PRINT_E("Cannot open [%s]\n", filename);
|
||||
LOGE("Cannot open [%s]\n", filename);
|
||||
return 1;
|
||||
}
|
||||
char *line = NULL, *pch;
|
||||
@@ -292,7 +292,14 @@ int read_prop_file(const char* filename, const int trigger) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int verbose_logging(const char *fmt, va_list ap) {
|
||||
return prop_verbose ? vfprintf(stderr, fmt, ap) : 0;
|
||||
}
|
||||
|
||||
int resetprop_main(int argc, char *argv[]) {
|
||||
cmdline_logging();
|
||||
log_cb.d = verbose_logging;
|
||||
|
||||
int trigger = 1, persist = 0;
|
||||
char *argv0 = argv[0], *prop;
|
||||
|
||||
|
Reference in New Issue
Block a user