mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon: ldm: Don't return an error if /dev/mapper doesn't exist.
This commit is contained in:
@@ -105,6 +105,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))
|
||||
|
||||
@@ -1019,7 +1019,7 @@ split_lines (char *str)
|
||||
char *p, *pend;
|
||||
|
||||
if (STREQ (str, ""))
|
||||
goto empty_list;
|
||||
return empty_list ();
|
||||
|
||||
p = str;
|
||||
while (p) {
|
||||
@@ -1040,13 +1040,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.
|
||||
*/
|
||||
|
||||
23
daemon/ldm.c
23
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_*");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user