[Libguestfs] [PATCH 9/9] daemon error handling: gnulib calls need separate error handling.

Richard W.M. Jones rjones at redhat.com
Fri Nov 27 18:05:48 UTC 2009


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://et.redhat.com/~rjones/libguestfs/
See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
-------------- next part --------------
>From 9d736b09a45fab349943058d60c7b4343167a3af Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones at redhat.com>
Date: Fri, 27 Nov 2009 17:56:51 +0000
Subject: [PATCH 9/9] daemon error handling: gnulib calls need separate error handling.

---
 daemon/augeas.c      |    8 ++++----
 daemon/checksum.c    |    2 +-
 daemon/cmp.c         |    4 ++--
 daemon/command.c     |    2 +-
 daemon/cpmv.c        |    4 ++--
 daemon/daemon.h      |    9 +++++++++
 daemon/dd.c          |    4 ++--
 daemon/debug.c       |    6 +++---
 daemon/dir.c         |    4 ++--
 daemon/du.c          |    2 +-
 daemon/echo_daemon.c |    2 +-
 daemon/ext2.c        |    2 +-
 daemon/file.c        |   10 +++++-----
 daemon/find.c        |    8 ++++----
 daemon/grep.c        |    2 +-
 daemon/grub.c        |    2 +-
 daemon/guestfsd.c    |    6 +++---
 daemon/headtail.c    |    2 +-
 daemon/hexdump.c     |    2 +-
 daemon/initrd.c      |    2 +-
 daemon/inotify.c     |    8 ++++----
 daemon/link.c        |    6 +++---
 daemon/ls.c          |    2 +-
 daemon/lvm.c         |    4 ++--
 daemon/mount.c       |    8 ++++----
 daemon/parted.c      |    6 +++---
 daemon/proto.c       |    2 +-
 daemon/readdir.c     |    4 ++--
 daemon/realpath.c    |    4 ++--
 daemon/scrub.c       |    4 ++--
 daemon/selinux.c     |    2 +-
 daemon/stat.c        |    8 ++++----
 daemon/statvfs.c     |   10 +++++-----
 daemon/strings.c     |    2 +-
 daemon/swap.c        |    6 +++---
 daemon/tar.c         |    8 ++++----
 daemon/wc.c          |    2 +-
 daemon/xattr.c       |   22 +++++++++++-----------
 src/generator.ml     |    6 +++---
 39 files changed, 103 insertions(+), 94 deletions(-)

diff --git a/daemon/augeas.c b/daemon/augeas.c
index de325de..c04e345 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -74,7 +74,7 @@ do_aug_init (const char *root, int flags)
 
   buf = sysroot_path (root);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -179,7 +179,7 @@ do_aug_get (const char *path)
   /* The value is an internal Augeas string, so we must copy it. GC FTW. */
   v = strdup (value);
   if (v == NULL) {
-    reply_with_perror ("strdup");
+    reply_with_perror_gnulib ("strdup");
     return NULL;
   }
 
@@ -290,7 +290,7 @@ do_aug_match (const char *path)
    */
   vp = realloc (matches, sizeof (char *) * (r+1));
   if (vp == NULL) {
-    reply_with_perror ("realloc");
+    reply_with_perror_gnulib ("realloc");
     free (vp);
     return NULL;
   }
@@ -365,7 +365,7 @@ do_aug_ls (const char *path)
     len += 3;			/* / * + terminating \0 */
     buf = malloc (len);
     if (buf == NULL) {
-      reply_with_perror ("malloc");
+      reply_with_perror_gnulib ("malloc");
       return NULL;
     }
 
