daemon: ldm: Don't return an error if /dev/mapper doesn't exist.

This commit is contained in:
Richard W.M. Jones
2013-08-10 12:39:40 +01:00
parent 1d7c3a2782
commit 2089f7a21a
3 changed files with 37 additions and 2 deletions

View File

@@ -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))

View File

@@ -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.
*/

View File

@@ -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_*");
}