Merge "Additional cleanup of start_device_log."
This commit is contained in:
commit
ca2b67e117
2 changed files with 20 additions and 9 deletions
15
adb/adb.cpp
15
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 path[PATH_MAX];
|
||||
strftime(path, sizeof(path), "/data/adb/adb-%Y-%m-%d-%H-%M-%S.txt", &now);
|
||||
char timestamp[PATH_MAX];
|
||||
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d-%H-%M-%S", &now);
|
||||
|
||||
int fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640);
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, sizeof(path), "/data/adb/adb-%s-%d", timestamp, getpid());
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -349,9 +349,23 @@ int adb_main(int is_daemon, int server_port)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if !ADB_HOST
|
||||
void close_stdin() {
|
||||
int fd = unix_open("/dev/null", O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("failed to open /dev/null, stdin will remain open");
|
||||
return;
|
||||
}
|
||||
dup2(fd, 0);
|
||||
adb_close(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
#if ADB_HOST
|
||||
adb_sysdeps_init();
|
||||
#else
|
||||
close_stdin();
|
||||
#endif
|
||||
adb_trace_init();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue