From nobody Sat Nov 30 00:36:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1620756456; cv=none; d=zohomail.com; s=zohoarc; b=aUyO731d6j/WjSVZbi3A+wWfOjqdfdIiYF8MJE1ZDvj65zQ3Hb2g7at4+2qPwyMneOuSL0TkkVL+gDWzrlf285taTi7AlvXoOQc7Mi2ZBOrJz5aLV3QYpdaas5+rSlKGtkVtu/49bamgNVknfSlo7DpaZOeUH2EyVkK7UBvnRz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620756456; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3utvrb3NeUVS0Y4ZwE9lUeEpIUJ+0tlwmh9NC8YSv8s=; b=XWSZtJs8Vy5i58onXKlrSuv/AvrV58N1FyDdxlWse0LfloXF9YVR9EStG8LGzKDRUy2vKaQlPQAu52Cc/RI7vyTyWBPYBpskuhJfVcNRwF6SYfT5QvhYHQBHNSFn3E4MpWNYoRno8g83ViOz79OPHJJt54kJXQsvgj+phd9lqsQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620756456063108.03405533128898; Tue, 11 May 2021 11:07:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125909.237061 (Exim 4.92) (envelope-from ) id 1lgWmv-0003I9-Od; Tue, 11 May 2021 18:07:21 +0000 Received: by outflank-mailman (output) from mailman id 125909.237061; Tue, 11 May 2021 18:07:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lgWmv-0003Ge-Kz; Tue, 11 May 2021 18:07:21 +0000 Received: by outflank-mailman (input) for mailman id 125909; Tue, 11 May 2021 18:07:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lgWmu-0001nY-DX for xen-devel@lists.xenproject.org; Tue, 11 May 2021 18:07:20 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6f8c4a83-831a-40ed-8f89-f3d2965861df; Tue, 11 May 2021 18:07:10 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6f8c4a83-831a-40ed-8f89-f3d2965861df DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620756430; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p0W19jtbXsU+HwGFf/dzsvYLrPw4HfB2Wm1ke3VJSTU=; b=dQMd3S3Sh1uwjZz11L+p0WZJChMX7GaGF7J6k85HWSKjfLzhEFGL5iRL Yo2pTQXXwISgXE6xH9onF5WBFRWYXD/O05R2T/mMB08JTlo4PKp92qirt kR5CB9AWLI4Mm1J6taOI84LMctdfsxRnGVQuOSk2h0nTTgEepL4D5dMTO 4=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: kFob7Ev9G9Y0/Z94owD+Jbmq1srgk7MQRmvTxVjkheEbgfYfIYGrsES29esGjpru6VOo6Ms2Fj hnpvqhiBExUTY88zyv6g5xoAf2Ub94Y3+Olbbof+howte6Bx1X63++ZmL48iyZq5Eo8ATVkWIT +HrnHtJsz+KmkrHR+F/ShE9BNc5cP1J/6P9zyYSSt+w3QgHlhR0SNjy7MKIKQGdoCS0obasASc 5M1yS0iVLBq+bCSgZr4ujmoj5A7RpVUqrdLvyGRCixyUsy+XEDekU8jYHQ2C4c9FoOeZWXeeor b7Y= X-SBRS: 5.1 X-MesageID: 45101013 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:jrcCBa6OcVqvAPVt+QPXwPDXdLJyesId70hD6qhwISY6TiX+rb HWoB17726TtN9/YhEdcLy7VJVoBEmskKKdgrNhWotKPjOW21dARbsKheCJrgEIWReOktK1vZ 0QC5SWY+eQMbEVt6nHCXGDYrQd/OU= X-IronPort-AV: E=Sophos;i="5.82,291,1613451600"; d="scan'208";a="45101013" From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= To: CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , "Christian Lindig" , David Scott , "Ian Jackson" , Wei Liu Subject: [PATCH v2 07/17] tools/ocaml/xenstored: validate config file before live update Date: Tue, 11 May 2021 19:05:20 +0100 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) The configuration file can contain typos or various errors that could preve= nt 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 confi= g file is valid *for the new binary*. Signed-off-by: Edwin T=C3=B6r=C3=B6k --- 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/par= se_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 =3D restart: bool; live_reload: bool; disable_socket: bool; + config_test: bool; } =20 let do_argv () =3D @@ -38,6 +39,7 @@ let do_argv () =3D and restart =3D ref false and live_reload =3D ref false and disable_socket =3D ref false + and config_test =3D ref false in =20 let speclist =3D @@ -55,6 +57,7 @@ let do_argv () =3D ("-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 :=3D true), "D= isable socket"); ] in let usage_msg =3D "usage : xenstored [--config-file ] [--no-dom= ain-init] [--help] [--no-fork] [--reraise-top-level] [--restart] [--disable= -socket]" in @@ -70,4 +73,5 @@ let do_argv () =3D restart =3D !restart; live_reload =3D !live_reload; disable_socket =3D !disable_socket; + config_test =3D !config_test; } diff --git a/tools/ocaml/xenstored/process.ml b/tools/ocaml/xenstored/proce= ss.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 =3D =20 let validate_exn t =3D (* --help must be last to check validity of earlier arguments *) - let t' =3D {t with cmdline=3D t.cmdline @ ["--help"]} in + let t' =3D {t with cmdline=3D t.cmdline @ ["--config-test"]} in let cmd =3D 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/xen= stored.ml index 2aa0dbc0e1..34e706910e 100644 --- a/tools/ocaml/xenstored/xenstored.ml +++ b/tools/ocaml/xenstored/xenstored.ml @@ -88,7 +88,7 @@ let default_pidfile =3D Paths.xen_run_dir ^ "/xenstored.p= id" =20 let ring_scan_interval =3D ref 20 =20 -let parse_config filename =3D +let parse_config ?(strict=3Dfalse) filename =3D let pidfile =3D ref default_pidfile in let options =3D [ ("merge-activate", Config.Set_bool Transaction.do_coalesce); @@ -126,11 +126,12 @@ let parse_config filename =3D ("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 =20 let main () =3D let cf =3D do_argv () in + if cf.config_test then begin + let _pidfile:string =3D parse_config ~strict:true (config_filename cf) = in + exit 0 + end; let pidfile =3D if Sys.file_exists (config_filename cf) then parse_config (config_filename cf) --=20 2.25.1