[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [nbdkit PATCH] file: Diagnose a missing file earlier

If a user typos the filename for the file plugin, they do not
find out about it until later when the first client gets an
abrupt hangup, when file_open() fails to open things.  Better
is to avoid starting a server at all if the file doesn't exist

While at it, avoid a memory leak if the caller passes a file=
argument more than once.

Signed-off-by: Eric Blake <eblake redhat com>
 plugins/file/file.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/plugins/file/file.c b/plugins/file/file.c
index ef5da3d..4a91251 100644
--- a/plugins/file/file.c
+++ b/plugins/file/file.c
@@ -117,6 +117,7 @@ file_config (const char *key, const char *value)
   if (strcmp (key, "file") == 0) {
     /* See FILENAMES AND PATHS in nbdkit-plugin(3). */
+    free (filename);
     filename = nbdkit_absolute_path (value);
     if (!filename)
       return -1;
@@ -147,6 +148,10 @@ file_config_complete (void)
     nbdkit_error ("you must supply the file=<FILENAME> parameter after the plugin name on the command line");
     return -1;
+  if (access (filename, F_OK) < 0) {
+    nbdkit_error ("access '%s': %m", filename);
+    return -1;
+  }

   return 0;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]