diff --git a/daemon/checksum.c b/daemon/checksum.c
index 499d19d..6775a38 100644
--- a/daemon/checksum.c
+++ b/daemon/checksum.c
@@ -58,7 +58,7 @@ do_checksum (const char *csumtype, const char *path)
   /* Make the path relative to /sysroot. */
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
diff --git a/daemon/cmp.c b/daemon/cmp.c
index 2b7e33b..2700bd0 100644
--- a/daemon/cmp.c
+++ b/daemon/cmp.c
@@ -36,13 +36,13 @@ do_equal (const char *file1, const char *file2)
 
   file1buf = sysroot_path (file1);
   if (file1buf == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
   file2buf = sysroot_path (file2);
   if (file2buf == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     free (file1buf);
     return -1;
   }
diff --git a/daemon/command.c b/daemon/command.c
index b2350ec..d9ca2cb 100644
--- a/daemon/command.c
+++ b/daemon/command.c
@@ -64,7 +64,7 @@ do_command (char *const *argv)
   if (sysroot_dev == NULL || sysroot_dev_pts == NULL ||
       sysroot_proc == NULL || sysroot_selinux == NULL ||
       sysroot_sys == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     free (sysroot_dev);
     free (sysroot_dev_pts);
     free (sysroot_proc);
diff --git a/daemon/cpmv.c b/daemon/cpmv.c
index 47b8aa2..5288b69 100644
--- a/daemon/cpmv.c
+++ b/daemon/cpmv.c
@@ -54,13 +54,13 @@ cpmv_cmd (const char *cmd, const char *flags, const char *src, const char *dest)
 
   srcbuf = sysroot_path (src);
   if (srcbuf == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
   destbuf = sysroot_path (dest);
   if (destbuf == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     free (srcbuf);
     return -1;
   }
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 96d08dd..167f1e5 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -130,6 +130,10 @@ extern void main_loop (int sock) __attribute__((noreturn));
  *     return -1;
  *   }
  *
+ * The _gnulib_ variations are used for Gnulib replacement functions
+ * (eg. malloc, strdup, asprintf).  These always set errno, not the
+ * Windows equivalent.
+ *
  * The _sock_ variations are only used for socket calls (Win32 has a
  * different way to return errors from socket calls).  In reality
  * these variants are never used because the only socket we talk to is
@@ -139,6 +143,7 @@ extern void main_loop (int sock) __attribute__((noreturn));
 typedef int errtype;
 static inline void clear_error(void) { errno = 0; }
 static inline int get_error(void) { return errno; }
+static inline int get_gnulib_error(void) { return errno; }
 static inline int get_sock_error(void) { return errno; }
 #else
 typedef DWORD errtype;
@@ -149,6 +154,7 @@ static inline void clear_error(void)
   errno = 0;
 }
 static inline DWORD get_error(void) { return GetLastError (); }
+static inline DWORD get_gnulib_error(void) { return (DWORD) errno; }
 static inline DWORD get_sock_error(void) { return WSAGetLastError (); }
 #endif
 
@@ -174,6 +180,7 @@ static inline int get_errno(void) { return errno; }
 /* Ordinary daemon functions use these to indicate errors.
  * reply_with_error: Report an error.
  * reply_with_perror: Report an error followed by errno message.
+ * reply_with_perror_gnulib: Same as reply_with_perror for Gnulib calls.
  * reply_with_perror_sock: Same as reply_with_perror for socket calls.
  * reply_with_perror_with_err: Same as reply_with_perror but use an
  *   error code that you saved previously from get_error().
@@ -182,6 +189,8 @@ extern void reply_with_error (const char *fs, ...)
   __attribute__((format (printf,1,2)));
 #define reply_with_perror(...) \
   reply_with_perror_with_err (get_error(),__VA_ARGS__)
+#define reply_with_perror_gnulib(...) \
+  reply_with_perror_with_err (get_gnulib_error(),__VA_ARGS__)
 #define reply_with_perror_sock(...) \
   reply_with_perror_with_err (get_sock_error(),__VA_ARGS__)
 extern void reply_with_perror_with_err (errtype err, const char *fs, ...)
diff --git a/daemon/dd.c b/daemon/dd.c
index 0a53b31..907fa01 100644
--- a/daemon/dd.c
+++ b/daemon/dd.c
@@ -41,7 +41,7 @@ do_dd (const char *src, const char *dest)
   else
     r = asprintf (&if_arg, "if=%s%s", sysroot, src);
   if (r == -1) {
-    reply_with_perror ("asprintf");
+    reply_with_perror_gnulib ("asprintf");
     return -1;
   }
 
@@ -52,7 +52,7 @@ do_dd (const char *src, const char *dest)
   else
     r = asprintf (&of_arg, "of=%s%s", sysroot, dest);
   if (r == -1) {
-    reply_with_perror ("asprintf");
+    reply_with_perror_gnulib ("asprintf");
     free (if_arg);
     return -1;
   }
diff --git a/daemon/debug.c b/daemon/debug.c
index cb905cb..2b5fb06 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -101,7 +101,7 @@ debug_help (const char *subcmd, int argc, char *const *const argv)
 
   r = strdup ("Commands supported:");
   if (!r) {
-    reply_with_perror ("strdup");
+    reply_with_perror_gnulib ("strdup");
     return NULL;
   }
 
@@ -110,7 +110,7 @@ debug_help (const char *subcmd, int argc, char *const *const argv)
     len += strlen (cmds[i].cmd) + 1; /* space + new command */
     p = realloc (r, len + 1);	     /* +1 for the final NUL */
     if (p == NULL) {
-      reply_with_perror ("realloc");
+      reply_with_perror_gnulib ("realloc");
       free (r);
       return NULL;
     }
@@ -226,7 +226,7 @@ debug_sh (const char *subcmd, int argc, char *const *const argv)
     len += strlen (argv[i]) + 1;
   cmd = malloc (len);
   if (!cmd) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
   for (i = j = 0; i < argc; ++i) {
diff --git a/daemon/dir.c b/daemon/dir.c
index 072dcf5..8eac736 100644
--- a/daemon/dir.c
+++ b/daemon/dir.c
@@ -65,7 +65,7 @@ do_rm_rf (const char *path)
 
   buf = sysroot_path (path);
   if (buf == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -224,7 +224,7 @@ do_mkdtemp (const char *template)
 {
   char *writable = strdup (template);
   if (writable == NULL) {
-    reply_with_perror ("strdup");
+    reply_with_perror_gnulib ("strdup");
     return NULL;
   }
 
diff --git a/daemon/du.c b/daemon/du.c
index e6df245..21e6818 100644
--- a/daemon/du.c
+++ b/daemon/du.c
@@ -39,7 +39,7 @@ do_du (const char *path)
   /* Make the path relative to /sysroot. */
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
diff --git a/daemon/echo_daemon.c b/daemon/echo_daemon.c
index 658974b..e9ad742 100644
--- a/daemon/echo_daemon.c
+++ b/daemon/echo_daemon.c
@@ -49,7 +49,7 @@ do_echo_daemon (char *const *argv)
     /* Make the output buffer big enough for the string and its terminator */
     char *out_new = realloc (out, out_len + 1);
     if (NULL == out_new) {
-      reply_with_perror ("realloc");
+      reply_with_perror_gnulib ("realloc");
       free(out);
       return 0;
     }
diff --git a/daemon/ext2.c b/daemon/ext2.c
index f46bac9..b00e5fb 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -225,7 +225,7 @@ do_get_e2uuid (const char *device)
 
   p = strdup (p);
   if (!p) {
-    reply_with_perror ("strdup");
+    reply_with_perror_gnulib ("strdup");
     free (out);
     return NULL;
   }
diff --git a/daemon/file.c b/daemon/file.c
index bbb6426..da1f988 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -99,7 +99,7 @@ do_cat (const char *path)
       }
       buf2 = realloc (buf, alloc);
       if (buf2 == NULL) {
-        reply_with_perror ("realloc");
+        reply_with_perror_gnulib ("realloc");
         free (buf);
         close (fd);
         return NULL;
@@ -366,7 +366,7 @@ do_read_file (const char *path, size_t *size_r)
   }
   r = malloc (*size_r);
   if (r == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     close (fd);
     return NULL;
   }
@@ -417,7 +417,7 @@ do_pread (const char *path, int count, int64_t offset, size_t *size_r)
 
   buf = malloc (count);
   if (buf == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     close (fd);
     return NULL;
   }
@@ -455,7 +455,7 @@ do_file (const char *path)
   else {
     buf = sysroot_path (path);
     if (!buf) {
-      reply_with_perror ("malloc");
+      reply_with_perror_gnulib ("malloc");
       return NULL;
     }
     freeit = 1;
@@ -511,7 +511,7 @@ do_zfile (const char *method, const char *path)
   }
 
   if (asprintf_nowarn (&cmd, "%s %R | file -bsL -", zcat, path) == -1) {
-    reply_with_perror ("asprintf");
+    reply_with_perror_gnulib ("asprintf");
     return NULL;
   }
 
diff --git a/daemon/find.c b/daemon/find.c
index 391b87b..2382634 100644
--- a/daemon/find.c
+++ b/daemon/find.c
@@ -62,7 +62,7 @@ do_find (const char *dir)
 
   sysrootdir = sysroot_path (dir);
   if (!sysrootdir) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
@@ -82,7 +82,7 @@ do_find (const char *dir)
 
   /* Assemble the external find command. */
   if (asprintf_nowarn (&cmd, "find %Q -print0", sysrootdir) == -1) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("gnulib");
     free (sysrootdir);
     return NULL;
   }
@@ -154,7 +154,7 @@ do_find0 (const char *dir)
 
   sysrootdir = sysroot_path (dir);
   if (!sysrootdir) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -173,7 +173,7 @@ do_find0 (const char *dir)
   sysrootdirlen = strlen (sysrootdir);
 
   if (asprintf_nowarn (&cmd, "find %Q -print0", sysrootdir) == -1) {
-    reply_with_perror ("asprintf");
+    reply_with_perror_gnulib ("asprintf");
     free (sysrootdir);
     return -1;
   }
diff --git a/daemon/grep.c b/daemon/grep.c
index d1f5a3f..bb0faa3 100644
--- a/daemon/grep.c
+++ b/daemon/grep.c
@@ -38,7 +38,7 @@ grep (const char *prog, const char *flag, const char *regex, const char *path)
   /* Make the path relative to /sysroot. */
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
diff --git a/daemon/grub.c b/daemon/grub.c
index 657abbb..a073313 100644
--- a/daemon/grub.c
+++ b/daemon/grub.c
@@ -33,7 +33,7 @@ do_grub_install (const char *root, const char *device)
   char *buf;
 
   if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) {
-    reply_with_perror ("asprintf");
+    reply_with_perror_gnulib ("asprintf");
     return -1;
   }
 
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index c3af8c5..b293ef6 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -445,7 +445,7 @@ read_cmdline (void)
 
 /* Turn "/path" into "/sysroot/path".
  *
- * Caller must check for NULL and call reply_with_perror ("malloc")
+ * Caller must check for NULL and call reply_with_perror_gnulib ("malloc")
  * if it is.  Caller must also free the string.
  *
  * See also the custom %R printf formatter which does shell quoting too.
@@ -516,7 +516,7 @@ add_string (char ***argv, int *size, int *alloc, const char *str)
     *alloc += 64;
     new_argv = realloc (*argv, *alloc * sizeof (char *));
     if (new_argv == NULL) {
-      reply_with_perror ("realloc");
+      reply_with_perror_gnulib ("realloc");
       free_strings (*argv);
       return -1;
     }
@@ -526,7 +526,7 @@ add_string (char ***argv, int *size, int *alloc, const char *str)
   if (str) {
     new_str = strdup (str);
     if (new_str == NULL) {
-      reply_with_perror ("strdup");
+      reply_with_perror_gnulib ("strdup");
       free_strings (*argv);
     }
   } else
diff --git a/daemon/headtail.c b/daemon/headtail.c
index 9175cf0..52fe060 100644
--- a/daemon/headtail.c
+++ b/daemon/headtail.c
@@ -38,7 +38,7 @@ headtail (const char *prog, const char *flag, const char *n, const char *path)
   /* Make the path relative to /sysroot. */
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
diff --git a/daemon/hexdump.c b/daemon/hexdump.c
index 7016faf..55409af 100644
--- a/daemon/hexdump.c
+++ b/daemon/hexdump.c
@@ -34,7 +34,7 @@ do_hexdump (const char *path)
 
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
diff --git a/daemon/initrd.c b/daemon/initrd.c
index 9c92fee..0d8fdc0 100644
--- a/daemon/initrd.c
+++ b/daemon/initrd.c
@@ -40,7 +40,7 @@ do_initrd_list (const char *path)
 
   /* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted. */
   if (asprintf_nowarn (&cmd, "zcat %R | cpio --quiet -it", path) == -1) {
-    reply_with_perror ("asprintf");
+    reply_with_perror_gnulib ("asprintf");
     return NULL;
   }
 
diff --git a/daemon/inotify.c b/daemon/inotify.c
index 749b8b7..634c125 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -159,7 +159,7 @@ do_inotify_add_watch (const char *path, int mask)
 
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -204,7 +204,7 @@ do_inotify_read (void)
 
   ret = malloc (sizeof *ret);
   if (ret == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
   ret->guestfs_int_inotify_event_list_len = 0;
@@ -257,7 +257,7 @@ do_inotify_read (void)
                     (ret->guestfs_int_inotify_event_list_len + 1) *
                     sizeof (guestfs_int_inotify_event));
       if (np == NULL) {
-        reply_with_perror ("realloc");
+        reply_with_perror_gnulib ("realloc");
         goto error;
       }
       ret->guestfs_int_inotify_event_list_val = np;
@@ -273,7 +273,7 @@ do_inotify_read (void)
       else
         in->in_name = strdup (""); /* Should have optional string fields XXX. */
       if (in->in_name == NULL) {
-        reply_with_perror ("strdup");
+        reply_with_perror_gnulib ("strdup");
         goto error;
       }
 
diff --git a/daemon/link.c b/daemon/link.c
index 97f6ac0..b6d0a6a 100644
--- a/daemon/link.c
+++ b/daemon/link.c
@@ -47,7 +47,7 @@ do_readlink (const char *path)
 
   ret = strndup (link, r);
   if (ret == NULL) {
-    reply_with_perror ("strndup");
+    reply_with_perror_gnulib ("strndup");
     return NULL;
   }
 
@@ -117,7 +117,7 @@ _link (const char *flag, int symbolic, const char *target, const char *linkname)
   /* Prefix linkname with sysroot. */
   buf_linkname = sysroot_path (linkname);
   if (!buf_linkname) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -130,7 +130,7 @@ _link (const char *flag, int symbolic, const char *target, const char *linkname)
   if (!symbolic && target[0] == '/') {
     buf_target = sysroot_path (target);
     if (!buf_target) {
-      reply_with_perror ("malloc");
+      reply_with_perror_gnulib ("malloc");
       free (buf_linkname);
       return -1;
     }
diff --git a/daemon/ls.c b/daemon/ls.c
index a15ce62..d9bc3e8 100644
--- a/daemon/ls.c
+++ b/daemon/ls.c
@@ -88,7 +88,7 @@ do_ll (const char *path)
 
   spath = sysroot_path (path);
   if (!spath) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
diff --git a/daemon/lvm.c b/daemon/lvm.c
index 564517c..81d2fdd 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -209,7 +209,7 @@ do_vgcreate (const char *volgroup, char *const *physvols)
   argc = count_strings (physvols) + 3;
   argv = malloc (sizeof (char *) * (argc + 1));
   if (argv == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
   argv[0] = "/sbin/lvm";
@@ -437,7 +437,7 @@ do_vg_activate (int activate, char *const *volgroups)
   argc = count_strings (volgroups) + 4;
   argv = malloc (sizeof (char *) * (argc+1));
   if (argv == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
diff --git a/daemon/mount.c b/daemon/mount.c
index f447380..ef8b51f 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -59,7 +59,7 @@ do_mount_vfs (const char *options, const char *vfstype,
 
   mp = sysroot_path (mountpoint);
   if (!mp) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -116,7 +116,7 @@ do_umount (const char *pathordevice)
   buf = is_dev ? strdup (pathordevice)
                : sysroot_path (pathordevice);
   if (buf == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -323,13 +323,13 @@ do_mount_loop (const char *file, const char *mountpoint)
   /* We have to prefix /sysroot on both the filename and the mountpoint. */
   mp = sysroot_path (mountpoint);
   if (!mp) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
   buf = sysroot_path (file);
   if (!file) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     free (mp);
     return -1;
   }
diff --git a/daemon/parted.c b/daemon/parted.c
index 2b0df44..5f17e99 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -291,7 +291,7 @@ do_part_get_parttype (const char *device)
 
   r = strdup (r);
   if (!r) {
-    reply_with_perror ("strdup");
+    reply_with_perror_gnulib ("strdup");
     free_strings (lines);
     return NULL;
   }
@@ -321,14 +321,14 @@ do_part_list (const char *device)
 
   r = malloc (sizeof *r);
   if (r == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     goto error1;
   }
   r->guestfs_int_partition_list_len = nr_rows;
   r->guestfs_int_partition_list_val =
     malloc (nr_rows * sizeof (guestfs_int_partition));
   if (r->guestfs_int_partition_list_val == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     goto error2;
   }
 
diff --git a/daemon/proto.c b/daemon/proto.c
index 23748a4..f4fb017 100644
--- a/daemon/proto.c
+++ b/daemon/proto.c
@@ -81,7 +81,7 @@ main_loop (int _sock)
 
     buf = malloc (len);
     if (!buf) {
-      reply_with_perror ("malloc");
+      reply_with_perror_gnulib ("malloc");
       continue;
     }
 
diff --git a/daemon/readdir.c b/daemon/readdir.c
index 0d72912..849cf45 100644
--- a/daemon/readdir.c
+++ b/daemon/readdir.c
@@ -39,7 +39,7 @@ do_readdir (const char *path)
 
   ret = malloc (sizeof *ret);
   if (ret == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
@@ -65,7 +65,7 @@ do_readdir (const char *path)
                  sizeof (guestfs_int_dirent) * (i+1));
     v.name = strdup (d->d_name);
     if (!p || !v.name) {
-      reply_with_perror ("allocate");
+      reply_with_perror_gnulib ("realloc");
       free (ret->guestfs_int_dirent_list_val);
       free (p);
       free (v.name);
diff --git a/daemon/realpath.c b/daemon/realpath.c
index 2760aff..0d50bb9 100644
--- a/daemon/realpath.c
+++ b/daemon/realpath.c
@@ -191,7 +191,7 @@ do_case_sensitive_path (const char *path)
   ret[next] = '\0';
   char *retp = strdup (ret);
   if (retp == NULL) {
-    reply_with_perror ("strdup");
+    reply_with_perror_gnulib ("strdup");
     return NULL;
   }
   return retp;                  /* caller frees */
@@ -205,7 +205,7 @@ do_case_sensitive_path (const char *path)
    */
   char *ret = strdup (path);
   if (ret == NULL) {
-    reply_with_perror ("strdup");
+    reply_with_perror_gnulib ("strdup");
     return NULL;
   }
   return ret;
diff --git a/daemon/scrub.c b/daemon/scrub.c
index e37a1e1..f7cdddf 100644
--- a/daemon/scrub.c
+++ b/daemon/scrub.c
@@ -63,7 +63,7 @@ do_scrub_file (const char *file)
   /* Make the path relative to /sysroot. */
   buf = sysroot_path (file);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -90,7 +90,7 @@ do_scrub_freespace (const char *dir)
   /* Make the path relative to /sysroot. */
   buf = sysroot_path (dir);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
diff --git a/daemon/selinux.c b/daemon/selinux.c
index e49e657..aac44e7 100644
--- a/daemon/selinux.c
+++ b/daemon/selinux.c
@@ -79,7 +79,7 @@ do_getcon (void)
   r = strdup (context);
   freecon (context);
   if (r == NULL) {
-    reply_with_perror ("strdup");
+    reply_with_perror_gnulib ("strdup");
     return NULL;
   }
 
diff --git a/daemon/stat.c b/daemon/stat.c
index c14d15e..ad999cb 100644
--- a/daemon/stat.c
+++ b/daemon/stat.c
@@ -50,7 +50,7 @@ do_stat (const char *path)
 
   ret = malloc (sizeof *ret);
   if (ret == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
@@ -99,7 +99,7 @@ do_lstat (const char *path)
 
   ret = malloc (sizeof *ret);
   if (ret == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
@@ -140,13 +140,13 @@ do_lstatlist (const char *path, char *const *names)
 
   ret = malloc (sizeof *ret);
   if (!ret) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
   ret->guestfs_int_stat_list_len = nr_names;
   ret->guestfs_int_stat_list_val = calloc (nr_names, sizeof (guestfs_int_stat));
   if (ret->guestfs_int_stat_list_val == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     free (ret);
     return NULL;
   }
diff --git a/daemon/statvfs.c b/daemon/statvfs.c
index 4fdcc24..202e9db 100644
--- a/daemon/statvfs.c
+++ b/daemon/statvfs.c
@@ -60,7 +60,7 @@ do_statvfs (const char *path)
 
   ret = malloc (sizeof *ret);
   if (ret == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
@@ -89,7 +89,7 @@ do_statvfs (const char *path)
 
   disk = sysroot_path (path);
   if (!disk) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
@@ -105,7 +105,7 @@ do_statvfs (const char *path)
 
   ret = malloc (sizeof *ret);
   if (ret == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
@@ -150,7 +150,7 @@ do_statvfs (const char *path)
 
   disk = sysroot_path (path);
   if (!disk) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
@@ -164,7 +164,7 @@ do_statvfs (const char *path)
 
   ret = malloc (sizeof *ret);
   if (ret == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
diff --git a/daemon/strings.c b/daemon/strings.c
index d7dc392..051573b 100644
--- a/daemon/strings.c
+++ b/daemon/strings.c
@@ -35,7 +35,7 @@ do_strings_e (const char *encoding, const char *path)
 
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return NULL;
   }
 
diff --git a/daemon/swap.c b/daemon/swap.c
index 2d3d9ff..6c86d30 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -94,7 +94,7 @@ do_mkswap_file (const char *path)
 
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -145,7 +145,7 @@ do_swapon_file (const char *path)
 
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
@@ -162,7 +162,7 @@ do_swapoff_file (const char *path)
 
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
diff --git a/daemon/tar.c b/daemon/tar.c
index 56d291d..cbd3aa2 100644
--- a/daemon/tar.c
+++ b/daemon/tar.c
@@ -51,7 +51,7 @@ do_tar_in (const char *dir)
 
   /* "tar -C /sysroot%s -xf -" but we have to quote the dir. */
   if (asprintf_nowarn (&cmd, "tar -C %R -xf -", dir) == -1) {
-    err = get_error ();
+    err = get_gnulib_error ();
     cancel_receive ();
     reply_with_perror_with_err (err, "asprintf");
     return -1;
@@ -105,7 +105,7 @@ do_tar_out (const char *dir)
 
   /* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */
   if (asprintf_nowarn (&cmd, "tar -C %R -cf - .", dir) == -1) {
-    reply_with_perror ("asprintf");
+    reply_with_perror_gnulib ("asprintf");
     return -1;
   }
 
@@ -169,7 +169,7 @@ do_tgz_in (const char *dir)
 
   /* "tar -C /sysroot%s -zxf -" but we have to quote the dir. */
   if (asprintf_nowarn (&cmd, "tar -C %R -zxf -", dir) == -1) {
-    err = get_error ();
+    err = get_gnulib_error ();
     cancel_receive ();
     reply_with_perror_with_err (err, "asprintf");
     return -1;
@@ -223,7 +223,7 @@ do_tgz_out (const char *dir)
 
   /* "tar -C /sysroot%s -zcf - ." but we have to quote the dir. */
   if (asprintf_nowarn (&cmd, "tar -C %R -zcf - .", dir) == -1) {
-    reply_with_perror ("asprintf");
+    reply_with_perror_gnulib ("asprintf");
     return -1;
   }
 
diff --git a/daemon/wc.c b/daemon/wc.c
index b64940b..53791fa 100644
--- a/daemon/wc.c
+++ b/daemon/wc.c
@@ -37,7 +37,7 @@ wc (const char *flag, const char *path)
   /* Make the path relative to /sysroot. */
   buf = sysroot_path (path);
   if (!buf) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     return -1;
   }
 
diff --git a/daemon/xattr.c b/daemon/xattr.c
index 77092c4..17afbae 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -135,7 +135,7 @@ getxattrs (const char *path,
 
   buf = malloc (len);
   if (buf == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     goto error;
   }
 
@@ -150,7 +150,7 @@ getxattrs (const char *path,
 
   r = calloc (1, sizeof (*r));
   if (r == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     goto error;
   }
 
@@ -164,7 +164,7 @@ getxattrs (const char *path,
   r->guestfs_int_xattr_list_val =
     calloc (r->guestfs_int_xattr_list_len, sizeof (guestfs_int_xattr));
   if (r->guestfs_int_xattr_list_val == NULL) {
-    reply_with_perror ("calloc");
+    reply_with_perror_gnulib ("calloc");
     goto error;
   }
 
@@ -184,7 +184,7 @@ getxattrs (const char *path,
 
     if (r->guestfs_int_xattr_list_val[j].attrname == NULL ||
         r->guestfs_int_xattr_list_val[j].attrval.attrval_val == NULL) {
-      reply_with_perror ("malloc");
+      reply_with_perror_gnulib ("malloc");
       goto error;
     }
 
@@ -284,7 +284,7 @@ do_lxattrlist (const char *path, char *const *names)
 
   ret = malloc (sizeof (*ret));
   if (ret == NULL) {
-    reply_with_perror ("malloc");
+    reply_with_perror_gnulib ("malloc");
     goto error;
   }
 
@@ -309,7 +309,7 @@ do_lxattrlist (const char *path, char *const *names)
       realloc (ret->guestfs_int_xattr_list_val,
                (ret->guestfs_int_xattr_list_len+1)*sizeof (guestfs_int_xattr));
     if (newptr == NULL) {
-      reply_with_perror ("realloc");
+      reply_with_perror_gnulib ("realloc");
       goto error;
     }
     ret->guestfs_int_xattr_list_val = newptr;
@@ -323,7 +323,7 @@ do_lxattrlist (const char *path, char *const *names)
 
     entry->attrname = strdup ("");
     if (entry->attrname == NULL) {
-      reply_with_perror ("strdup");
+      reply_with_perror_gnulib ("strdup");
       goto error;
     }
 
@@ -335,7 +335,7 @@ do_lxattrlist (const char *path, char *const *names)
 
     buf = malloc (len);
     if (buf == NULL) {
-      reply_with_perror ("malloc");
+      reply_with_perror_gnulib ("malloc");
       goto error;
     }
 
@@ -357,7 +357,7 @@ do_lxattrlist (const char *path, char *const *names)
                (ret->guestfs_int_xattr_list_len+nr_attrs) *
                sizeof (guestfs_int_xattr));
     if (newptr == NULL) {
-      reply_with_perror ("realloc");
+      reply_with_perror_gnulib ("realloc");
       goto error;
     }
     ret->guestfs_int_xattr_list_val = newptr;
@@ -389,7 +389,7 @@ do_lxattrlist (const char *path, char *const *names)
 
       if (entry[j+1].attrname == NULL ||
           entry[j+1].attrval.attrval_val == NULL) {
-        reply_with_perror ("malloc");
+        reply_with_perror_gnulib ("malloc");
         goto error;
       }
 
@@ -412,7 +412,7 @@ do_lxattrlist (const char *path, char *const *names)
     entry[0].attrval.attrval_val = strdup (num);
 
     if (entry[0].attrval.attrval_val == NULL) {
-      reply_with_perror ("strdup");
+      reply_with_perror_gnulib ("strdup");
       goto error;
     }
   }
diff --git a/src/generator.ml b/src/generator.ml
index 9e602ac..129041d 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -5646,7 +5646,7 @@ and generate_daemon_actions () =
              pr "  %s = realloc (args.%s.%s_val,\n" n n n;
              pr "                sizeof (char *) * (args.%s.%s_len+1));\n" n n;
              pr "  if (%s == NULL) {\n" n;
-             pr "    reply_with_perror (\"realloc\");\n";
+             pr "    reply_with_perror_gnulib (\"realloc\");\n";
              pr "    goto done;\n";
              pr "  }\n";
              pr "  %s[args.%s.%s_len] = NULL;\n" n n n;
@@ -5898,7 +5898,7 @@ and generate_daemon_actions () =
         pr "\n";
         pr "  ret = malloc (sizeof *ret);\n";
         pr "  if (!ret) {\n";
-        pr "    reply_with_perror (\"malloc\");\n";
+        pr "    reply_with_perror_gnulib (\"malloc\");\n";
         pr "    return NULL;\n";
         pr "  }\n";
         pr "\n";
@@ -5941,7 +5941,7 @@ and generate_daemon_actions () =
         pr "    newp = realloc (ret->guestfs_int_lvm_%s_list_val,\n" typ;
         pr "		    sizeof (guestfs_int_lvm_%s) * (i+1));\n" typ;
         pr "    if (newp == NULL) {\n";
-        pr "      reply_with_perror (\"realloc\");\n";
+        pr "      reply_with_perror_gnulib (\"realloc\");\n";
         pr "      free (ret->guestfs_int_lvm_%s_list_val);\n" typ;
         pr "      free (ret);\n";
         pr "      free (out);\n";
-- 
1.6.5.2



More information about the Libguestfs mailing list