[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 07/17] tools/ocaml/xenstored: validate config file before live update


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Edwin Török <edvin.torok@xxxxxxxxxx>
  • Date: Tue, 11 May 2021 19:05:20 +0100
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Edwin Török <edvin.torok@xxxxxxxxxx>, "Christian Lindig" <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, "Ian Jackson" <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 11 May 2021 18:07:21 +0000
  • Ironport-hdrordr: A9a23:jrcCBa6OcVqvAPVt+QPXwPDXdLJyesId70hD6qhwISY6TiX+rb HWoB17726TtN9/YhEdcLy7VJVoBEmskKKdgrNhWotKPjOW21dARbsKheCJrgEIWReOktK1vZ 0QC5SWY+eQMbEVt6nHCXGDYrQd/OU=
  • Ironport-sdr: kFob7Ev9G9Y0/Z94owD+Jbmq1srgk7MQRmvTxVjkheEbgfYfIYGrsES29esGjpru6VOo6Ms2Fj hnpvqhiBExUTY88zyv6g5xoAf2Ub94Y3+Olbbof+howte6Bx1X63++ZmL48iyZq5Eo8ATVkWIT +HrnHtJsz+KmkrHR+F/ShE9BNc5cP1J/6P9zyYSSt+w3QgHlhR0SNjy7MKIKQGdoCS0obasASc 5M1yS0iVLBq+bCSgZr4ujmoj5A7RpVUqrdLvyGRCixyUsy+XEDekU8jYHQ2C4c9FoOeZWXeeor b7Y=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The configuration file can contain typos or various errors that could prevent
live update from succeeding (e.g. a flag only valid on a different version).
Unknown entries in the config file would be ignored on startup normally,
add a strict --config-test that live-update can use to check that the config 
file
is valid *for the new binary*.

Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
---
 tools/ocaml/xenstored/parse_arg.ml | 4 ++++
 tools/ocaml/xenstored/process.ml   | 2 +-
 tools/ocaml/xenstored/xenstored.ml | 9 +++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/tools/ocaml/xenstored/parse_arg.ml 
b/tools/ocaml/xenstored/parse_arg.ml
index 965cb9ebeb..588970825f 100644
--- a/tools/ocaml/xenstored/parse_arg.ml
+++ b/tools/ocaml/xenstored/parse_arg.ml
@@ -26,6 +26,7 @@ type config =
        restart: bool;
        live_reload: bool;
        disable_socket: bool;
+       config_test: bool;
 }
 
 let do_argv () =
@@ -38,6 +39,7 @@ let do_argv () =
        and restart = ref false
        and live_reload = ref false
        and disable_socket = ref false
+       and config_test = ref false
        in
 
        let speclist =
@@ -55,6 +57,7 @@ let do_argv () =
                  ("-T", Arg.Set_string tracefile, ""); (* for compatibility *)
                  ("--restart", Arg.Set restart, "Read database on starting");
                  ("--live", Arg.Set live_reload, "Read live dump on startup");
+                 ("--config-test", Arg.Set config_test, "Test validity of 
config file");
                  ("--disable-socket", Arg.Unit (fun () -> disable_socket := 
true), "Disable socket");
                ] in
        let usage_msg = "usage : xenstored [--config-file <filename>] 
[--no-domain-init] [--help] [--no-fork] [--reraise-top-level] [--restart] 
[--disable-socket]" in
@@ -70,4 +73,5 @@ let do_argv () =
                restart = !restart;
                live_reload = !live_reload;
                disable_socket = !disable_socket;
+               config_test = !config_test;
        }
diff --git a/tools/ocaml/xenstored/process.ml b/tools/ocaml/xenstored/process.ml
index 27790d4a5c..d573c88685 100644
--- a/tools/ocaml/xenstored/process.ml
+++ b/tools/ocaml/xenstored/process.ml
@@ -121,7 +121,7 @@ let launch_exn t =
 
 let validate_exn t =
        (* --help must be last to check validity of earlier arguments *)
-       let t' = {t with cmdline= t.cmdline @ ["--help"]} in
+       let t' = {t with cmdline= t.cmdline @ ["--config-test"]} in
        let cmd = string_of_t t' in
        debug "Executing %s" cmd ;
        match Unix.fork () with
diff --git a/tools/ocaml/xenstored/xenstored.ml 
b/tools/ocaml/xenstored/xenstored.ml
index 2aa0dbc0e1..34e706910e 100644
--- a/tools/ocaml/xenstored/xenstored.ml
+++ b/tools/ocaml/xenstored/xenstored.ml
@@ -88,7 +88,7 @@ let default_pidfile = Paths.xen_run_dir ^ "/xenstored.pid"
 
 let ring_scan_interval = ref 20
 
-let parse_config filename =
+let parse_config ?(strict=false) filename =
        let pidfile = ref default_pidfile in
        let options = [
                ("merge-activate", Config.Set_bool Transaction.do_coalesce);
@@ -126,11 +126,12 @@ let parse_config filename =
                ("xenstored-port", Config.Set_string Domains.xenstored_port); ] 
in
        begin try Config.read filename options (fun _ _ -> raise Not_found)
        with
-       | Config.Error err -> List.iter (fun (k, e) ->
+       | Config.Error err as e -> List.iter (fun (k, e) ->
                match e with
                | "unknown key" -> eprintf "config: unknown key %s\n" k
                | _             -> eprintf "config: %s: %s\n" k e
                ) err;
+               if strict then raise e
        | Sys_error m -> eprintf "error: config: %s\n" m;
        end;
        !pidfile
@@ -408,6 +409,10 @@ end
 
 let main () =
        let cf = do_argv () in
+       if cf.config_test then begin
+         let _pidfile:string = parse_config ~strict:true (config_filename cf) 
in
+         exit 0
+       end;
        let pidfile =
                if Sys.file_exists (config_filename cf) then
                        parse_config (config_filename cf)
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.