apphandler: Add "System Name" System Info parameter

Use the BMC's hostname to respond to requests for the "System Name"
parameter.

Signed-off-by: Xo Wang <xow@google.com>
Change-Id: I23845aab6091a0d003b6f8370d2b67fc11e580e8
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/apphandler.cpp b/apphandler.cpp
index 7f16b1f..4a2f2da 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -10,10 +10,12 @@
 #include "utils.hpp"
 
 #include <arpa/inet.h>
+#include <limits.h>
 #include <mapper.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <systemd/sd-bus.h>
+#include <unistd.h>
 
 #include "host-ipmid/ipmid-api.h"
 
@@ -635,6 +637,17 @@
 
 static std::unique_ptr<SysInfoParamStore> sysInfoParamStore;
 
+static std::string sysInfoReadSystemName()
+{
+    // Use the BMC hostname as the "System Name."
+    char hostname[HOST_NAME_MAX + 1] = {};
+    if (gethostname(hostname, HOST_NAME_MAX) != 0)
+    {
+        perror("System info parameter: system name");
+    }
+    return hostname;
+}
+
 struct IpmiSysInfoResp
 {
     uint8_t paramRevision;
@@ -764,6 +777,8 @@
     if (sysInfoParamStore == nullptr)
     {
         sysInfoParamStore = std::make_unique<SysInfoParamStore>();
+        sysInfoParamStore->update(IPMI_SYSINFO_SYSTEM_NAME,
+                                  sysInfoReadSystemName);
     }
 
     // Parameters other than Set In Progress are assumed to be strings.