diff mbox

[4/6] libxl: debug output for args and env when invoking hotplug script

Message ID 20160614124617.GK28116@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu June 14, 2016, 12:46 p.m. UTC
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 <wei.liu2@citrix.com>
> ...
> > +        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 <wei.liu2@citrix.com>
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 <wei.liu2@citrix.com>
---
v2: write the loops differently.
---
 tools/libxl/libxl_device.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Wei Liu July 2, 2016, 10:21 a.m. UTC | #1
> From 49714976c5fde3d08baa6f34295b3f7db6a81444 Mon Sep 17 00:00:00 2001
> From: Wei Liu <wei.liu2@citrix.com>
> 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 <wei.liu2@citrix.com>

Ian, Ping?

> ---
> 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) {
> -- 
> 2.1.4
>
Ian Jackson July 4, 2016, 5:06 p.m. UTC | #2
Wei Liu writes ("Re: [PATCH 4/6] libxl: debug output for args and env when invoking hotplug script"):
> > From 49714976c5fde3d08baa6f34295b3f7db6a81444 Mon Sep 17 00:00:00 2001
> > From: Wei Liu <wei.liu2@citrix.com>
> > 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 <wei.liu2@citrix.com>
> 
> Ian, Ping?

Sorry, yes.

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Wei Liu July 6, 2016, 5:23 p.m. UTC | #3
On Mon, Jul 04, 2016 at 06:06:27PM +0100, Ian Jackson wrote:
> Wei Liu writes ("Re: [PATCH 4/6] libxl: debug output for args and env when invoking hotplug script"):
> > > From 49714976c5fde3d08baa6f34295b3f7db6a81444 Mon Sep 17 00:00:00 2001
> > > From: Wei Liu <wei.liu2@citrix.com>
> > > 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 <wei.liu2@citrix.com>
> > 
> > Ian, Ping?
> 
> Sorry, yes.
> 
> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

Queued. Thanks.
diff mbox

Patch

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) {