change strncmp(...) != 0 to STRNEQLEN(...)
[libguestfs.git] / daemon / guestfsd.c
index bf06c73..61a6236 100644 (file)
@@ -38,6 +38,8 @@
 #include <printf.h>
 
 #include "c-ctype.h"
+#include "ignore-value.h"
+
 #include "daemon.h"
 
 static char *read_cmdline (void);
@@ -546,7 +548,7 @@ commandf (char **stdoutput, char **stderror, int flags, const char *name, ...)
 
   va_end (args);
 
-  r = commandvf (stdoutput, stderror, flags, (char **) argv);
+  r = commandvf (stdoutput, stderror, flags, (const char * const*) argv);
 
   /* NB: Mustn't free the strings which are on the stack. */
   free (argv);
@@ -603,7 +605,8 @@ commandrf (char **stdoutput, char **stderror, int flags, const char *name, ...)
 
 /* Same as 'command', but passing an argv. */
 int
-commandvf (char **stdoutput, char **stderror, int flags, char *const *argv)
+commandvf (char **stdoutput, char **stderror, int flags,
+           char const *const *argv)
 {
   int r;
 
@@ -638,7 +641,7 @@ commandvf (char **stdoutput, char **stderror, int flags, char *const *argv)
  */
 int
 commandrvf (char **stdoutput, char **stderror, int flags,
-           char const* const *argv)
+            char const* const *argv)
 {
   int so_size = 0, se_size = 0;
   int so_fd[2], se_fd[2];
@@ -742,15 +745,20 @@ commandrvf (char **stdoutput, char **stderror, int flags,
       }
       if (r == 0) { FD_CLR (se_fd[0], &rset); quit++; }
 
-      if (r > 0 && stderror) {
-        se_size += r;
-        p = realloc (*stderror, se_size);
-        if (p == NULL) {
-          perror ("realloc");
-          goto quit;
+      if (r > 0) {
+        if (verbose)
+          ignore_value (write (2, buf, r));
+
+        if (stderror) {
+          se_size += r;
+          p = realloc (*stderror, se_size);
+          if (p == NULL) {
+            perror ("realloc");
+            goto quit;
+          }
+          *stderror = p;
+          memcpy (*stderror + se_size - r, buf, r);
         }
-        *stderror = p;
-        memcpy (*stderror + se_size - r, buf, r);
       }
     }
   }
@@ -937,7 +945,7 @@ device_name_translation (char *device, const char *func)
   }
 
   /* If the name begins with "/dev/sd" then try the alternatives. */
-  if (strncmp (device, "/dev/sd", 7) != 0)
+  if (STRNEQLEN (device, "/dev/sd", 7))
     goto error;
 
   device[5] = 'h';             /* /dev/hd (old IDE driver) */