Create file if host is running
This file is used by the host start services to know
if they should actually run or not
Change-Id: I62c5af0cd54a40ed272a59871dc26a3e125070a2
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/configure.ac b/configure.ac
index f2cb6ad..b6ee1da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,10 @@
AS_IF([test "x$BMC_OBJPATH" == "x"], [BMC_OBJPATH="/xyz/openbmc_project/state/bmc"])
AC_DEFINE_UNQUOTED([BMC_OBJPATH], ["$BMC_OBJPATH"], [The BMC state manager Dbus root])
+AC_ARG_VAR(HOST_RUNNING_FILE, [File to create if host is running])
+AS_IF([test "x$HOST_RUNNING_FILE" == "x"], [HOST_RUNNING_FILE="/run/openbmc/host@%u-on"])
+AC_DEFINE_UNQUOTED([HOST_RUNNING_FILE], ["$HOST_RUNNING_FILE"], [File to create if host is running])
+
# Check for header files.
AC_CHECK_HEADER(systemd/sd-bus.h, ,[AC_MSG_ERROR([Could not find systemd/sd-bus.h...systemd developement package required])])
AC_CHECK_HEADER(sdbusplus/server.hpp, ,[AC_MSG_ERROR([Could not find sdbusplus/server.hpp...openbmc/sdbusplus package required])])
diff --git a/host_check_main.cpp b/host_check_main.cpp
index 3eab1e3..5645b8e 100644
--- a/host_check_main.cpp
+++ b/host_check_main.cpp
@@ -1,8 +1,12 @@
#include <cstdlib>
#include <unistd.h>
+#include <iostream>
+#include <fstream>
+#include <cstdio>
#include <sdbusplus/bus.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Control/Host/server.hpp>
+#include <config.h>
using namespace std::literals;
using namespace phosphor::logging;
@@ -122,8 +126,18 @@
// If host running then create file
if(hostRunning)
{
- // TODO - Add file creation
log<level::INFO>("Host is running!");
+ // Create file for host instance and create in filesystem to indicate
+ // to services that host is running
+ auto size = std::snprintf(nullptr,0,HOST_RUNNING_FILE,0);
+ std::unique_ptr<char[]> buf(new char[size+1]);
+ std::snprintf(buf.get(),size,HOST_RUNNING_FILE,0);
+ std::ofstream outfile(buf.get());
+ outfile.close();
+ }
+ else
+ {
+ log<level::INFO>("Host is not running!");
}
return 0;