diff options
author | Dan Albert <danalbert@google.com> | 2015-03-19 22:53:30 -0700 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2015-03-20 09:49:15 -0700 |
commit | 8743ef98414b336f222327253f2cde6bf6aee386 (patch) | |
tree | dad722507f4a48fff58f66969ccdfc3a8644a9b6 /adb/adb.cpp | |
parent | 4b8b38f4e5f216f317d9837de49468b32be86984 (diff) | |
download | system_core-8743ef98414b336f222327253f2cde6bf6aee386.zip system_core-8743ef98414b336f222327253f2cde6bf6aee386.tar.gz system_core-8743ef98414b336f222327253f2cde6bf6aee386.tar.bz2 |
Additional cleanup of start_device_log.
Addresses nnk's post commit review comments on
https://android-review.googlesource.com/#/c/139381/
Remove unneeded code for creating /data/adb.
Add an O_CLOEXEC.
Move the closing of stdin out to main().
Append the pid of the current process to the log file to avoid
clobbering the log if the process crashes and restarts within the same
second.
Change-Id: Ide0be86b4b33256486634c29ba02efaf10cf913d
Diffstat (limited to 'adb/adb.cpp')
-rw-r--r-- | adb/adb.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/adb/adb.cpp b/adb/adb.cpp index d37ca36..ad85184 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -79,18 +79,19 @@ void fatal_errno(const char *fmt, ...) #if !ADB_HOST void start_device_log(void) { - adb_mkdir("/data/adb", 0775); - struct tm now; time_t t; tzset(); time(&t); localtime_r(&t, &now); + char timestamp[PATH_MAX]; + strftime(timestamp, sizeof(timestamp), "%Y-%m-%d-%H-%M-%S", &now); + char path[PATH_MAX]; - strftime(path, sizeof(path), "/data/adb/adb-%Y-%m-%d-%H-%M-%S.txt", &now); + snprintf(path, sizeof(path), "/data/adb/adb-%s-%d", timestamp, getpid()); - int fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640); + int fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0640); if (fd == -1) { return; } @@ -100,10 +101,6 @@ void start_device_log(void) { dup2(fd, STDERR_FILENO); fprintf(stderr, "--- adb starting (pid %d) ---\n", getpid()); adb_close(fd); - - fd = unix_open("/dev/null", O_RDONLY); - dup2(fd, 0); - adb_close(fd); } #endif |