summaryrefslogtreecommitdiffstats
path: root/hci/src/btsnoop.c
diff options
context:
space:
mode:
authorZach Johnson <zachoverflow@google.com>2015-03-04 14:06:13 -0800
committerAndre Eisenbach <eisenbach@google.com>2015-03-16 16:51:48 -0700
commit04bb236d873005ccb5950cb8e8f1f348499e032e (patch)
treec2237bd95e57b0af23d5ee8d44af4731cf36c76b /hci/src/btsnoop.c
parent1d8e6b8e7fcf6bc691be94a362030915ac15b23b (diff)
downloadandroid_system_bt-04bb236d873005ccb5950cb8e8f1f348499e032e.tar.gz
android_system_bt-04bb236d873005ccb5950cb8e8f1f348499e032e.tar.bz2
android_system_bt-04bb236d873005ccb5950cb8e8f1f348499e032e.zip
Reinstate btsnoop last log saving
Waited for the merge to complete before reworking the feature into the stack.
Diffstat (limited to 'hci/src/btsnoop.c')
-rw-r--r--hci/src/btsnoop.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/hci/src/btsnoop.c b/hci/src/btsnoop.c
index 2d45c1075..5fc309fe5 100644
--- a/hci/src/btsnoop.c
+++ b/hci/src/btsnoop.c
@@ -141,11 +141,20 @@ static void update_logging() {
if (should_log) {
btsnoop_net_open();
- const char *path = stack_config->get_btsnoop_log_path();
- logfile_fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+ const char *log_path = stack_config->get_btsnoop_log_path();
+
+ // Save the old log if configured to do so
+ if (stack_config->get_btsnoop_should_save_last()) {
+ char last_log_path[PATH_MAX];
+ snprintf(last_log_path, PATH_MAX, "%s.last", log_path);
+ if (!rename(log_path, last_log_path) && errno != ENOENT)
+ LOG_ERROR("%s unable to rename '%s' to '%s': %s", __func__, log_path, last_log_path, strerror(errno));
+ }
+ logfile_fd = open(log_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (logfile_fd == INVALID_FD) {
- LOG_ERROR("%s unable to open '%s': %s", __func__, path, strerror(errno));
+ LOG_ERROR("%s unable to open '%s': %s", __func__, log_path, strerror(errno));
+ is_logging = false;
return;
}