diff options
author | John Estabrook <jestabro@vyos.io> | 2025-07-08 08:01:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-08 08:01:31 -0500 |
commit | 111bfa17c6ab2a983fb22427d55ecf6fd35d4529 (patch) | |
tree | a90f02f02b9d32f404d4dd2991cd433bcca49407 /src/vyconf_cli.ml | |
parent | 97641ae54f7a7bd377caead3b2fe1e6080e8357f (diff) | |
parent | 9ac7c1e3a258c1e41c4c4abd7b45a8f29af7907a (diff) | |
download | vyconf-current.tar.gz vyconf-current.zip |
Merge pull request #24 from jestabro/merge-configcurrent
T7499: allow load from internal representation to avoid re-parsing
Diffstat (limited to 'src/vyconf_cli.ml')
-rw-r--r-- | src/vyconf_cli.ml | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/vyconf_cli.ml b/src/vyconf_cli.ml index ded03df..0d1535e 100644 --- a/src/vyconf_cli.ml +++ b/src/vyconf_cli.ml @@ -29,6 +29,14 @@ let output_format_of_string s = | "json" -> Out_json | _ -> failwith (Printf.sprintf "Unknown output format %s, should be plain or json" s) +let in_cli_config_session () = + let env = Unix.environment () in + let res = Array.find_opt (fun c -> String.starts_with ~prefix:"_OFR_CONFIGURE" c) env + in + match res with + | Some _ -> true + | None -> false + let get_session () = let pid = Int32.of_int (Unix.getppid()) in let socket = "/var/run/vyconfd.sock" in @@ -42,6 +50,13 @@ let get_session () = | Error _ -> setup_session client "vyconf_cli" pid | _ as c -> c |> Lwt.return +let close_session () = + let%lwt client = get_session () in + match client with + | Ok c -> + teardown_session c + | Error e -> Error e |> Lwt.return + let main op path = let%lwt client = get_session () in let%lwt result = @@ -57,6 +72,10 @@ let main op path = end | Error e -> Error e |> Lwt.return in + let () = + if not (in_cli_config_session ()) then + close_session () |> Lwt.ignore_result + in match result with | Ok s -> let%lwt () = Lwt_io.write Lwt_io.stdout s in Lwt.return 0 | Error e -> let%lwt () = Lwt_io.write Lwt_io.stderr (Printf.sprintf "%s\n" e) in Lwt.return 1 |