aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/memif
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2018-07-31 12:25:23 +0200
committerDave Barach <openvpp@barachs.net>2018-07-31 14:05:41 +0000
commit15c3a6ad8094aeec6bbb78845d25050aabb82f4d (patch)
tree2638ae39155006d3367cbfbe29abada9e24ef650 /src/plugins/memif
parent937c089ab72fad238774cc6829d2b6d167c25683 (diff)
memif: socket filename fix
create runtime dir when adding default socket filename. Change-Id: Iad7e751fcab7ce773e0907302414a06ea44dd6cd Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Diffstat (limited to 'src/plugins/memif')
-rw-r--r--src/plugins/memif/memif.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index 0299e95ad60..b04929401f3 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -621,10 +621,11 @@ int
memif_socket_filename_add_del (u8 is_add, u32 sock_id, u8 * sock_filename)
{
struct stat file_stat;
- char *dir = 0;
+ char *dir = 0, *tmp;
u32 idx = 0;
- if (sock_id == 0 || sock_id == ~0)
+ /* allow adding socket id 0 */
+ if ((sock_id == 0 && is_add == 0) || sock_id == ~0)
{
return VNET_API_ERROR_INVALID_ARGUMENT;
}
@@ -646,11 +647,17 @@ memif_socket_filename_add_del (u8 is_add, u32 sock_id, u8 * sock_filename)
/* copy runtime dir path */
vec_add (dir, vlib_unix_get_runtime_dir (),
strlen (vlib_unix_get_runtime_dir ()));
+ vec_add1 (dir, '/');
/* if sock_filename contains dirs, add them to path */
- idx = strrchr ((char *) sock_filename, '/') - (char *) sock_filename;
- vec_add (dir, sock_filename, idx);
+ tmp = strrchr ((char *) sock_filename, '/');
+ if (tmp)
+ {
+ idx = tmp - (char *) sock_filename;
+ vec_add (dir, sock_filename, idx);
+ }
+ vec_add1 (dir, '\0');
/* create socket dir */
error = vlib_unix_recursive_mkdir (dir);
if (error)
@@ -667,8 +674,13 @@ memif_socket_filename_add_del (u8 is_add, u32 sock_id, u8 * sock_filename)
sock_filename = vec_dup (sock_filename);
/* check if directory exists */
- idx = strrchr ((char *) sock_filename, '/') - (char *) sock_filename;
- vec_add (dir, sock_filename, idx);
+ tmp = strrchr ((char *) sock_filename, '/');
+ if (tmp)
+ {
+ idx = tmp - (char *) sock_filename;
+ vec_add (dir, sock_filename, idx);
+ vec_add1 (dir, '\0');
+ }
if (((stat (dir, &file_stat) == -1) || (!S_ISDIR (file_stat.st_mode)))
&& (idx != 0))
@@ -1007,7 +1019,6 @@ static clib_error_t *
memif_init (vlib_main_t * vm)
{
memif_main_t *mm = &memif_main;
- u8 *filename;
memset (mm, 0, sizeof (memif_main_t));
@@ -1022,10 +1033,7 @@ memif_init (vlib_main_t * vm)
* for socket-id 0 to MEMIF_DEFAULT_SOCKET_FILENAME in the
* default run-time directory.
*/
- filename = format (0, "%s/%s%c",
- vlib_unix_get_runtime_dir (),
- MEMIF_DEFAULT_SOCKET_FILENAME, 0);
- memif_add_socket_file (0, filename);
+ memif_socket_filename_add_del (1, 0, (u8 *) MEMIF_DEFAULT_SOCKET_FILENAME);
return 0;
}