Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 1 | #include "config.h" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 2 | |
| 3 | #include "image_manager.hpp" |
| 4 | |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 5 | #include "version.hpp" |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 6 | #include "watch.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <sys/wait.h> |
| 12 | #include <unistd.h> |
| 13 | |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 14 | #include <elog-errors.hpp> |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 15 | #include <phosphor-logging/elog.hpp> |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 16 | #include <phosphor-logging/lg2.hpp> |
Adriana Kobylak | 43699ca | 2018-10-17 14:56:29 -0500 | [diff] [blame] | 17 | #include <xyz/openbmc_project/Software/Image/error.hpp> |
Gunnar Mills | e91d321 | 2017-04-19 15:42:47 -0500 | [diff] [blame] | 18 | |
Adriana Kobylak | 58aa750 | 2020-06-08 11:12:11 -0500 | [diff] [blame] | 19 | #include <algorithm> |
| 20 | #include <cstring> |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 21 | #include <ctime> |
Adriana Kobylak | 58aa750 | 2020-06-08 11:12:11 -0500 | [diff] [blame] | 22 | #include <filesystem> |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 23 | #include <random> |
Adriana Kobylak | 58aa750 | 2020-06-08 11:12:11 -0500 | [diff] [blame] | 24 | #include <string> |
| 25 | |
Gunnar Mills | e91d321 | 2017-04-19 15:42:47 -0500 | [diff] [blame] | 26 | namespace phosphor |
| 27 | { |
| 28 | namespace software |
| 29 | { |
| 30 | namespace manager |
| 31 | { |
| 32 | |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 33 | PHOSPHOR_LOG2_USING; |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 34 | using namespace phosphor::logging; |
Adriana Kobylak | 43699ca | 2018-10-17 14:56:29 -0500 | [diff] [blame] | 35 | using namespace sdbusplus::xyz::openbmc_project::Software::Image::Error; |
Gunnar Mills | b30cadd | 2017-10-06 16:07:32 -0500 | [diff] [blame] | 36 | namespace Software = phosphor::logging::xyz::openbmc_project::Software; |
Adriana Kobylak | 43699ca | 2018-10-17 14:56:29 -0500 | [diff] [blame] | 37 | using ManifestFail = Software::Image::ManifestFileFailure; |
| 38 | using UnTarFail = Software::Image::UnTarFailure; |
| 39 | using InternalFail = Software::Image::InternalFailure; |
Adriana Kobylak | 447d0da | 2021-03-15 13:40:52 -0500 | [diff] [blame] | 40 | using ImageFail = Software::Image::ImageFailure; |
Adriana Kobylak | c98d912 | 2020-05-05 10:36:01 -0500 | [diff] [blame] | 41 | namespace fs = std::filesystem; |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 42 | |
| 43 | struct RemovablePath |
| 44 | { |
| 45 | fs::path path; |
| 46 | |
Lei YU | 0cd6d84 | 2021-12-27 11:56:02 +0800 | [diff] [blame] | 47 | explicit RemovablePath(const fs::path& path) : path(path) |
Adriana Kobylak | 58aa750 | 2020-06-08 11:12:11 -0500 | [diff] [blame] | 48 | {} |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 49 | ~RemovablePath() |
| 50 | { |
Lei YU | 5d93028 | 2019-03-08 16:41:51 +0800 | [diff] [blame] | 51 | if (!path.empty()) |
Adriana Kobylak | 2b2cd9f | 2018-02-12 16:20:13 -0600 | [diff] [blame] | 52 | { |
Lei YU | 5d93028 | 2019-03-08 16:41:51 +0800 | [diff] [blame] | 53 | std::error_code ec; |
| 54 | fs::remove_all(path, ec); |
Adriana Kobylak | 2b2cd9f | 2018-02-12 16:20:13 -0600 | [diff] [blame] | 55 | } |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 56 | } |
| 57 | }; |
| 58 | |
Lei YU | f6144e9 | 2019-10-18 17:13:49 +0800 | [diff] [blame] | 59 | namespace // anonymous |
| 60 | { |
| 61 | |
| 62 | std::vector<std::string> getSoftwareObjects(sdbusplus::bus::bus& bus) |
| 63 | { |
| 64 | std::vector<std::string> paths; |
| 65 | auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 66 | MAPPER_INTERFACE, "GetSubTreePaths"); |
| 67 | method.append(SOFTWARE_OBJPATH); |
| 68 | method.append(0); // Depth 0 to search all |
| 69 | method.append(std::vector<std::string>({VERSION_BUSNAME})); |
| 70 | auto reply = bus.call(method); |
| 71 | reply.read(paths); |
| 72 | return paths; |
| 73 | } |
| 74 | |
| 75 | } // namespace |
| 76 | |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 77 | int Manager::processImage(const std::string& tarFilePath) |
Gunnar Mills | e91d321 | 2017-04-19 15:42:47 -0500 | [diff] [blame] | 78 | { |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 79 | if (!fs::is_regular_file(tarFilePath)) |
| 80 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 81 | error("Tarball {PATH} does not exist", "PATH", tarFilePath); |
Gunnar Mills | b30cadd | 2017-10-06 16:07:32 -0500 | [diff] [blame] | 82 | report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str())); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 83 | return -1; |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 84 | } |
| 85 | RemovablePath tarPathRemove(tarFilePath); |
| 86 | fs::path tmpDirPath(std::string{IMG_UPLOAD_DIR}); |
| 87 | tmpDirPath /= "imageXXXXXX"; |
Lei YU | 5d93028 | 2019-03-08 16:41:51 +0800 | [diff] [blame] | 88 | auto tmpDir = tmpDirPath.string(); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 89 | |
Lei YU | 5d93028 | 2019-03-08 16:41:51 +0800 | [diff] [blame] | 90 | // Create a tmp dir to extract tarball. |
| 91 | if (!mkdtemp(tmpDir.data())) |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 92 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 93 | error("Error ({ERRNO}) occurred during mkdtemp", "ERRNO", errno); |
Gunnar Mills | b30cadd | 2017-10-06 16:07:32 -0500 | [diff] [blame] | 94 | report<InternalFailure>(InternalFail::FAIL("mkdtemp")); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 95 | return -1; |
| 96 | } |
| 97 | |
Lei YU | 5d93028 | 2019-03-08 16:41:51 +0800 | [diff] [blame] | 98 | tmpDirPath = tmpDir; |
| 99 | RemovablePath tmpDirToRemove(tmpDirPath); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 100 | fs::path manifestPath = tmpDirPath; |
| 101 | manifestPath /= MANIFEST_FILE_NAME; |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 102 | |
Lei YU | 5d93028 | 2019-03-08 16:41:51 +0800 | [diff] [blame] | 103 | // Untar tarball into the tmp dir |
| 104 | auto rc = unTar(tarFilePath, tmpDirPath.string()); |
| 105 | if (rc < 0) |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 106 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 107 | error("Error ({RC}) occurred during untar", "RC", rc); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | // Verify the manifest file |
| 112 | if (!fs::is_regular_file(manifestPath)) |
| 113 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 114 | error("No manifest file {PATH}", "PATH", tarFilePath); |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 115 | report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str())); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | // Get version |
| 120 | auto version = Version::getValue(manifestPath.string(), "version"); |
| 121 | if (version.empty()) |
| 122 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 123 | error("Unable to read version from manifest file {PATH}", "PATH", |
| 124 | tarFilePath); |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 125 | report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str())); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 126 | return -1; |
| 127 | } |
| 128 | |
Vijay Khemka | b7c062e | 2019-09-18 17:15:57 -0700 | [diff] [blame] | 129 | // Get running machine name |
| 130 | std::string currMachine = Version::getBMCMachine(OS_RELEASE_FILE); |
| 131 | if (currMachine.empty()) |
| 132 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 133 | auto path = OS_RELEASE_FILE; |
| 134 | error("Failed to read machine name from osRelease: {PATH}", "PATH", |
| 135 | path); |
Adriana Kobylak | 447d0da | 2021-03-15 13:40:52 -0500 | [diff] [blame] | 136 | report<ImageFailure>(ImageFail::FAIL("Failed to read machine name"), |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 137 | ImageFail::PATH(path)); |
Vijay Khemka | b7c062e | 2019-09-18 17:15:57 -0700 | [diff] [blame] | 138 | return -1; |
| 139 | } |
| 140 | |
| 141 | // Get machine name for image to be upgraded |
| 142 | std::string machineStr = |
| 143 | Version::getValue(manifestPath.string(), "MachineName"); |
| 144 | if (!machineStr.empty()) |
| 145 | { |
| 146 | if (machineStr != currMachine) |
| 147 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 148 | error( |
| 149 | "BMC upgrade: Machine name doesn't match: {CURRENT_MACHINE} vs {NEW_MACHINE}", |
| 150 | "CURRENT_MACHINE", currMachine, "NEW_MACHINE", machineStr); |
Adriana Kobylak | 447d0da | 2021-03-15 13:40:52 -0500 | [diff] [blame] | 151 | report<ImageFailure>( |
| 152 | ImageFail::FAIL("Machine name does not match"), |
| 153 | ImageFail::PATH(manifestPath.string().c_str())); |
Vijay Khemka | b7c062e | 2019-09-18 17:15:57 -0700 | [diff] [blame] | 154 | return -1; |
| 155 | } |
| 156 | } |
| 157 | else |
| 158 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 159 | warning("No machine name in Manifest file"); |
Adriana Kobylak | 447d0da | 2021-03-15 13:40:52 -0500 | [diff] [blame] | 160 | report<ImageFailure>( |
| 161 | ImageFail::FAIL("MANIFEST is missing machine name"), |
| 162 | ImageFail::PATH(manifestPath.string().c_str())); |
Vijay Khemka | b7c062e | 2019-09-18 17:15:57 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 165 | // Get purpose |
| 166 | auto purposeString = Version::getValue(manifestPath.string(), "purpose"); |
| 167 | if (purposeString.empty()) |
| 168 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 169 | error("Unable to read purpose from manifest file {PATH}", "PATH", |
| 170 | tarFilePath); |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 171 | report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str())); |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 172 | return -1; |
| 173 | } |
| 174 | |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 175 | auto convertedPurpose = |
| 176 | sdbusplus::message::convert_from_string<Version::VersionPurpose>( |
| 177 | purposeString); |
| 178 | |
| 179 | if (!convertedPurpose) |
Gunnar Mills | b30cadd | 2017-10-06 16:07:32 -0500 | [diff] [blame] | 180 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 181 | error( |
| 182 | "Failed to convert manifest purpose ({PURPOSE}) to enum; setting to Unknown.", |
| 183 | "PURPOSE", purposeString); |
Gunnar Mills | b30cadd | 2017-10-06 16:07:32 -0500 | [diff] [blame] | 184 | } |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 185 | auto purpose = convertedPurpose.value_or(Version::VersionPurpose::Unknown); |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 186 | |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 187 | // Get ExtendedVersion |
| 188 | std::string extendedVersion = |
| 189 | Version::getValue(manifestPath.string(), "ExtendedVersion"); |
| 190 | |
Justin Ledford | 054bb0b | 2022-03-15 15:46:58 -0700 | [diff] [blame^] | 191 | // Get CompatibleNames |
| 192 | std::vector<std::string> compatibleNames = |
| 193 | Version::getRepeatedValues(manifestPath.string(), "CompatibleName"); |
| 194 | |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 195 | // Compute id |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 196 | auto salt = std::to_string(randomGen()); |
| 197 | auto id = Version::getId(version + salt); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 198 | |
| 199 | fs::path imageDirPath = std::string{IMG_UPLOAD_DIR}; |
| 200 | imageDirPath /= id; |
| 201 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 202 | auto objPath = std::string{SOFTWARE_OBJPATH} + '/' + id; |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 203 | |
Lei YU | f6144e9 | 2019-10-18 17:13:49 +0800 | [diff] [blame] | 204 | // This service only manages the uploaded versions, and there could be |
| 205 | // active versions on D-Bus that is not managed by this service. |
| 206 | // So check D-Bus if there is an existing version. |
| 207 | auto allSoftwareObjs = getSoftwareObjects(bus); |
| 208 | auto it = |
| 209 | std::find(allSoftwareObjs.begin(), allSoftwareObjs.end(), objPath); |
| 210 | if (versions.find(id) == versions.end() && it == allSoftwareObjs.end()) |
Saqib Khan | d377ba1 | 2017-10-16 14:32:30 -0500 | [diff] [blame] | 211 | { |
selvaganapathim | 3ea1e87 | 2021-09-09 22:55:30 +0530 | [diff] [blame] | 212 | // Rename the temp dir to image dir |
| 213 | fs::rename(tmpDirPath, imageDirPath); |
| 214 | // Clear the path, so it does not attemp to remove a non-existing path |
| 215 | tmpDirToRemove.path.clear(); |
| 216 | |
Lei YU | f6144e9 | 2019-10-18 17:13:49 +0800 | [diff] [blame] | 217 | // Create Version object |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 218 | auto versionPtr = std::make_unique<Version>( |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 219 | bus, objPath, version, purpose, extendedVersion, |
Justin Ledford | 054bb0b | 2022-03-15 15:46:58 -0700 | [diff] [blame^] | 220 | imageDirPath.string(), compatibleNames, |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 221 | std::bind(&Manager::erase, this, std::placeholders::_1), id); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 222 | versionPtr->deleteObject = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 223 | std::make_unique<phosphor::software::manager::Delete>(bus, objPath, |
| 224 | *versionPtr); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 225 | versions.insert(std::make_pair(id, std::move(versionPtr))); |
Saqib Khan | d377ba1 | 2017-10-16 14:32:30 -0500 | [diff] [blame] | 226 | } |
| 227 | else |
| 228 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 229 | info("Software Object with the same version ({VERSION}) already exists", |
| 230 | "VERSION", id); |
Saqib Khan | d377ba1 | 2017-10-16 14:32:30 -0500 | [diff] [blame] | 231 | } |
Gunnar Mills | e91d321 | 2017-04-19 15:42:47 -0500 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
Leonel Gonzalez | 50d559c | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 235 | void Manager::erase(std::string entryId) |
| 236 | { |
| 237 | auto it = versions.find(entryId); |
| 238 | if (it == versions.end()) |
| 239 | { |
| 240 | return; |
| 241 | } |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 242 | |
Leonel Gonzalez | 50d559c | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 243 | // Delete image dir |
| 244 | fs::path imageDirPath = (*(it->second)).path(); |
| 245 | if (fs::exists(imageDirPath)) |
| 246 | { |
| 247 | fs::remove_all(imageDirPath); |
| 248 | } |
| 249 | this->versions.erase(entryId); |
| 250 | } |
| 251 | |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 252 | int Manager::unTar(const std::string& tarFilePath, |
| 253 | const std::string& extractDirPath) |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 254 | { |
| 255 | if (tarFilePath.empty()) |
| 256 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 257 | error("TarFilePath is empty"); |
Gunnar Mills | b30cadd | 2017-10-06 16:07:32 -0500 | [diff] [blame] | 258 | report<UnTarFailure>(UnTarFail::PATH(tarFilePath.c_str())); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 259 | return -1; |
| 260 | } |
| 261 | if (extractDirPath.empty()) |
| 262 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 263 | error("ExtractDirPath is empty"); |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 264 | report<UnTarFailure>(UnTarFail::PATH(extractDirPath.c_str())); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 265 | return -1; |
| 266 | } |
| 267 | |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 268 | info("Untaring {PATH} to {EXTRACTIONDIR}", "PATH", tarFilePath, |
| 269 | "EXTRACTIONDIR", extractDirPath); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 270 | int status = 0; |
| 271 | pid_t pid = fork(); |
| 272 | |
| 273 | if (pid == 0) |
| 274 | { |
| 275 | // child process |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 276 | execl("/bin/tar", "tar", "-xf", tarFilePath.c_str(), "-C", |
| 277 | extractDirPath.c_str(), (char*)0); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 278 | // execl only returns on fail |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 279 | error("Failed to execute untar on {PATH}", "PATH", tarFilePath); |
Gunnar Mills | b30cadd | 2017-10-06 16:07:32 -0500 | [diff] [blame] | 280 | report<UnTarFailure>(UnTarFail::PATH(tarFilePath.c_str())); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 281 | return -1; |
| 282 | } |
| 283 | else if (pid > 0) |
| 284 | { |
| 285 | waitpid(pid, &status, 0); |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 286 | if (WEXITSTATUS(status)) |
| 287 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 288 | error("Failed ({STATUS}) to untar file {PATH}", "STATUS", status, |
| 289 | "PATH", tarFilePath); |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 290 | report<UnTarFailure>(UnTarFail::PATH(tarFilePath.c_str())); |
| 291 | return -1; |
| 292 | } |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 293 | } |
| 294 | else |
| 295 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 296 | error("fork() failed: {ERRNO}", "ERRNO", errno); |
Gunnar Mills | b30cadd | 2017-10-06 16:07:32 -0500 | [diff] [blame] | 297 | report<UnTarFailure>(UnTarFail::PATH(tarFilePath.c_str())); |
Gunnar Mills | 19e4ce5 | 2017-04-27 11:24:19 -0500 | [diff] [blame] | 298 | return -1; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
Gunnar Mills | 3027bba | 2017-04-27 15:49:03 -0500 | [diff] [blame] | 303 | |
Gunnar Mills | e91d321 | 2017-04-19 15:42:47 -0500 | [diff] [blame] | 304 | } // namespace manager |
| 305 | } // namespace software |
Gunnar Mills | fa34e02 | 2018-09-04 10:05:45 -0500 | [diff] [blame] | 306 | } // namespace phosphor |