From patchwork Tue May 11 18:05:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?RWR3aW4gVMO2csO2aw==?= X-Patchwork-Id: 12251631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BF18C433B4 for ; Tue, 11 May 2021 18:07:31 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C214961628 for ; Tue, 11 May 2021 18:07:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C214961628 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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?b?RWR3aW4gVMO2csO2aw==?= To: CC: =?utf-8?b?RWR3aW4gVMO2csO2aw==?= , "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 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 --- 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 ] [--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)