system/corennnnn
リビジョン | 1f546e6d1f6ccd1964336ddf0d8e8b3b11b1e945 (tree) |
---|---|
日時 | 2009-05-26 07:17:55 |
作者 | Mike Lockwood <lockwood@andr...> |
コミッター | Mike Lockwood |
adb: Allow enabling of device side adbd logging with a persistent system property.
To enable logging, set the property persist.adb.trace_mask to a hex value
containing the bitmask for adb_trace_mask (see the TRACE_* enum values in adb.h).
This will result in adb writing log output to a file in /data/adb/
No logging will occur if persist.adb.trace_mask is not set or has a value
that cannot be parsed as a hex integer.
The property is read once only at startup, so you must reboot or restart adbd
for changes in the property to take effect.
Signed-off-by: Mike Lockwood <lockwood@android.com>
@@ -23,6 +23,7 @@ | ||
23 | 23 | #include <errno.h> |
24 | 24 | #include <string.h> |
25 | 25 | #include <time.h> |
26 | +#include <sys/time.h> | |
26 | 27 | |
27 | 28 | #include "sysdeps.h" |
28 | 29 | #include "adb.h" |
@@ -657,10 +658,25 @@ void start_logging(void) | ||
657 | 658 | void start_device_log(void) |
658 | 659 | { |
659 | 660 | int fd; |
660 | - char path[100]; | |
661 | + char path[PATH_MAX]; | |
662 | + struct tm now; | |
663 | + time_t t; | |
664 | + char value[PROPERTY_VALUE_MAX]; | |
665 | + | |
666 | + // read the trace mask from persistent property persist.adb.trace_mask | |
667 | + // give up if the property is not set or cannot be parsed | |
668 | + property_get("persist.adb.trace_mask", value, ""); | |
669 | + if (sscanf(value, "%x", &adb_trace_mask) != 1) | |
670 | + return; | |
661 | 671 | |
662 | - snprintf(path, sizeof path, "/data/adb_%ld.txt", (long)time(NULL)); | |
663 | - fd = unix_open(path, O_WRONLY | O_CREAT | O_APPEND, 0640); | |
672 | + adb_mkdir("/data/adb", 0775); | |
673 | + tzset(); | |
674 | + time(&t); | |
675 | + localtime_r(&t, &now); | |
676 | + strftime(path, sizeof(path), | |
677 | + "/data/adb/adb-%Y-%m-%d-%H-%M-%S.txt", | |
678 | + &now); | |
679 | + fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640); | |
664 | 680 | if (fd < 0) |
665 | 681 | return; |
666 | 682 |
@@ -671,11 +687,6 @@ void start_device_log(void) | ||
671 | 687 | |
672 | 688 | fd = unix_open("/dev/null", O_RDONLY); |
673 | 689 | dup2(fd, 0); |
674 | - | |
675 | - // log everything | |
676 | - adb_trace_mask = ~0; | |
677 | - // except TRACE_RWX is a bit too verbose | |
678 | - adb_trace_mask &= ~TRACE_RWX; | |
679 | 690 | } |
680 | 691 | #endif |
681 | 692 |
@@ -1079,9 +1090,8 @@ int main(int argc, char **argv) | ||
1079 | 1090 | adb_device_banner = "recovery"; |
1080 | 1091 | recovery_mode = 1; |
1081 | 1092 | } |
1082 | -#if ADB_DEVICE_LOG | |
1093 | + | |
1083 | 1094 | start_device_log(); |
1084 | -#endif | |
1085 | 1095 | return adb_main(0); |
1086 | 1096 | #endif |
1087 | 1097 | } |
@@ -345,11 +345,6 @@ typedef enum { | ||
345 | 345 | #endif |
346 | 346 | |
347 | 347 | |
348 | -/* set this to log to /data/adb/adb_<time>.txt on the device. | |
349 | - * has no effect if the /data/adb/ directory does not exist. | |
350 | - */ | |
351 | -#define ADB_DEVICE_LOG 0 | |
352 | - | |
353 | 348 | #if !TRACE_PACKETS |
354 | 349 | #define print_packet(tag,p) do {} while (0) |
355 | 350 | #endif |