| 4857 | } |
| 4858 | |
| 4859 | std::string SystemInformationImplementation::ParseValueFromKStat( |
| 4860 | char const* arguments) |
| 4861 | { |
| 4862 | std::vector<std::string> args_string; |
| 4863 | std::string command = arguments; |
| 4864 | size_t start = std::string::npos; |
| 4865 | size_t pos = command.find(' ', 0); |
| 4866 | while (pos != std::string::npos) { |
| 4867 | bool inQuotes = false; |
| 4868 | // Check if we are between quotes |
| 4869 | size_t b0 = command.find('"', 0); |
| 4870 | size_t b1 = command.find('"', b0 + 1); |
| 4871 | while (b0 != std::string::npos && b1 != std::string::npos && b1 > b0) { |
| 4872 | if (pos > b0 && pos < b1) { |
| 4873 | inQuotes = true; |
| 4874 | break; |
| 4875 | } |
| 4876 | b0 = command.find('"', b1 + 1); |
| 4877 | b1 = command.find('"', b0 + 1); |
| 4878 | } |
| 4879 | |
| 4880 | if (!inQuotes) { |
| 4881 | args_string.push_back(command.substr(start + 1, pos - start - 1)); |
| 4882 | std::string& arg = args_string.back(); |
| 4883 | |
| 4884 | // Remove the quotes if any |
| 4885 | arg.erase(std::remove(arg.begin(), arg.end(), '"'), arg.end()); |
| 4886 | start = pos; |
| 4887 | } |
| 4888 | pos = command.find(' ', pos + 1); |
| 4889 | } |
| 4890 | command.erase(0, start + 1); |
| 4891 | args_string.push_back(command); |
| 4892 | |
| 4893 | std::vector<char const*> args; |
| 4894 | args.reserve(3 + args_string.size()); |
| 4895 | args.push_back("kstat"); |
| 4896 | args.push_back("-p"); |
| 4897 | for (auto const& i : args_string) { |
| 4898 | args.push_back(i.c_str()); |
| 4899 | } |
| 4900 | args.push_back(nullptr); |
| 4901 | |
| 4902 | std::string buffer = this->RunProcess(args); |
| 4903 | |
| 4904 | std::string value; |
| 4905 | for (size_t i = buffer.size() - 1; i > 0; i--) { |
| 4906 | if (buffer[i] == ' ' || buffer[i] == '\t') { |
| 4907 | break; |
| 4908 | } |
| 4909 | if (buffer[i] != '\n' && buffer[i] != '\r') { |
| 4910 | value.insert(0u, 1, buffer[i]); |
| 4911 | } |
| 4912 | } |
| 4913 | return value; |
| 4914 | } |
| 4915 | |
| 4916 | /** Querying for system information from Solaris */ |