Gunnar Mills | a927de4 | 2017-04-06 21:40:50 -0500 | [diff] [blame^] | 1 | #include <iostream> |
| 2 | #include <string> |
| 3 | #include <unistd.h> |
| 4 | #include <sys/wait.h> |
| 5 | #include <phosphor-logging/log.hpp> |
| 6 | #include "config.h" |
Gunnar Mills | 701e021 | 2017-04-03 11:21:27 -0500 | [diff] [blame] | 7 | #include "download_manager.hpp" |
| 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace software |
| 12 | { |
| 13 | namespace manager |
| 14 | { |
| 15 | |
Gunnar Mills | a927de4 | 2017-04-06 21:40:50 -0500 | [diff] [blame^] | 16 | using namespace phosphor::logging; |
| 17 | |
Gunnar Mills | 701e021 | 2017-04-03 11:21:27 -0500 | [diff] [blame] | 18 | void Download::downloadViaTFTP(const std::string fileName, |
| 19 | const std::string serverAddress) |
| 20 | { |
Gunnar Mills | a927de4 | 2017-04-06 21:40:50 -0500 | [diff] [blame^] | 21 | if (fileName.empty()) |
| 22 | { |
| 23 | log<level::ERR>("Error FileName is empty"); |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | if (serverAddress.empty()) |
| 28 | { |
| 29 | log<level::ERR>("Error ServerAddress is empty"); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | log<level::INFO>("Downloading via TFTP", |
| 34 | entry("FILENAME=%s", fileName), |
| 35 | entry("SERVERADDRESS=%s", serverAddress)); |
| 36 | |
| 37 | pid_t pid = fork(); |
| 38 | |
| 39 | if (pid == 0) |
| 40 | { |
| 41 | // child process |
| 42 | execl("/usr/bin/tftp", "tftp", "-g", "-r", fileName.c_str(), |
| 43 | serverAddress.c_str(), "-l", (std::string{IMG_UPLOAD_DIR} + '/' + |
| 44 | fileName).c_str(), (char*)0); |
| 45 | // execl only returns on fail |
| 46 | log<level::ERR>("Error occurred during the TFTP call"); |
| 47 | } |
| 48 | else if (pid < 0) |
| 49 | { |
| 50 | log<level::ERR>("Error occurred during fork"); |
| 51 | } |
| 52 | |
Gunnar Mills | 701e021 | 2017-04-03 11:21:27 -0500 | [diff] [blame] | 53 | return; |
| 54 | } |
| 55 | |
| 56 | } // namespace manager |
| 57 | } // namespace software |
| 58 | } // namespace phosphor |
| 59 | |