net/local: Add an option to specify the prefix of named pipe

to avoid the user create socket under the real filesystem
which isn't supported by nuttx VFS yet.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ib04c90e9c3c5a215bfda65515498d81e5f834895
This commit is contained in:
Xiang Xiao 2021-02-05 12:29:26 +08:00 committed by David Sidrane
parent 96d4bc11c0
commit 1a9267db65
2 changed files with 16 additions and 6 deletions

View File

@ -15,6 +15,12 @@ config NET_LOCAL
if NET_LOCAL if NET_LOCAL
config NET_LOCAL_PATH_PREFIX
string "Path prefix to Unix domain sockets"
default "/var/socket"
---help---
The path prefix to where Unix domain sockets will exist in the VFS namespace.
config NET_LOCAL_STREAM config NET_LOCAL_STREAM
bool "Unix domain stream sockets" bool "Unix domain stream sockets"
default y default y

View File

@ -83,12 +83,14 @@ static inline void local_cs_name(FAR struct local_conn_s *conn,
{ {
if (conn->lc_instance_id < 0) if (conn->lc_instance_id < 0)
{ {
snprintf(path, LOCAL_FULLPATH_LEN - 1, "%s" LOCAL_CS_SUFFIX, snprintf(path, LOCAL_FULLPATH_LEN - 1,
CONFIG_NET_LOCAL_PATH_PREFIX "%s" LOCAL_CS_SUFFIX,
conn->lc_path); conn->lc_path);
} }
else else
{ {
snprintf(path, LOCAL_FULLPATH_LEN - 1, "%s" LOCAL_CS_SUFFIX "%" PRIx32, snprintf(path, LOCAL_FULLPATH_LEN - 1,
CONFIG_NET_LOCAL_PATH_PREFIX "%s" LOCAL_CS_SUFFIX "%" PRIx32,
conn->lc_path, conn->lc_instance_id); conn->lc_path, conn->lc_instance_id);
} }
@ -110,12 +112,14 @@ static inline void local_sc_name(FAR struct local_conn_s *conn,
{ {
if (conn->lc_instance_id < 0) if (conn->lc_instance_id < 0)
{ {
snprintf(path, LOCAL_FULLPATH_LEN - 1, "%s" LOCAL_SC_SUFFIX, snprintf(path, LOCAL_FULLPATH_LEN - 1,
CONFIG_NET_LOCAL_PATH_PREFIX "%s" LOCAL_SC_SUFFIX,
conn->lc_path); conn->lc_path);
} }
else else
{ {
snprintf(path, LOCAL_FULLPATH_LEN - 1, "%s" LOCAL_SC_SUFFIX "%" PRIx32, snprintf(path, LOCAL_FULLPATH_LEN - 1,
CONFIG_NET_LOCAL_PATH_PREFIX "%s" LOCAL_SC_SUFFIX "%" PRIx32,
conn->lc_path, conn->lc_instance_id); conn->lc_path, conn->lc_instance_id);
} }
@ -134,8 +138,8 @@ static inline void local_sc_name(FAR struct local_conn_s *conn,
#ifdef CONFIG_NET_LOCAL_DGRAM #ifdef CONFIG_NET_LOCAL_DGRAM
static inline void local_hd_name(FAR const char *inpath, FAR char *outpath) static inline void local_hd_name(FAR const char *inpath, FAR char *outpath)
{ {
snprintf(outpath, LOCAL_FULLPATH_LEN - 1, "%s" LOCAL_HD_SUFFIX, snprintf(outpath, LOCAL_FULLPATH_LEN - 1,
inpath); CONFIG_NET_LOCAL_PATH_PREFIX "%s" LOCAL_HD_SUFFIX, inpath);
outpath[LOCAL_FULLPATH_LEN - 1] = '\0'; outpath[LOCAL_FULLPATH_LEN - 1] = '\0';
} }
#endif /* CONFIG_NET_LOCAL_DGRAM */ #endif /* CONFIG_NET_LOCAL_DGRAM */