meta-google: dhcp-done: Adding status report

Previously dhcp-done only sends status code, this one provides the
capability to send status code + status message for better
troubleshooting.
Provide a way to let other process upgrade the status.

Tested: Unit test passed.

Change-Id: I9c689f90502a32b586c41e3491ad47ebc78fcc38
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
diff --git a/subprojects/dhcp-done/dhcp-done.cpp b/subprojects/dhcp-done/dhcp-done.cpp
index d6c5c96..7ea8761 100644
--- a/subprojects/dhcp-done/dhcp-done.cpp
+++ b/subprojects/dhcp-done/dhcp-done.cpp
@@ -12,6 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#include "file-io.hpp"
+
 #include <sdeventplus/event.hpp>
 #include <sdeventplus/source/io.hpp>
 #include <stdplus/fd/create.hpp>
@@ -23,11 +25,6 @@
 // A privileged port that is reserved for querying BMC DHCP completion.
 // This is well known by the clients querying the status.
 constexpr uint16_t kListenPort = 23;
-enum : uint8_t
-{
-    DONE = 0,
-    POWERCYCLE = 1,
-};
 
 stdplus::ManagedFd createListener()
 {
@@ -43,30 +40,8 @@
     return sock;
 }
 
-int main(int argc, char* argv[])
+int main()
 {
-    if (argc != 2)
-    {
-        stdplus::println(stderr, "Invalid parameter count");
-        return 1;
-    }
-
-    std::vector<uint8_t> data;
-
-    if (argv[1] == "POWERCYCLE"sv)
-    {
-        data.push_back(POWERCYCLE);
-    }
-    else if (argv[1] == "DONE"sv)
-    {
-        data.push_back(DONE);
-    }
-    else
-    {
-        stdplus::println(stderr, "Invalid parameter");
-        return 1;
-    }
-
     try
     {
         auto listener = createListener();
@@ -76,6 +51,20 @@
             [&](sdeventplus::source::IO&, int, uint32_t) {
             while (auto fd = stdplus::fd::accept(listener))
             {
+                std::string data;
+                try
+                {
+                    data = fileRead(statusFile);
+                }
+                catch (const std::exception& e)
+                {
+                    // we don't want to fail the upgrade process, set the status
+                    // to ONGOING
+                    data.push_back(2);
+                    data.append("Failed to read status ");
+                    data.append(e.what());
+                }
+
                 stdplus::fd::sendExact(*fd, data, stdplus::fd::SendFlags(0));
             }
         });