vlib: add 'use-current-dir' knob to unix {} conf 98/42898/3
authorDamjan Marion <[email protected]>
Fri, 25 Apr 2025 20:01:40 +0000 (22:01 +0200)
committerMohammed HAWARI <[email protected]>
Mon, 28 Apr 2025 09:59:34 +0000 (09:59 +0000)
...to tell vpp to stay in current dir.

Type: improvement
Change-Id: I50813908fbe8bfe81f86c641a2bacc52bfe3122d
Signed-off-by: Damjan Marion <[email protected]>
src/vlib/unix/main.c

index 5841451..cd1f1e1 100644 (file)
@@ -386,6 +386,7 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
   clib_error_t *error = 0;
   gid_t gid;
   int pidfd = -1;
+  int use_current_dir = 0;
 
   /* Defaults */
   um->cli_pager_buffer_limit = UNIX_CLI_DEFAULT_PAGER_LIMIT;
@@ -409,6 +410,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, "use-current-dir"))
+       use_current_dir = 1;
       else if (unformat (input, "runtime-dir %s", &um->runtime_dir))
        ;
       else if (unformat (input, "cli-line-mode"))
@@ -498,6 +501,13 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
                                  format_unformat_error, input);
     }
 
+  if (use_current_dir)
+    {
+      char cwd[PATH_MAX];
+      if (getcwd (cwd, PATH_MAX))
+       um->runtime_dir = format (um->runtime_dir, "%s", cwd);
+    }
+
   if (um->runtime_dir == 0)
     {
       uid_t uid = geteuid ();