| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 4 |
| 5 #include "update_engine/omaha_request_prep_action.h" | 5 #include "update_engine/omaha_request_prep_action.h" |
| 6 #include <sys/utsname.h> | 6 #include <sys/utsname.h> |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "update_engine/simple_key_value_store.h" |
| 10 #include "update_engine/utils.h" | 12 #include "update_engine/utils.h" |
| 11 | 13 |
| 14 using std::map; |
| 12 using std::string; | 15 using std::string; |
| 13 | 16 |
| 14 // This gathers local system information and prepares info used by the | 17 // This gathers local system information and prepares info used by the |
| 15 // update check action. | 18 // update check action. |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 const string OmahaIdPath() { | 21 const string OmahaIdPath() { |
| 19 return string(chromeos_update_engine::utils::kStatefulPartition) + | 22 return string(chromeos_update_engine::utils::kStatefulPartition) + |
| 20 "/etc/omaha_id"; | 23 "/etc/omaha_id"; |
| 21 } | 24 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 string OmahaRequestPrepAction::GetLsbValue( | 98 string OmahaRequestPrepAction::GetLsbValue( |
| 96 const string& key, const string& default_value) const { | 99 const string& key, const string& default_value) const { |
| 97 string files[] = {string(utils::kStatefulPartition) + "/etc/lsb-release", | 100 string files[] = {string(utils::kStatefulPartition) + "/etc/lsb-release", |
| 98 "/etc/lsb-release"}; | 101 "/etc/lsb-release"}; |
| 99 for (unsigned int i = 0; i < arraysize(files); i++) { | 102 for (unsigned int i = 0; i < arraysize(files); i++) { |
| 100 // TODO(adlr): make sure files checked are owned as root (and all | 103 // TODO(adlr): make sure files checked are owned as root (and all |
| 101 // their parents are recursively, too). | 104 // their parents are recursively, too). |
| 102 string file_data; | 105 string file_data; |
| 103 if (!utils::ReadFileToString(root_ + files[i], &file_data)) | 106 if (!utils::ReadFileToString(root_ + files[i], &file_data)) |
| 104 continue; | 107 continue; |
| 105 string::size_type pos = 0; | 108 |
| 106 if (!utils::StringHasPrefix(file_data, key + "=")) { | 109 map<string, string> data = simple_key_value_store::ParseString(file_data); |
| 107 pos = file_data.find(string("\n") + key + "="); | 110 if (utils::MapContainsKey(data, key)) |
| 108 if (pos != string::npos) | 111 return data[key]; |
| 109 pos++; // advance past \n | |
| 110 } | |
| 111 if (pos == string::npos) | |
| 112 continue; | |
| 113 pos += key.size() + 1; // advance past the key and the '=' | |
| 114 string::size_type endpos = file_data.find('\n', pos); | |
| 115 string::size_type length = | |
| 116 (endpos == string::npos ? string::npos : endpos - pos); | |
| 117 return file_data.substr(pos, length); | |
| 118 } | 112 } |
| 119 // not found | 113 // not found |
| 120 return default_value; | 114 return default_value; |
| 121 } | 115 } |
| 122 | 116 |
| 123 string OmahaRequestPrepAction::GetMachineType() const { | 117 string OmahaRequestPrepAction::GetMachineType() const { |
| 124 struct utsname buf; | 118 struct utsname buf; |
| 125 string ret; | 119 string ret; |
| 126 if (uname(&buf) == 0) | 120 if (uname(&buf) == 0) |
| 127 ret = buf.machine; | 121 ret = buf.machine; |
| 128 return ret; | 122 return ret; |
| 129 } | 123 } |
| 130 | 124 |
| 131 } // namespace chromeos_update_engine | 125 } // namespace chromeos_update_engine |
| OLD | NEW |