diff mbox

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

Message ID 1465210332-25440-5-git-send-email-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu June 6, 2016, 10:52 a.m. UTC
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 tools/libxl/libxl_device.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Ian Jackson June 14, 2016, 10:26 a.m. UTC | #1
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];
> +        }

What a strange way to write

   for (x=2; (arg = args[x]); x++) {

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];

   for (x=0; (k = env[x]) && (v = env[x+1]); x += 2) {

   for (x=0; (k = env[x++]) && (v = env[x++]); ) {

   x = 0;
   while ((k = env[x++])) {
       v = env[x++];
       assert(v);

?

Ian.
diff mbox

Patch

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 4717027..b922a94 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -1167,6 +1167,31 @@  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 = 2;
+
+        arg = args[x];
+        while (arg) {
+            LOG(DEBUG, "\t%s", arg);
+            x++;
+            arg = args[x];
+        }
+    }
+    LOG(DEBUG, "env:");
+    {
+        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];
+        }
+    }
 
     nullfd = open("/dev/null", O_RDONLY);
     if (nullfd < 0) {