2729bd
From b97b90779d5ea261d5e737f073bb4ec5dc546511 Mon Sep 17 00:00:00 2001
2729bd
From: Laszlo Ersek <lersek@redhat.com>
2729bd
Date: Mon, 2 May 2022 10:56:00 +0200
2729bd
Subject: [PATCH] guestfs_readdir(): rewrite with FileOut transfer, to lift
2729bd
 protocol limit
2729bd
2729bd
Currently the guestfs_readdir() API can not list long directories, due to
2729bd
it sending back the whole directory listing in a single guestfs protocol
2729bd
response, which is limited to GUESTFS_MESSAGE_MAX (approx. 4MB) in size.
2729bd
2729bd
Introduce the "internal_readdir" action, for transferring the directory
2729bd
listing from the daemon to the library through a FileOut parameter.
2729bd
Rewrite guestfs_readdir() on top of this new internal function:
2729bd
2729bd
- The new "internal_readdir" action is a daemon action. Do not repurpose
2729bd
  the "readdir" proc_nr (138) for "internal_readdir", as some distros ship
2729bd
  the binary appliance to their users, and reusing the proc_nr could
2729bd
  create a mismatch between library & appliance with obscure symptoms.
2729bd
  Replace the old proc_nr (138) with a new proc_nr (511) instead; a
2729bd
  mismatch would then produce a clear error message. Assume the new action
2729bd
  will first be released in libguestfs-1.48.2.
2729bd
2729bd
- Turn "readdir" from a daemon action into a non-daemon one. Call the
2729bd
  daemon action guestfs_internal_readdir() manually, receive the FileOut
2729bd
  parameter into a temp file, then deserialize the dirents array from the
2729bd
  temp file.
2729bd
2729bd
This patch sneakily fixes an independent bug, too. In the pre-patch
2729bd
do_readdir() function [daemon/readdir.c], when readdir() returns NULL, we
2729bd
don't distinguish "end of directory stream" from "readdir() failed". This
2729bd
rewrite fixes this problem -- I didn't see much value separating out the
2729bd
fix for the original do_readdir().
2729bd
2729bd
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1674392
2729bd
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
2729bd
Message-Id: <20220502085601.15012-2-lersek@redhat.com>
2729bd
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2729bd
(cherry picked from commit 45b7f1736b64e9f0741e21e5a9d83a837bd863bf)
2729bd
---
2729bd
 TODO                      |   8 ---
2729bd
 daemon/readdir.c          | 132 +++++++++++++++++++-------------------
2729bd
 generator/actions_core.ml | 127 +++++++++++++++++++-----------------
2729bd
 generator/proc_nr.ml      |   2 +-
2729bd
 lib/MAX_PROC_NR           |   2 +-
2729bd
 lib/Makefile.am           |   1 +
2729bd
 lib/readdir.c             | 131 +++++++++++++++++++++++++++++++++++++
2729bd
 7 files changed, 267 insertions(+), 136 deletions(-)
2729bd
 create mode 100644 lib/readdir.c
2729bd
2729bd
diff --git a/TODO b/TODO
2729bd
index a50f7d73c..513e55f92 100644
2729bd
--- a/TODO
2729bd
+++ b/TODO
2729bd
@@ -484,14 +484,6 @@ this approach works, it doesn't solve the MBR problem, so likely we'd
2729bd
 have to write a library for that (or perhaps go back to sfdisk but
2729bd
 using a very abstracted interface over sfdisk).
2729bd
 
2729bd
-Reimplement some APIs to avoid protocol limits
2729bd
-----------------------------------------------
2729bd
-
2729bd
-Mostly this item was done (eg. commits a69f44f56f and before).  The
2729bd
-most notable API with a protocol limit remaining is:
2729bd
-
2729bd
- - guestfs_readdir
2729bd
-
2729bd
 hivex
2729bd
 -----
2729bd
 
2729bd
diff --git a/daemon/readdir.c b/daemon/readdir.c
2729bd
index e488f93e7..9ab0b0aec 100644
2729bd
--- a/daemon/readdir.c
2729bd
+++ b/daemon/readdir.c
2729bd
@@ -16,77 +16,67 @@
2729bd
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2729bd
  */
2729bd
 
