This patch for bug 1832 will do the following:
1.  If /run/dpdk is not present, it will create it first with and
    then create powermanager directory underneath it.
2.  If /run/dpdk is present, it will verify it is actually a directory
    before creating subdirectory, powermanager.

All directory permissions are 0700.

Signed-off-by: Sudheendra Sampath <[email protected]>
---
 examples/vm_power_manager/channel_manager.c | 27 ++++++++++++++++++++-
 examples/vm_power_manager/channel_manager.h |  2 +-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/examples/vm_power_manager/channel_manager.c 
b/examples/vm_power_manager/channel_manager.c
index b69449c61d..60d767ea98 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -420,8 +420,33 @@ add_all_channels(const char *vm_name)
        if (d == NULL) {
                RTE_LOG(ERR, CHANNEL_MANAGER, "Error opening directory '%s': 
%s\n",
                                CHANNEL_MGR_SOCKET_PATH, strerror(errno));
-               return -1;
+
+               const char *run_dpdk = "/run/dpdk";
+               struct stat path_stat;
+               int ret;
+
+               if (stat(run_dpdk, &path_stat) != 0) {
+                       ret = mkdir(run_dpdk, 0700);
+                       if (ret < 0 && errno != EEXIST) {
+                               RTE_LOG(ERR, CHANNEL_MANAGER, "Error creating 
'%s': %s",
+                                               run_dpdk, strerror(errno));
+                               return -1;
+                       }
+               }
+
+               /* Make sure /run/dpdk is a directory */
+               if (!S_ISDIR(path_stat.st_mode)) {
+                       return -1;
+               }
+
+               ret = mkdir(CHANNEL_MGR_SOCKET_PATH, 0700);
+               if (ret < 0 && errno != EEXIST) {
+                       RTE_LOG(ERR, CHANNEL_MANAGER, "Error creating '%s': %s",
+                               CHANNEL_MGR_SOCKET_PATH, strerror(errno));
+                       return -1;
+               }
        }
+
        while ((dir = readdir(d)) != NULL) {
                if (!strncmp(dir->d_name, ".", 1) ||
                                !strncmp(dir->d_name, "..", 2))
diff --git a/examples/vm_power_manager/channel_manager.h 
b/examples/vm_power_manager/channel_manager.h
index 6f70539815..5fc93ae0be 100644
--- a/examples/vm_power_manager/channel_manager.h
+++ b/examples/vm_power_manager/channel_manager.h
@@ -22,7 +22,7 @@ extern "C" {
 #define CHANNEL_MGR_DEFAULT_HV_PATH "qemu:///system"
 
 /* File socket directory */
-#define CHANNEL_MGR_SOCKET_PATH     "/tmp/powermonitor/"
+#define CHANNEL_MGR_SOCKET_PATH     "/run/dpdk/powermonitor/"
 
 /* FIFO file name template */
 #define CHANNEL_MGR_FIFO_PATTERN_NAME   "fifo"
-- 
2.43.0

Reply via email to