summaryrefslogtreecommitdiffstats
path: root/src/framework
diff options
context:
space:
mode:
authorrainbow_0206 <jiangwenjiang@huawei.com>2018-08-09 15:07:30 +0800
committerrainbow_0206 <jiangwenjiang@huawei.com>2018-08-21 17:55:59 +0800
commit1c690bb23570b5ef3d8e1de683e5ae67e8e24304 (patch)
tree3b9530c49fb35e1a345035f2e7a215909eadb01e /src/framework
parent941b368b03f2fc26538bba3e7e4c9c36841b3456 (diff)
Fix: check whether the domain path exist
Change-Id: Id7cbbe7d5179f8854afcd3801f0f6acdf9f2a37c Signed-off-by: rainbow_0206 <jiangwenjiang@huawei.com>
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/common/base/liblinuxapi/nsfw_lock_file.c7
-rw-r--r--src/framework/include/nsfw_mgr_com_api.h2
-rw-r--r--src/framework/ipc/mgr_com/mgr_com.c102
-rw-r--r--src/framework/ipc/mgr_com/mgr_com.h4
4 files changed, 79 insertions, 36 deletions
diff --git a/src/framework/common/base/liblinuxapi/nsfw_lock_file.c b/src/framework/common/base/liblinuxapi/nsfw_lock_file.c
index 0ec196f..abfbfd1 100644
--- a/src/framework/common/base/liblinuxapi/nsfw_lock_file.c
+++ b/src/framework/common/base/liblinuxapi/nsfw_lock_file.c
@@ -94,13 +94,6 @@ nsfw_proc_start_with_lock (u8 proc_type)
return -1;
}
- ret = STRCAT_S (lock_fpath, NSFW_FILE_PATH_LEN, LOCK_FOLDER);
- if (EOK != ret)
- {
- NSFW_LOGERR ("lock init STRCAT_S failed]ret=%d", ret);
- return -1;
- }
-
ret = STRCAT_S (lock_fpath, NSFW_FILE_PATH_LEN, module_name);
if (EOK != ret)
{
diff --git a/src/framework/include/nsfw_mgr_com_api.h b/src/framework/include/nsfw_mgr_com_api.h
index 094043e..56ec08f 100644
--- a/src/framework/include/nsfw_mgr_com_api.h
+++ b/src/framework/include/nsfw_mgr_com_api.h
@@ -107,7 +107,7 @@ typedef enum _fw_poc_type
NSFW_PROC_MAX = 16
} fw_poc_type;
-#define NSFW_DOMAIN_DIR "/var/run"
+#define NSFW_DOMAIN_DIR "/var/log/nStack/ip_module/"
#define NSTACK_MAX_PROC_NAME_LEN 20
typedef enum _nsfw_mgr_msg_rsp_code
diff --git a/src/framework/ipc/mgr_com/mgr_com.c b/src/framework/ipc/mgr_com/mgr_com.c
index 2b35e2c..bc2aca2 100644
--- a/src/framework/ipc/mgr_com/mgr_com.c
+++ b/src/framework/ipc/mgr_com/mgr_com.c
@@ -32,6 +32,7 @@
#include <stddef.h>
#include <sys/epoll.h>
#include <fcntl.h>
+#include <sys/stat.h>
#include "nsfw_maintain_api.h"
#include "nsfw_ps_api.h"
@@ -320,8 +321,9 @@ nsfw_mgr_msg_free (nsfw_mgr_msg * msg)
i32
nsfw_mgr_get_listen_socket ()
{
- i32 fd, len;
+ i32 fd, len, retVal;
struct sockaddr_un un;
+ char name[NSFW_MGRCOM_PATH_LEN] = { 0 };
if ((fd = nsfw_base_socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
{
@@ -329,7 +331,23 @@ nsfw_mgr_get_listen_socket ()
return -1;
}
- if (-1 == unlink ((char *) g_mgr_com_cfg.domain_path))
+ retVal = STRCPY_S ((char *) name, sizeof (name),
+ (char *) g_mgr_com_cfg.domain_path);
+ if (EOK != retVal)
+ {
+ (void) nsfw_base_close (fd);
+ NSFW_LOGERR ("module mgr get listen STRCPY_S failed! ret=%d", retVal);
+ return -1;
+ }
+
+ if (EOK != STRCAT_S (name, NSFW_MGRCOM_PATH_LEN, NSFW_MAIN_FILE))
+ {
+ (void) nsfw_base_close (fd);
+ NSFW_LOGERR ("module mgr get listen STRCAT_S failed!");
+ return -1;
+ }
+
+ if (-1 == unlink ((char *) name))
{
NSFW_LOGWAR ("unlink failed]error=%d", errno);
}
@@ -341,8 +359,8 @@ nsfw_mgr_get_listen_socket ()
}
un.sun_family = AF_UNIX;
- int retVal = STRCPY_S ((char *) un.sun_path, sizeof (un.sun_path),
- (char *) g_mgr_com_cfg.domain_path);
+ retVal = STRCPY_S ((char *) un.sun_path, sizeof (un.sun_path),
+ (char *) name);
if (EOK != retVal)
{
(void) nsfw_base_close (fd);
@@ -358,9 +376,7 @@ nsfw_mgr_get_listen_socket ()
return -1;
}
- len =
- offsetof (struct sockaddr_un,
- sun_path) +strlen ((char *) g_mgr_com_cfg.domain_path);
+ len = offsetof (struct sockaddr_un, sun_path) +strlen ((char *) name);
if (nsfw_base_bind (fd, (struct sockaddr *) &un, len) < 0)
{
@@ -1807,6 +1823,58 @@ nsfw_mgr_comm_fd_init (u32 proc_type)
}
/*****************************************************************************
+* Prototype : nsfw_mgr_com_mkdir_domainpath
+* Description : check whether the domain path exist.if not exist, create it.
+* Input : char *pathname
+* Output : None
+* Return Value : void
+* Calls :
+* Called By :
+*****************************************************************************/
+void nsfw_mgr_com_mkdir_domainpath (char *pathname);
+void
+nsfw_mgr_com_mkdir_domainpath (char *pathname)
+{
+ char dirname[NSFW_MGRCOM_PATH_LEN] = { 0 };
+ int i, len;
+
+ if (NULL == pathname)
+ {
+ NSFW_LOGERR ("the pathname is null.");
+ return;
+ }
+
+ strncpy (dirname, pathname, NSFW_MGRCOM_PATH_LEN - 1);
+ len = strlen (dirname);
+ if (dirname[len - 1] != '/')
+ strncat (dirname, "/", 2);
+
+ if (access (dirname, F_OK) == 0)
+ return;
+
+ len = strlen (dirname);
+
+ for (i = 1; i < len; i++)
+ {
+ if (dirname[i] == '/')
+ {
+ dirname[i] = 0;
+ if (access (dirname, F_OK) != 0)
+ {
+ if (mkdir (dirname, 0755) == -1)
+ {
+ NSFW_LOGERR ("mkdir:%s error", dirname);
+ return;
+ }
+ }
+ dirname[i] = '/';
+ }
+ }
+
+ return;
+}
+
+/*****************************************************************************
* Prototype : nsfw_mgr_com_module_init
* Description : module init
* Input : void* param
@@ -1849,15 +1917,7 @@ nsfw_mgr_com_module_init (void *param)
return -1;
}
- /* modify destMax, remove "-1" */
- if (EOK !=
- STRCAT_S (mgr_cfg->domain_path, NSFW_MGRCOM_PATH_LEN,
- NSFW_MAIN_FILE))
- {
- NSFW_LOGERR ("module mgr init STRCAT_S failed!");
- lint_unlock_1 ();
- return -1;
- }
+ nsfw_mgr_com_mkdir_domainpath (mgr_cfg->domain_path);
NSFW_LOGINF ("module mgr init]NSFW_PROC_MAIN domain_path=%s",
mgr_cfg->domain_path);
@@ -1880,16 +1940,6 @@ nsfw_mgr_com_module_init (void *param)
return -1;
}
- /* modify destMax, remove "-1" */
- if (EOK !=
- STRCAT_S (mgr_cfg->domain_path, NSFW_MGRCOM_PATH_LEN,
- NSFW_MASTER_FILE))
- {
- NSFW_LOGERR ("module mgr init STRCAT_S failed!");
- lint_unlock_1 ();
- return -1;
- }
-
NSFW_LOGINF ("module mgr init]NSFW_PROC_MASTER domain_path=%s",
mgr_cfg->domain_path);
diff --git a/src/framework/ipc/mgr_com/mgr_com.h b/src/framework/ipc/mgr_com/mgr_com.h
index 02e46c1..03f58c8 100644
--- a/src/framework/ipc/mgr_com/mgr_com.h
+++ b/src/framework/ipc/mgr_com/mgr_com.h
@@ -52,8 +52,8 @@ extern "C"{
#define MGR_COM_RECV_TIMEOUT (g_mgr_com_cfg.max_recv_timeout)
#define MGR_COM_MAX_DROP_MSG (g_mgr_com_cfg.max_recv_drop_msg)
-#define NSFW_MAIN_FILE "/ip_module/nStackMainMgr"
-#define NSFW_MASTER_FILE "/ip_module/nStackMasterMgr"
+#define NSFW_MAIN_FILE "nStackMainMgr"
+#define NSFW_MASTER_FILE "nStackMasterMgr"
#define NSFW_ALARM_FILE "/HuskyAlarm.domain"
#define NSFW_MGRCOM_THREAD "nStackMgrCom"