2729bd
-#include <config.h>
2729bd
+#include <config.h> /* HAVE_STRUCT_DIRENT_D_TYPE */
2729bd
 
2729bd
-#include <stdio.h>
2729bd
-#include <stdlib.h>
2729bd
-#include <string.h>
2729bd
-#include <unistd.h>
2729bd
-#include <dirent.h>
2729bd
+#include <dirent.h>    /* readdir() */
2729bd
+#include <errno.h>     /* errno */
2729bd
+#include <rpc/xdr.h>   /* xdrmem_create() */
2729bd
+#include <stdio.h>     /* perror() */
2729bd
+#include <stdlib.h>    /* malloc() */
2729bd
+#include <sys/types.h> /* opendir() */
2729bd
 
2729bd
-#include "daemon.h"
2729bd
-#include "actions.h"
2729bd
+#include "daemon.h" /* reply_with_perror() */
2729bd
 
2729bd
-static void
2729bd
-free_int_dirent_list (guestfs_int_dirent *p, size_t len)
2729bd
+/* Has one FileOut parameter. */
2729bd
+int
2729bd
+do_internal_readdir (const char *dir)
2729bd
 {
2729bd
-  size_t i;
2729bd
+  int ret;
2729bd
+  DIR *dirstream;
2729bd
+  void *xdr_buf;
2729bd
+  XDR xdr;
2729bd
 
2729bd
-  for (i = 0; i < len; ++i) {
2729bd
-    free (p[i].name);
2729bd
-  }
2729bd
-  free (p);
2729bd
-}
2729bd
-
2729bd
-guestfs_int_dirent_list *
2729bd
-do_readdir (const char *path)
2729bd
-{
2729bd
-  guestfs_int_dirent_list *ret;
2729bd
-  guestfs_int_dirent v;
2729bd
-  DIR *dir;
2729bd
-  struct dirent *d;
2729bd
-  size_t i;
2729bd
-
2729bd
-  ret = malloc (sizeof *ret);
2729bd
-  if (ret == NULL) {
2729bd
-    reply_with_perror ("malloc");
2729bd
-    return NULL;
2729bd
-  }
2729bd
-
2729bd
-  ret->guestfs_int_dirent_list_len = 0;
2729bd
-  ret->guestfs_int_dirent_list_val = NULL;
2729bd
+  /* Prepare to fail. */
2729bd
+  ret = -1;
2729bd
 
2729bd
   CHROOT_IN;
2729bd
-  dir = opendir (path);
2729bd
+  dirstream = opendir (dir);
2729bd
   CHROOT_OUT;
2729bd
 
2729bd
-  if (dir == NULL) {
2729bd
-    reply_with_perror ("opendir: %s", path);
2729bd
-    free (ret);
2729bd
-    return NULL;
2729bd
+  if (dirstream == NULL) {
2729bd
+    reply_with_perror ("opendir: %s", dir);
2729bd
+    return ret;
2729bd
   }
2729bd
 
2729bd
-  i = 0;
2729bd
-  while ((d = readdir (dir)) != NULL) {
2729bd
-    guestfs_int_dirent *p;
2729bd
+  xdr_buf = malloc (GUESTFS_MAX_CHUNK_SIZE);
2729bd
+  if (xdr_buf == NULL) {
2729bd
+    reply_with_perror ("malloc");
2729bd
+    goto close_dir;
2729bd
+  }
2729bd
+  xdrmem_create (&xdr, xdr_buf, GUESTFS_MAX_CHUNK_SIZE, XDR_ENCODE);
2729bd
+
2729bd
+  /* Send an "OK" reply, before starting the file transfer. */
2729bd
+  reply (NULL, NULL);
2729bd
+
2729bd
+  /* From this point on, we can only report errors by canceling the file
2729bd
+   * transfer.
2729bd
+   */
2729bd
+  for (;;) {
2729bd
+    struct dirent *d;
2729bd
+    guestfs_int_dirent v;
2729bd
+
2729bd
+    errno = 0;
2729bd
+    d = readdir (dirstream);
2729bd
+    if (d == NULL) {
2729bd
+      if (errno == 0)
2729bd
+        ret = 0;
2729bd
+      else
2729bd
+        perror ("readdir");
2729bd
 
2729bd
-    p = realloc (ret->guestfs_int_dirent_list_val,
2729bd
-                 sizeof (guestfs_int_dirent) * (i+1));
2729bd
-    v.name = strdup (d->d_name);
2729bd
-    if (!p || !v.name) {
2729bd
-      reply_with_perror ("allocate");
2729bd
-      if (p) {
2729bd
-        free_int_dirent_list (p, i);
2729bd
-      } else {
2729bd
-        free_int_dirent_list (ret->guestfs_int_dirent_list_val, i);
2729bd
-      }
2729bd
-      free (v.name);
2729bd
-      free (ret);
2729bd
-      closedir (dir);
2729bd
-      return NULL;
2729bd
+      break;
2729bd
     }
2729bd
-    ret->guestfs_int_dirent_list_val = p;
2729bd
 
2729bd
+    v.name = d->d_name;
2729bd
     v.ino = d->d_ino;
2729bd
 #ifdef HAVE_STRUCT_DIRENT_D_TYPE
2729bd
     switch (d->d_type) {
2729bd
@@ -104,19 +94,29 @@ do_readdir (const char *path)
2729bd
     v.ftyp = 'u';
2729bd
 #endif
2729bd
 
2729bd
-    ret->guestfs_int_dirent_list_val[i] = v;
2729bd
+    if (!xdr_guestfs_int_dirent (&xdr, &v)) {
2729bd
+      fprintf (stderr, "xdr_guestfs_int_dirent failed\n");
2729bd
+      break;
2729bd
+    }
2729bd
 
2729bd
-    i++;
2729bd
+    if (send_file_write (xdr_buf, xdr_getpos (&xdr)) != 0)
2729bd
+      break;
2729bd
+
2729bd
+    xdr_setpos (&xdr, 0);
2729bd
   }
2729bd
 
2729bd
-  ret->guestfs_int_dirent_list_len = i;
2729bd
+  /* Finish or cancel the transfer. Note that if (ret == -1) because the library
2729bd
+   * canceled, we still need to cancel back!
2729bd
+   */
2729bd
+  send_file_end (ret == -1);
2729bd
 
2729bd
-  if (closedir (dir) == -1) {
2729bd
-    reply_with_perror ("closedir");
2729bd
-    free (ret->guestfs_int_dirent_list_val);
2729bd
-    free (ret);
2729bd
-    return NULL;
2729bd
-  }
2729bd
+  xdr_destroy (&xdr;;
2729bd
+  free (xdr_buf);
2729bd
+
2729bd
+close_dir:
2729bd
+  if (closedir (dirstream) == -1)
2729bd
+    /* Best we can do here is log an error. */
2729bd
+    perror ("closedir");
2729bd
 
2729bd
   return ret;
2729bd
 }
2729bd
diff --git a/generator/actions_core.ml b/generator/actions_core.ml
2729bd
index dc12fdc33..807150615 100644
2729bd
--- a/generator/actions_core.ml
2729bd
+++ b/generator/actions_core.ml
2729bd
@@ -141,6 +141,66 @@ only useful for printing debug and internal error messages.
2729bd
 
2729bd
 For more information on states, see L<guestfs(3)>." };
2729bd
 
2729bd
+  { defaults with
2729bd
+    name = "readdir"; added = (1, 0, 55);
2729bd
+    style = RStructList ("entries", "dirent"), [String (Pathname, "dir")], [];
2729bd
+    progress = true; cancellable = true;
2729bd
+    shortdesc = "read directories entries";
2729bd
+    longdesc = "\
2729bd
+This returns the list of directory entries in directory C<dir>.
2729bd
+
2729bd
+All entries in the directory are returned, including C<.> and
2729bd
+C<..>.  The entries are I<not> sorted, but returned in the same
2729bd
+order as the underlying filesystem.
2729bd
+
2729bd
+Also this call returns basic file type information about each
2729bd
+file.  The C<ftyp> field will contain one of the following characters:
2729bd
+
2729bd
+=over 4
2729bd
+
2729bd
+=item 'b'
2729bd
+
2729bd
+Block special
2729bd
+
2729bd
+=item 'c'
2729bd
+
2729bd
+Char special
2729bd
+
2729bd
+=item 'd'
2729bd
+
2729bd
+Directory
2729bd
+
2729bd
+=item 'f'
2729bd
+
2729bd
+FIFO (named pipe)
2729bd
+
2729bd
+=item 'l'
2729bd
+
2729bd
+Symbolic link
2729bd
+
2729bd
+=item 'r'
2729bd
+
2729bd
+Regular file
2729bd
+
2729bd
+=item 's'
2729bd
+
2729bd
+Socket
2729bd
+
2729bd
+=item 'u'
2729bd
+
2729bd
+Unknown file type
2729bd
+
2729bd
+=item '?'
2729bd
+
2729bd
+The L<readdir(3)> call returned a C<d_type> field with an
2729bd
+unexpected value
2729bd
+
2729bd
+=back
2729bd
+
2729bd
+This function is primarily intended for use by programs.  To
2729bd
+get a simple list of names, use C<guestfs_ls>.  To get a printable
2729bd
+directory for human consumption, use C<guestfs_ll>." };
2729bd
+
2729bd
   { defaults with
2729bd
     name = "version"; added = (1, 0, 58);
2729bd
     style = RStruct ("version", "version"), [], [];
2729bd
@@ -3939,66 +3999,6 @@ L<umask(2)>, C<guestfs_mknod>, C<guestfs_mkdir>.
2729bd
 
2729bd
 This call returns the previous umask." };
2729bd
 
2729bd
-  { defaults with
2729bd
-    name = "readdir"; added = (1, 0, 55);
2729bd
-    style = RStructList ("entries", "dirent"), [String (Pathname, "dir")], [];
2729bd
-    protocol_limit_warning = true;
2729bd
-    shortdesc = "read directories entries";
2729bd
-    longdesc = "\
2729bd
-This returns the list of directory entries in directory C<dir>.
2729bd
-
2729bd
-All entries in the directory are returned, including C<.> and
2729bd
-C<..>.  The entries are I<not> sorted, but returned in the same
2729bd
-order as the underlying filesystem.
2729bd
-
2729bd
-Also this call returns basic file type information about each
2729bd
-file.  The C<ftyp> field will contain one of the following characters:
2729bd
-
2729bd
-=over 4
2729bd
-
2729bd
-=item 'b'
2729bd
-
2729bd
-Block special
2729bd
-
2729bd
-=item 'c'
2729bd
-
2729bd
-Char special
2729bd
-
2729bd
-=item 'd'
2729bd
-
2729bd
-Directory
2729bd
-
2729bd
-=item 'f'
2729bd
-
2729bd
-FIFO (named pipe)
2729bd
-
2729bd
-=item 'l'
2729bd
-
2729bd
-Symbolic link
2729bd
-
2729bd
-=item 'r'
2729bd
-
2729bd
-Regular file
2729bd
-
2729bd
-=item 's'
2729bd
-
2729bd
-Socket
2729bd
-
2729bd
-=item 'u'
2729bd
-
2729bd
-Unknown file type
2729bd
-
2729bd
-=item '?'
2729bd
-
2729bd
-The L<readdir(3)> call returned a C<d_type> field with an
2729bd
-unexpected value
2729bd
-
2729bd
-=back
2729bd
-
2729bd
-This function is primarily intended for use by programs.  To
2729bd
-get a simple list of names, use C<guestfs_ls>.  To get a printable
2729bd
-directory for human consumption, use C<guestfs_ll>." };
2729bd
-
2729bd
   { defaults with
2729bd
     name = "getxattrs"; added = (1, 0, 59);
2729bd
     style = RStructList ("xattrs", "xattr"), [String (Pathname, "path")], [];
2729bd
@@ -9713,4 +9713,11 @@ C<guestfs_cryptsetup_open>.  The C<device> parameter must be
2729bd
 the name of the mapping device (ie. F</dev/mapper/mapname>)
2729bd
 and I<not> the name of the underlying block device." };
2729bd
 
2729bd
+  { defaults with
2729bd
+    name = "internal_readdir"; added = (1, 48, 2);
2729bd
+    style = RErr, [String (Pathname, "dir"); String (FileOut, "filename")], [];
2729bd
+    visibility = VInternal;
2729bd
+    shortdesc = "read directories entries";
2729bd
+    longdesc = "Internal function for readdir." };
2729bd
+
2729bd
 ]
2729bd
diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml
2729bd
index b20672ff0..bdced51c9 100644
2729bd
--- a/generator/proc_nr.ml
2729bd
+++ b/generator/proc_nr.ml
2729bd
@@ -152,7 +152,6 @@ let proc_nr = [
2729bd
 135, "mknod_b";
2729bd
 136, "mknod_c";
2729bd
 137, "umask";
2729bd
-138, "readdir";
2729bd
 139, "sfdiskM";
2729bd
 140, "zfile";
2729bd
 141, "getxattrs";
2729bd
@@ -514,6 +513,7 @@ let proc_nr = [
2729bd
 508, "cryptsetup_open";
2729bd
 509, "cryptsetup_close";
2729bd
 510, "internal_list_rpm_applications";
2729bd
+511, "internal_readdir";
2729bd
 ]
2729bd
 
2729bd
 (* End of list.  If adding a new entry, add it at the end of the list
2729bd
diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR
2729bd
index 2bc4cd64b..c0556fb20 100644
2729bd
--- a/lib/MAX_PROC_NR
2729bd
+++ b/lib/MAX_PROC_NR
2729bd
@@ -1 +1 @@
2729bd
-510
2729bd
+511
2729bd
diff --git a/lib/Makefile.am b/lib/Makefile.am
2729bd
index 144c45588..212bcb94a 100644
2729bd
--- a/lib/Makefile.am
2729bd
+++ b/lib/Makefile.am
2729bd
@@ -105,6 +105,7 @@ libguestfs_la_SOURCES = \
2729bd
 	private-data.c \
2729bd
 	proto.c \
2729bd
 	qemu.c \
2729bd
+	readdir.c \
2729bd
 	rescue.c \
2729bd
 	stringsbuf.c \
2729bd
 	structs-compare.c \
2729bd
diff --git a/lib/readdir.c b/lib/readdir.c
2729bd
new file mode 100644
2729bd
index 000000000..9cb0d7cf6
2729bd
--- /dev/null
2729bd
+++ b/lib/readdir.c
2729bd
@@ -0,0 +1,131 @@
2729bd
+/* libguestfs
2729bd
+ * Copyright (C) 2016-2022 Red Hat Inc.
2729bd
+ *
2729bd
+ * This library is free software; you can redistribute it and/or
2729bd
+ * modify it under the terms of the GNU Lesser General Public
2729bd
+ * License as published by the Free Software Foundation; either
2729bd
+ * version 2 of the License, or (at your option) any later version.
2729bd
+ *
2729bd
+ * This library is distributed in the hope that it will be useful,
2729bd
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2729bd
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2729bd
+ * Lesser General Public License for more details.
2729bd
+ *
2729bd
+ * You should have received a copy of the GNU Lesser General Public
2729bd
+ * License along with this library; if not, write to the Free Software
2729bd
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2729bd
+ */
2729bd
+
2729bd
+#include <config.h> /* UNIX_PATH_MAX, needed by "guestfs-internal.h" */
2729bd
+
2729bd
+#include <rpc/xdr.h> /* xdrstdio_create() */
2729bd
+#include <stdint.h>  /* UINT32_MAX */
2729bd
+#include <stdio.h>   /* fopen() */
2729bd
+#include <string.h>  /* memset() */
2729bd
+
2729bd
+#include "guestfs.h"                  /* guestfs_internal_readdir() */
2729bd
+#include "guestfs_protocol.h"         /* guestfs_int_dirent */
2729bd
+#include "guestfs-internal.h"         /* guestfs_int_make_temp_path() */
2729bd
+#include "guestfs-internal-actions.h" /* guestfs_impl_readdir */
2729bd
+
2729bd
+struct guestfs_dirent_list *
2729bd
+guestfs_impl_readdir (guestfs_h *g, const char *dir)
2729bd
+{
2729bd
+  struct guestfs_dirent_list *ret;
2729bd
+  char *tmpfn;
2729bd
+  FILE *f;
2729bd
+  off_t fsize;
2729bd
+  XDR xdr;
2729bd
+  struct guestfs_dirent_list *dirents;
2729bd
+  uint32_t alloc_entries;
2729bd
+  size_t alloc_bytes;
2729bd
+
2729bd
+  /* Prepare to fail. */
2729bd
+  ret = NULL;
2729bd
+
2729bd
+  tmpfn = guestfs_int_make_temp_path (g, "readdir", NULL);
2729bd
+  if (tmpfn == NULL)
2729bd
+    return ret;
2729bd
+
2729bd
+  if (guestfs_internal_readdir (g, dir, tmpfn) == -1)
2729bd
+    goto drop_tmpfile;
2729bd
+
2729bd
+  f = fopen (tmpfn, "r");
2729bd
+  if (f == NULL) {
2729bd
+    perrorf (g, "fopen: %s", tmpfn);
2729bd
+    goto drop_tmpfile;
2729bd
+  }
2729bd
+
2729bd
+  if (fseeko (f, 0, SEEK_END) == -1) {
2729bd
+    perrorf (g, "fseeko");
2729bd
+    goto close_tmpfile;
2729bd
+  }
2729bd
+  fsize = ftello (f);
2729bd
+  if (fsize == -1) {
2729bd
+    perrorf (g, "ftello");
2729bd
+    goto close_tmpfile;
2729bd
+  }
2729bd
+  if (fseeko (f, 0, SEEK_SET) == -1) {
2729bd
+    perrorf (g, "fseeko");
2729bd
+    goto close_tmpfile;
2729bd
+  }
2729bd
+
2729bd
+  xdrstdio_create (&xdr, f, XDR_DECODE);
2729bd
+
2729bd
+  dirents = safe_malloc (g, sizeof *dirents);
2729bd
+  dirents->len = 0;
2729bd
+  alloc_entries = 8;
2729bd
+  alloc_bytes = alloc_entries * sizeof *dirents->val;
2729bd
+  dirents->val = safe_malloc (g, alloc_bytes);
2729bd
+
2729bd
+  while (xdr_getpos (&xdr) < fsize) {
2729bd
+    guestfs_int_dirent v;
2729bd
+    struct guestfs_dirent *d;
2729bd
+
2729bd
+    if (dirents->len == alloc_entries) {
2729bd
+      if (alloc_entries > UINT32_MAX / 2 || alloc_bytes > (size_t)-1 / 2) {
2729bd
+        error (g, "integer overflow");
2729bd
+        goto free_dirents;
2729bd
+      }
2729bd
+      alloc_entries *= 2u;
2729bd
+      alloc_bytes *= 2u;
2729bd
+      dirents->val = safe_realloc (g, dirents->val, alloc_bytes);
2729bd
+    }
2729bd
+
2729bd
+    /* Decoding does not work unless the target buffer is zero-initialized. */
2729bd
+    memset (&v, 0, sizeof v);
2729bd
+    if (!xdr_guestfs_int_dirent (&xdr, &v)) {
2729bd
+      error (g, "xdr_guestfs_int_dirent failed");
2729bd
+      goto free_dirents;
2729bd
+    }
2729bd
+
2729bd
+    d = &dirents->val[dirents->len];
2729bd
+    d->ino = v.ino;
2729bd
+    d->ftyp = v.ftyp;
2729bd
+    d->name = v.name; /* transfer malloc'd string to "d" */
2729bd
+
2729bd
+    dirents->len++;
2729bd
+  }
2729bd
+
2729bd
+  /* Success; transfer "dirents" to "ret". */
2729bd
+  ret = dirents;
2729bd
+  dirents = NULL;
2729bd
+
2729bd
+  /* Clean up. */
2729bd
+  xdr_destroy (&xdr;;
2729bd
+
2729bd
+free_dirents:
2729bd
+  guestfs_free_dirent_list (dirents);
2729bd
+
2729bd
+close_tmpfile:
2729bd
+  fclose (f);
2729bd
+
2729bd
+drop_tmpfile:
2729bd
+  /* In case guestfs_internal_readdir() failed, it may or may not have created
2729bd
+   * the temporary file.
2729bd
+   */
2729bd
+  unlink (tmpfn);
2729bd
+  free (tmpfn);
2729bd
+
2729bd
+  return ret;
2729bd
+}
2729bd
-- 
2729bd
2.31.1
2729bd