| 23 | } |
| 24 | |
| 25 | bool cmLDConfigLDConfigTool::GetLDConfigPaths(std::vector<std::string>& paths) |
| 26 | { |
| 27 | std::string ldConfigPath = |
| 28 | this->Archive->GetMakefile()->GetSafeDefinition("CMAKE_LDCONFIG_COMMAND"); |
| 29 | if (ldConfigPath.empty()) { |
| 30 | ldConfigPath = cmSystemTools::FindProgram( |
| 31 | "ldconfig", { "/sbin", "/usr/sbin", "/usr/local/sbin" }); |
| 32 | if (ldConfigPath.empty()) { |
| 33 | this->Archive->SetError("Could not find ldconfig"); |
| 34 | return false; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | cmList ldConfigCommand{ ldConfigPath }; |
| 39 | ldConfigCommand.emplace_back("-v"); |
| 40 | ldConfigCommand.emplace_back("-N"); // Don't rebuild the cache. |
| 41 | ldConfigCommand.emplace_back("-X"); // Don't update links. |
| 42 | |
| 43 | cmUVProcessChainBuilder builder; |
| 44 | builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT) |
| 45 | .AddCommand(ldConfigCommand); |
| 46 | auto process = builder.Start(); |
| 47 | if (!process.Valid() || process.GetStatus(0).SpawnResult != 0) { |
| 48 | this->Archive->SetError("Failed to start ldconfig process"); |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | std::string line; |
| 53 | static cmsys::RegularExpression const regex("^([^\t:]*):"); |
| 54 | cmUVIStream output(process.OutputStream()); |
| 55 | while (std::getline(output, line)) { |
| 56 | cmsys::RegularExpressionMatch match; |
| 57 | if (regex.find(line.c_str(), match)) { |
| 58 | paths.push_back(match.match(1)); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (!process.Wait()) { |
| 63 | this->Archive->SetError("Failed to wait on ldconfig process"); |
| 64 | return false; |
| 65 | } |
| 66 | if (process.GetStatus(0).ExitStatus != 0) { |
| 67 | this->Archive->SetError("Failed to run ldconfig"); |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | return true; |
| 72 | } |
no test coverage detected