Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include "chromecast/crash/linux/dump_info.h" | 4 #include "chromecast/crash/linux/dump_info.h" |
| 5 | 5 |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/stringprintf.h" | |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 | 14 |
| 14 namespace chromecast { | 15 namespace chromecast { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const char kDumpTimeFormat[] = "%Y-%m-%d %H:%M:%S"; | 19 // "%Y-%m-%d %H:%M:%S"; |
| 19 const unsigned kDumpTimeMaxLen = 255; | 20 const char kDumpTimeFormat[] = "%04d-%02d-%02d %02d:%02d:%02d"; |
| 20 | 21 |
| 21 const int kNumRequiredParams = 5; | 22 const int kNumRequiredParams = 5; |
| 22 | 23 |
| 23 const char kNameKey[] = "name"; | 24 const char kNameKey[] = "name"; |
| 24 const char kDumpTimeKey[] = "dump_time"; | 25 const char kDumpTimeKey[] = "dump_time"; |
| 25 const char kDumpKey[] = "dump"; | 26 const char kDumpKey[] = "dump"; |
| 26 const char kUptimeKey[] = "uptime"; | 27 const char kUptimeKey[] = "uptime"; |
| 27 const char kLogfileKey[] = "logfile"; | 28 const char kLogfileKey[] = "logfile"; |
| 28 const char kSuffixKey[] = "suffix"; | 29 const char kSuffixKey[] = "suffix"; |
| 29 const char kPrevAppNameKey[] = "prev_app_name"; | 30 const char kPrevAppNameKey[] = "prev_app_name"; |
| 30 const char kCurAppNameKey[] = "cur_app_name"; | 31 const char kCurAppNameKey[] = "cur_app_name"; |
| 31 const char kLastAppNameKey[] = "last_app_name"; | 32 const char kLastAppNameKey[] = "last_app_name"; |
| 32 const char kReleaseVersionKey[] = "release_version"; | 33 const char kReleaseVersionKey[] = "release_version"; |
| 33 const char kBuildNumberKey[] = "build_number"; | 34 const char kBuildNumberKey[] = "build_number"; |
| 34 const char kReasonKey[] = "reason"; | 35 const char kReasonKey[] = "reason"; |
| 35 | 36 |
| 36 } // namespace | 37 } // namespace |
| 37 | 38 |
| 38 DumpInfo::DumpInfo(const base::Value* entry) : valid_(ParseEntry(entry)) { | 39 DumpInfo::DumpInfo(const base::Value* entry) : valid_(ParseEntry(entry)) { |
| 39 } | 40 } |
| 40 | 41 |
| 41 DumpInfo::DumpInfo(const std::string& crashed_process_dump, | 42 DumpInfo::DumpInfo(const std::string& crashed_process_dump, |
| 42 const std::string& logfile, | 43 const std::string& logfile, |
| 43 const time_t& dump_time, | 44 const base::Time& dump_time, |
| 44 const MinidumpParams& params) | 45 const MinidumpParams& params) |
| 45 : crashed_process_dump_(crashed_process_dump), | 46 : crashed_process_dump_(crashed_process_dump), |
| 46 logfile_(logfile), | 47 logfile_(logfile), |
| 47 dump_time_(dump_time), | 48 dump_time_(dump_time), |
| 48 params_(params), | 49 params_(params), |
| 49 valid_(false) { | 50 valid_(true) {} |
|
bcf
2016/08/03 02:40:23
This is the only place valid_ is set to false, I t
ameyak
2016/08/03 18:50:32
Acknowledged. Ignored as discussed.
| |
| 50 | |
| 51 // Validate the time passed in. | |
| 52 struct tm* tm = gmtime(&dump_time); | |
| 53 char buf[kDumpTimeMaxLen]; | |
| 54 int n = strftime(buf, kDumpTimeMaxLen, kDumpTimeFormat, tm); | |
| 55 if (n <= 0) { | |
| 56 LOG(INFO) << "strftime failed"; | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 valid_ = true; | |
| 61 } | |
| 62 | 51 |
| 63 DumpInfo::~DumpInfo() { | 52 DumpInfo::~DumpInfo() { |
| 64 } | 53 } |
| 65 | 54 |
| 66 std::unique_ptr<base::Value> DumpInfo::GetAsValue() const { | 55 std::unique_ptr<base::Value> DumpInfo::GetAsValue() const { |
| 67 std::unique_ptr<base::Value> result = | 56 std::unique_ptr<base::Value> result = |
| 68 base::WrapUnique(new base::DictionaryValue()); | 57 base::WrapUnique(new base::DictionaryValue()); |
| 69 base::DictionaryValue* entry; | 58 base::DictionaryValue* entry; |
| 70 result->GetAsDictionary(&entry); | 59 result->GetAsDictionary(&entry); |
| 71 entry->SetString(kNameKey, params_.process_name); | 60 entry->SetString(kNameKey, params_.process_name); |
| 72 | 61 |
| 73 struct tm* tm = gmtime(&dump_time_); | 62 base::Time::Exploded ex; |
| 74 char buf[kDumpTimeMaxLen]; | 63 dump_time_.LocalExplode(&ex); |
| 75 int n = strftime(buf, kDumpTimeMaxLen, kDumpTimeFormat, tm); | 64 std::string dump_time = |
| 76 DCHECK_GT(n, 0); | 65 base::StringPrintf(kDumpTimeFormat, ex.year, ex.month, ex.day_of_month, |
| 77 std::string dump_time(buf); | 66 ex.hour, ex.minute, ex.second); |
| 78 entry->SetString(kDumpTimeKey, dump_time); | 67 entry->SetString(kDumpTimeKey, dump_time); |
| 79 | 68 |
| 80 entry->SetString(kDumpKey, crashed_process_dump_); | 69 entry->SetString(kDumpKey, crashed_process_dump_); |
| 81 std::string uptime = std::to_string(params_.process_uptime); | 70 std::string uptime = std::to_string(params_.process_uptime); |
| 82 entry->SetString(kUptimeKey, uptime); | 71 entry->SetString(kUptimeKey, uptime); |
| 83 entry->SetString(kLogfileKey, logfile_); | 72 entry->SetString(kLogfileKey, logfile_); |
| 84 entry->SetString(kSuffixKey, params_.suffix); | 73 entry->SetString(kSuffixKey, params_.suffix); |
| 85 entry->SetString(kPrevAppNameKey, params_.previous_app_name); | 74 entry->SetString(kPrevAppNameKey, params_.previous_app_name); |
| 86 entry->SetString(kCurAppNameKey, params_.current_app_name); | 75 entry->SetString(kCurAppNameKey, params_.current_app_name); |
| 87 entry->SetString(kLastAppNameKey, params_.last_app_name); | 76 entry->SetString(kLastAppNameKey, params_.last_app_name); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 134 |
| 146 // Disallow extraneous params | 135 // Disallow extraneous params |
| 147 if (dict->size() != num_params) | 136 if (dict->size() != num_params) |
| 148 return false; | 137 return false; |
| 149 | 138 |
| 150 valid_ = true; | 139 valid_ = true; |
| 151 return true; | 140 return true; |
| 152 } | 141 } |
| 153 | 142 |
| 154 bool DumpInfo::SetDumpTimeFromString(const std::string& timestr) { | 143 bool DumpInfo::SetDumpTimeFromString(const std::string& timestr) { |
| 155 struct tm tm = {0}; | 144 base::Time::Exploded ex = {0}; |
| 156 char* text = strptime(timestr.c_str(), kDumpTimeFormat, &tm); | 145 if (sscanf(timestr.c_str(), kDumpTimeFormat, &ex.year, &ex.month, |
| 157 dump_time_ = mktime(&tm); | 146 &ex.day_of_month, &ex.hour, &ex.minute, &ex.second) < 6) { |
| 158 if (!text || dump_time_ < 0) { | |
| 159 LOG(INFO) << "Failed to convert dump time invalid"; | 147 LOG(INFO) << "Failed to convert dump time invalid"; |
| 160 return false; | 148 return false; |
| 161 } | 149 } |
| 150 | |
| 151 dump_time_ = base::Time::FromLocalExploded(ex); | |
| 162 return true; | 152 return true; |
| 163 } | 153 } |
| 164 | 154 |
| 165 } // namespace chromecast | 155 } // namespace chromecast |
| OLD | NEW |