srvcfg: Updated for dynamic service/socket mgmt

Fixed srvcfg crash manager issue, by doing the service &
socket unit file queries dynamically and exposing the objects
to be controlled. This takes care of instanced service &
socket files like phosphor-ipmi-net@eth0 or
phosphor-ipmi-net@eth1 dynamically.

Tested:
1. Verified as per the base service name, all the instanced
service & socket names are dynamically queried and exposed
2. Made sure to list the disabled services thorugh this method
3. Made sure new services listed after fw-update are also
exposed as objects
4. Verfied phosphor-ipmi-net@eth0 port change using ipmitool
-p <newport> option
5. Verified permanent disable of the unit.
6. Verified run time enable / disable of the service.
7. Verified phosphor-ipmi-kcs service permanent & run time
enable / disable

Change-Id: Ib933a2fbff73eae4348a5940d350ae7972db03fb
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/inc/srvcfg_manager.hpp b/inc/srvcfg_manager.hpp
index 8979f78..8974b29 100644
--- a/inc/srvcfg_manager.hpp
+++ b/inc/srvcfg_manager.hpp
@@ -26,43 +26,80 @@
     "xyz.openbmc_project.Control.Service.Manager";

 static constexpr const char *serviceConfigIntfName =

     "xyz.openbmc_project.Control.Service.Attributes";

+static constexpr const char *srcCfgMgrBasePath =

+    "/xyz/openbmc_project/control/service";

+static constexpr const char *srvCfgPropPort = "Port";

+static constexpr const char *srvCfgPropMasked = "Masked";

+static constexpr const char *srvCfgPropEnabled = "Enabled";

+static constexpr const char *srvCfgPropRunning = "Running";

 

 enum class UpdatedProp

 {

     port = 1,

-    channel,

-    state

+    maskedState,

+    enabledState,

+    runningState

 };

 

+using VariantType =

+    std::variant<std::string, int64_t, uint64_t, double, int32_t, uint32_t,

+                 int16_t, uint16_t, uint8_t, bool,

+                 std::vector<std::tuple<std::string, std::string>>>;

+

 class ServiceConfig

 {

   public:

     ServiceConfig(sdbusplus::asio::object_server &srv_,

                   std::shared_ptr<sdbusplus::asio::connection> &conn_,

-                  std::string objPath_, std::string unitName);

+                  const std::string &objPath_, const std::string &baseUnitName,

+                  const std::string &instanceName,

+                  const std::string &serviceObjPath,

+                  const std::string &socketObjPath);

     ~ServiceConfig() = default;

 

-    void applySystemDServiceConfig();

-    void startServiceRestartTimer();

-

     std::shared_ptr<sdbusplus::asio::connection> conn;

     uint8_t updatedFlag;

 

+    void stopAndApplyUnitConfig(boost::asio::yield_context yield);

+    void restartUnitConfig(boost::asio::yield_context yield);

+    void startServiceRestartTimer();

+

   private:

     sdbusplus::asio::object_server &server;

+    std::shared_ptr<sdbusplus::asio::dbus_interface> iface;

+    bool internalSet = false;

     std::string objPath;

+    std::string instanceName;

+    std::string baseUnitName;

+    std::string instantiatedUnitName;

+    std::string socketObjectPath;

+    std::string serviceObjectPath;

+    std::string overrideConfDir;

 

+    // Properties

+    std::string activeState;

+    std::string subState;

     uint16_t portNum;

+    std::vector<std::string> channelList;

     std::string protocol;

     std::string stateValue;

-    std::vector<std::string> channelList;

+    bool unitMaskedState = false;

+    bool unitEnabledState = false;

+    bool unitRunningState = false;

+    std::string subStateValue;

 

+    bool isMaskedOut();

     void registerProperties();

-    std::string sysDUnitName;

-    std::string unitSocketFilePath;

-    std::string sysDSockObjPath;

-

-    void syncWithSystemD1Properties();

+    void queryAndUpdateProperties();

+    void createSocketOverrideConf();

+    void updateServiceProperties(

+        const boost::container::flat_map<std::string, VariantType>

+            &propertyMap);

+    void updateSocketProperties(

+        const boost::container::flat_map<std::string, VariantType>

+            &propertyMap);

+    std::string getSocketUnitName();

+    std::string getServiceUnitName();

 };

 

 } // namespace service

diff --git a/inc/utils.hpp b/inc/utils.hpp
index 27e66f3..5f01d44 100644
--- a/inc/utils.hpp
+++ b/inc/utils.hpp
@@ -23,18 +23,41 @@
 #include <experimental/filesystem>

 #include <boost/asio.hpp>

 

-static constexpr const char *sysdActionStartUnit = "StartUnit";

-static constexpr const char *sysdActionStopUnit = "StopUnit";

+static constexpr const char *sysdStartUnit = "StartUnit";

+static constexpr const char *sysdStopUnit = "StopUnit";

+static constexpr const char *sysdRestartUnit = "RestartUnit";

+static constexpr const char *sysdReloadMethod = "Reload";

+static constexpr const char *sysdGetJobMethod = "GetJob";

+static constexpr const char *sysdReplaceMode = "replace";

+static constexpr const char *dBusGetAllMethod = "GetAll";

+static constexpr const char *dBusGetMethod = "Get";

+static constexpr const char *sysdService = "org.freedesktop.systemd1";

+static constexpr const char *sysdObjPath = "/org/freedesktop/systemd1";

+static constexpr const char *sysdMgrIntf = "org.freedesktop.systemd1.Manager";

+static constexpr const char *sysdUnitIntf = "org.freedesktop.systemd1.Unit";

+static constexpr const char *sysdSocketIntf = "org.freedesktop.systemd1.Socket";

+static constexpr const char *dBusPropIntf = "org.freedesktop.DBus.Properties";

+static constexpr const char *stateMasked = "masked";

+static constexpr const char *stateEnabled = "enabled";

+static constexpr const char *stateDisabled = "disabled";

+static constexpr const char *subStateRunning = "running";

+

+static inline std::string addInstanceName(const std::string &instanceName,

+                                          const std::string &suffix)

+{

+    return (instanceName.empty() ? "" : suffix + instanceName);

+}

 

 void systemdDaemonReload(

-    const std::shared_ptr<sdbusplus::asio::connection> &conn);

+    const std::shared_ptr<sdbusplus::asio::connection> &conn,

+    boost::asio::yield_context yield);

 

 void systemdUnitAction(const std::shared_ptr<sdbusplus::asio::connection> &conn,

+                       boost::asio::yield_context yield,

                        const std::string &unitName,

                        const std::string &actionMethod);

 

 void systemdUnitFilesStateChange(

     const std::shared_ptr<sdbusplus::asio::connection> &conn,

-    const std::vector<std::string> &unitFiles, const std::string &unitState);

-

-bool checkSystemdUnitExist(const std::string &unitName);

+    boost::asio::yield_context yield, const std::vector<std::string> &unitFiles,

+    const std::string &unitState, bool maskedState, bool enabledState);