api: api socket respect unix runtime directory 00/21100/2
authorOle Troan <ot@cisco.com>
Wed, 7 Aug 2019 11:41:39 +0000 (13:41 +0200)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Thu, 8 Aug 2019 11:23:31 +0000 (11:23 +0000)
socksvr {} should respect the unix runtime directory.
Default is now /run/vpp/api.sock
The 'default' keyword is deprecated.
The user is responsible for creating directories outside of the
unix runtime directory.

Not yet done: Exit VPP when socket cannot be opened.
              (currently only process exits).

Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: I6dd66ed58a3d7e02674dfa16d72c1d7bba07b79e

docs/gettingstarted/users/configuring/startup.rst
src/vlibmemory/socket_api.c
src/vlibmemory/socket_api.h
src/vpp-api/python/vpp_papi/vpp_papi.py

index 77f12b2..df96ff7 100644 (file)
@@ -1377,10 +1377,10 @@ If not set, API server doesn't run.
  * **socket-name <filename>**
      Configure API socket filename.
      
-     **Example:** socket-name /run/vpp/vpp-api.sock
+     **Example:** socket-name /run/vpp/api.sock
      
  * **default**
-     Use the default API socket (/run/vpp-api.sock).
+     Use the default API socket (/run/api.sock).
      
      **Example:** default
 
index d3beafb..5aad8a9 100644 (file)
@@ -723,22 +723,6 @@ vl_sock_api_init (vlib_main_t * vm)
   vec_resize (sm->input_buffer, 4096);
 
   sock->config = (char *) sm->socket_name;
-
-  /* mkdir of file socket, only under /run  */
-  if (strncmp (sock->config, "/run", 4) == 0)
-    {
-      u8 *tmp = format (0, "%s", sock->config);
-      int i = vec_len (tmp);
-      while (i && tmp[--i] != '/')
-       ;
-
-      tmp[i] = 0;
-
-      if (i)
-       vlib_unix_recursive_mkdir ((char *) tmp);
-      vec_free (tmp);
-    }
-
   sock->flags = CLIB_SOCKET_F_IS_SERVER | CLIB_SOCKET_F_ALLOW_GROUP_WRITE;
   error = clib_socket_init (sock);
   if (error)
@@ -791,16 +775,21 @@ socksvr_config (vlib_main_t * vm, unformat_input_t * input)
     {
       if (unformat (input, "socket-name %s", &sm->socket_name))
        ;
+      /* DEPRECATE: default keyword is ignored */
       else if (unformat (input, "default"))
-       {
-         sm->socket_name = format (0, "%s%c", API_SOCKET_FILE, 0);
-       }
+       ;
       else
        {
          return clib_error_return (0, "unknown input '%U'",
                                    format_unformat_error, input);
        }
     }
+
+  if (!vec_len (sm->socket_name))
+    sm->socket_name = format (0, "%s/%s", vlib_unix_get_runtime_dir (),
+                             API_SOCKET_FILENAME);
+  vec_terminate_c_string (sm->socket_name);
+
   return 0;
 }
 
index f3af300..7192e0f 100644 (file)
 #include <svm/ssvm.h>
 #include <vppinfra/file.h>
 
-#define API_SOCKET_FILE "/run/vpp-api.sock"
+/* Deprecated */
+#define API_SOCKET_FILE "/run/vpp/api.sock"
+
+#define API_SOCKET_FILENAME "api.sock"
 
 typedef struct
 {
index a4523b4..818a55f 100644 (file)
@@ -191,7 +191,7 @@ class VPPApiClient(object):
     def __init__(self, apifiles=None, testmode=False, async_thread=True,
                  logger=None, loglevel=None,
                  read_timeout=5, use_socket=False,
-                 server_address='/run/vpp-api.sock'):
+                 server_address='/run/vpp/api.sock'):
         """Create a VPP API object.
 
         apifiles is a list of files containing API