From: "Richard W.M. Jones" <rjo...@redhat.com> (cherry picked from commit 2089f7a21a307402c3efa43e5d10ee8d5ff554fb) (cherry picked from commit 1879ba2cb0adcadb0b9a24cede21fa5e39bd898f) --- daemon/daemon.h | 2 ++ daemon/guestfsd.c | 14 ++++++++++++-- daemon/ldm.c | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index 8ca0593..544feb2 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -89,6 +89,8 @@ extern char *join_strings (const char *separator, char *const *argv); extern char **split_lines (char *str); +extern char **empty_list (void); + #define command(out,err,name,...) commandf((out),(err),0,(name),__VA_ARGS__) #define commandr(out,err,name,...) commandrf((out),(err),0,(name),__VA_ARGS__) #define commandv(out,err,argv) commandvf((out),(err),0,(argv)) diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 254e0ea..bba13f8 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -1086,7 +1086,7 @@ split_lines (char *str) char *p, *pend; if (STREQ (str, "")) - goto empty_list; + return empty_list (); p = str; while (p) { @@ -1107,13 +1107,23 @@ split_lines (char *str) p = pend; } - empty_list: if (end_stringsbuf (&lines) == -1) return NULL; return lines.argv; } +char ** +empty_list (void) +{ + DECLARE_STRINGSBUF (ret); + + if (end_stringsbuf (&ret) == -1) + return NULL; + + return ret.argv; +} + /* Skip leading and trailing whitespace, updating the original string * in-place. */ diff --git a/daemon/ldm.c b/daemon/ldm.c index b7ef301..aed8a0d 100644 --- a/daemon/ldm.c +++ b/daemon/ldm.c @@ -20,6 +20,9 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> #include <glob.h> #if HAVE_YAJL @@ -91,6 +94,16 @@ get_devices (const char *pattern) char ** do_list_ldm_volumes (void) { + struct stat buf; + + /* If /dev/mapper doesn't exist at all, don't give an error. */ + if (stat ("/dev/mapper", &buf) == -1) { + if (errno == ENOENT) + return empty_list (); + reply_with_perror ("/dev/mapper"); + return NULL; + } + return get_devices ("/dev/mapper/ldm_vol_*"); } @@ -98,6 +111,16 @@ do_list_ldm_volumes (void) char ** do_list_ldm_partitions (void) { + struct stat buf; + + /* If /dev/mapper doesn't exist at all, don't give an error. */ + if (stat ("/dev/mapper", &buf) == -1) { + if (errno == ENOENT) + return empty_list (); + reply_with_perror ("/dev/mapper"); + return NULL; + } + return get_devices ("/dev/mapper/ldm_part_*"); } -- 1.8.3.1 _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs