Make VPP runtime directory configurable
[vpp.git] / src / vlib / unix / main.c
index e31ea81..cb34a89 100644 (file)
@@ -48,6 +48,7 @@
 #include <fcntl.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <unistd.h>
 
 /** Default CLI pager limit is not configured in startup.conf */
 #define UNIX_CLI_DEFAULT_PAGER_LIMIT 100000
@@ -55,6 +56,8 @@
 /** Default CLI history depth if not configured in startup.conf */
 #define UNIX_CLI_DEFAULT_HISTORY 50
 
+char *vlib_default_runtime_dir __attribute__ ((weak));
+char *vlib_default_runtime_dir = "/run/vlib";
 
 unix_main_t unix_main;
 
@@ -313,6 +316,7 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
 {
   unix_main_t *um = &unix_main;
   clib_error_t *error = 0;
+  gid_t gid;
 
   /* Defaults */
   um->cli_pager_buffer_limit = UNIX_CLI_DEFAULT_PAGER_LIMIT;
@@ -330,6 +334,8 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
       else
        if (unformat (input, "cli-listen %s", &um->cli_listen_socket.config))
        ;
+      else if (unformat (input, "runtime-dir %s", &um->runtime_dir))
+       ;
       else if (unformat (input, "cli-line-mode"))
        um->cli_line_mode = 1;
       else if (unformat (input, "cli-no-banner"))
@@ -404,6 +410,11 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
              vec_free (lv);
            }
        }
+      else if (unformat (input, "gid %U", unformat_unix_gid, &gid))
+       {
+         if (setegid (gid) == -1)
+           return clib_error_return_unix (0, "setegid");
+       }
       else
        return clib_error_return (0, "unknown input `%U'",
                                  format_unformat_error, input);
@@ -425,6 +436,9 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
     }
   um->unix_config_complete = 1;
 
+  if (um->runtime_dir == 0)
+    um->runtime_dir = format (0, "%s%c", vlib_default_runtime_dir, 0);
+
   return 0;
 }
 
@@ -456,6 +470,10 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
  * Ask the Linux kernel to dump all memory-mapped address regions, instead
  * of just text+data+bss.
  *
+ * @cfgcmd{runtime-dir}
+ * Define directory where VPP is going to store all runtime files.
+ * Default is /run/vpp.
+ *
  * @cfgcmd{cli-listen, &lt;address:port&gt;}
  * Bind the CLI to listen at the address and port given. @clocalhost
  * on TCP port @c 5002, given as <tt>cli-listen localhost:5002</tt>,
@@ -482,7 +500,7 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
  * Limit pager buffer to @c nn lines of output.
  * A value of @c 0 disables the pager. Default value: @c 100000
 ?*/
-VLIB_CONFIG_FUNCTION (unix_config, "unix");
+VLIB_EARLY_CONFIG_FUNCTION (unix_config, "unix");
 
 static clib_error_t *
 unix_exit (vlib_main_t * vm)