blob: 434ece9a00ec00b853aabb8e6b47f1b3d948b42b [file] [log] [blame]
Gunnar Millsa927de42017-04-06 21:40:50 -05001#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 Mills701e0212017-04-03 11:21:27 -05007#include "download_manager.hpp"
8
9namespace phosphor
10{
11namespace software
12{
13namespace manager
14{
15
Gunnar Millsa927de42017-04-06 21:40:50 -050016using namespace phosphor::logging;
17
Gunnar Mills701e0212017-04-03 11:21:27 -050018void Download::downloadViaTFTP(const std::string fileName,
19 const std::string serverAddress)
20{
Gunnar Millsa927de42017-04-06 21:40:50 -050021 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 Mills701e0212017-04-03 11:21:27 -050053 return;
54}
55
56} // namespace manager
57} // namespace software
58} // namespace phosphor
59