From patchwork Tue Jun 14 12:46:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9175769 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E7E5260573 for ; Tue, 14 Jun 2016 12:48:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7FE5265F9 for ; Tue, 14 Jun 2016 12:48:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCF2C28047; Tue, 14 Jun 2016 12:48:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 32B9F265F9 for ; Tue, 14 Jun 2016 12:48:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCnjf-0000nj-Qq; Tue, 14 Jun 2016 12:46:27 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCnje-0000nc-Rx for xen-devel@lists.xenproject.org; Tue, 14 Jun 2016 12:46:26 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id D4/D1-06230-2ACFF575; Tue, 14 Jun 2016 12:46:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRWlGSWpSXmKPExsXitHSDve7CP/H hBv3X9Sy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozHh2exFVwRrui8f421gfE8bxcjJ4eEgL9E +7Q3bCA2i4CqxM/fb1lBbDYBZYmfnb1gcREBbYkXq9aB2cwCvhKbr14DqxEWiJZYOK2BEcTmF dCXmNA5D6iGi0NIYBOjxKp1d5kgEoISJ2c+YYFo1pFYsPsTUBEHkC0tsfwfB0iYU8BRYtqSY2 AlogIqElcmvGUHsYUEFCQ6ph9jgriTW+L26anMExj5ZyGZOgvJ1FkIUxcwMq9iVC9OLSpLLdI 11ksqykzPKMlNzMzRNTQw08tNLS5OTE/NSUwq1kvOz93ECAxABiDYwdjxz+kQoyQHk5Io7+2J 8eFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHjn/QbKCRalpqdWpGXmAGMBJi3BwaMkwssFjAch3 uKCxNzizHSI1ClGRSlx3uUgfQIgiYzSPLg2WPxdYpSVEuZlBDpEiKcgtSg3swRV/hWjOAejkj BvFMgUnsy8Erjpr4AWMwEttpkOtrgkESEl1cAY8e7WXeZrjZaF736LiDTefH2g/MG5H5fleA/ Gz/wgf7yjx0fw3vHqO7+YfKx+VF7PqdmoeWnm4anOp3/qnDv84/mKarNQ3ZhniZFNvfK6GyPP 3hHdvLTGZF9/CY/U9y0Huq9On30v7Q6Hdf3KTykJi9/e8ebRrvGvvrPF+kDnFbeZMu/c5leUK bEUZyQaajEXFScCALgE8q+6AgAA X-Env-Sender: prvs=966959e1a=wei.liu2@citrix.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1465908384!18981774!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60690 invoked from network); 14 Jun 2016 12:46:25 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-12.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 14 Jun 2016 12:46:25 -0000 X-IronPort-AV: E=Sophos;i="5.26,470,1459814400"; d="scan'208";a="367174103" Date: Tue, 14 Jun 2016 13:46:17 +0100 From: Wei Liu To: Ian Jackson Message-ID: <20160614124617.GK28116@citrix.com> References: <1465210332-25440-1-git-send-email-wei.liu2@citrix.com> <1465210332-25440-5-git-send-email-wei.liu2@citrix.com> <22367.56304.226295.618349@mariner.uk.xensource.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <22367.56304.226295.618349@mariner.uk.xensource.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-DLP: MIA2 Cc: Xen-devel , Wei Liu Subject: Re: [Xen-devel] [PATCH 4/6] libxl: debug output for args and env when invoking hotplug script X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Jun 14, 2016 at 11:26:56AM +0100, Ian Jackson wrote: > Wei Liu writes ("[PATCH 4/6] libxl: debug output for args and env when invoking hotplug script"): > > Signed-off-by: Wei Liu > ... > > + const char *arg; > > + unsigned int x = 2; > > + > > + arg = args[x]; > > + while (arg) { > > + LOG(DEBUG, "\t%s", arg); > > + x++; > > + arg = args[x]; > > + } I will use > > What a strange way to write > > for (x=2; (arg = args[x]); x++) { > This style. > or > > for (x=2; (arg = args[x++]); ) { > > or > > x = 2; > while ((arg = args[x++])) { > > If you really insist on not doing assignment in the conditional (which > IMO is a very usual C idiom) then you should avoid the repeated code > with > > x = 2; > for (;;) { > arg = args[x++]; > if (!arg) break; > > or some such. > > > + const char *k, *v; > > + unsigned int x = 0; > > + > > + k = env[x]; > > + while (k) { > > + v = env[x+1]; > > + LOG(DEBUG, "\t%s: %s", k, v); > > + x += 2; > > + k = env[x]; > > + } > > How about one of > > for (x=0; (k = env[x]); x += 2) { > v = env[x+1]; > And this style. ---8<--- From 49714976c5fde3d08baa6f34295b3f7db6a81444 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Fri, 15 Apr 2016 12:56:03 +0100 Subject: [PATCH] libxl: debug output for args and env when invoking hotplug script Signed-off-by: Wei Liu Acked-by: Ian Jackson --- v2: write the loops differently. --- tools/libxl/libxl_device.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 4717027..b3213be 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -1167,6 +1167,24 @@ static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev) } LOG(DEBUG, "calling hotplug script: %s %s", args[0], args[1]); + LOG(DEBUG, "extra args:"); + { + const char *arg; + unsigned int x; + + for (x = 2; (arg = args[x]); x++) + LOG(DEBUG, "\t%s", arg); + } + LOG(DEBUG, "env:"); + { + const char *k, *v; + unsigned int x; + + for (x = 0; (k = env[x]); x += 2) { + v = env[x+1]; + LOG(DEBUG, "\t%s: %s", k, v); + } + } nullfd = open("/dev/null", O_RDONLY); if (nullfd < 0) {