From 554ac72db109a04b2d53843bc75aa80965d22546 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Sun, 29 Jun 2025 01:47:05 -0500 Subject: T7374: close session to avoid stale data --- src/vyconf_cli.ml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/vyconf_cli.ml') 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 -- cgit v1.2.3