[PATCH] build: Choose a virtual directory for the daemon which is not a symlink.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
Check /sbin, /usr/sbin, /bin and /usr/bin to ensure that neither the
directory nor the parent (eg. /usr) is a symlink, and use this
directory for the virtual directory used to store guestfsd in the
appliance.
---
appliance/Makefile.am | 9 +++++----
configure.ac | 20 ++++++++++++++++++++
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/appliance/Makefile.am b/appliance/Makefile.am
index 99896be..fcf6422 100644
--- a/appliance/Makefile.am
+++ b/appliance/Makefile.am
@@ -67,10 +67,11 @@ stamp-supermin: make.sh packagelist excludelist
supermin.d/daemon.img: ../daemon/guestfsd
mkdir -p supermin.d
rm -f $@ $@-t
- mkdir sbin
- cd sbin && ln ../../daemon/guestfsd
- echo -e "sbin\nsbin/guestfsd" | cpio --quiet -o -H newc > $@-t
- rm -r sbin
+ rm -rf tmp
+ mkdir -p tmp/$(DAEMON_SUPERMIN_DIR)
+ cd tmp/$(DAEMON_SUPERMIN_DIR) && ln $(abs_top_builddir)/daemon/guestfsd
+ ( cd tmp && find | cpio --quiet -o -H newc ) > $@-t
+ rm -rf tmp
mv $@-t $@
supermin.d/init.img: init
diff --git a/configure.ac b/configure.ac
index 5caca32..3712d19 100644
--- a/configure.ac
+++ b/configure.ac
@@ -278,6 +278,26 @@ if test "x$enable_daemon" = "xyes"; then
AC_DEFINE([VALGRIND_DAEMON],[1],[Define to 1 to run the daemon under valgrind])
AC_DEFINE_UNQUOTED([VALGRIND_LOG_PATH],["$(pwd)"],[Path to save valgrind log files])
fi
+
+ dnl Which directory should we put the daemon in? NOTE: This
+ dnl is the "virtual" directory inside the appliance, not the
+ dnl install directory for libguestfs live. Since Fedora 17
+ dnl /sbin is a symlink to /usr/sbin. We have to put the
+ dnl daemon into a real (non-symlink) directory.
+ dirs="/sbin /usr/sbin /bin /usr/bin"
+ AC_MSG_CHECKING([which of $dirs is a real directory])
+ for dir in $dirs; do
+ parent=`dirname $dir`
+ if test -d $parent && test -d $dir; then
+ DAEMON_SUPERMIN_DIR=$dir
+ break
+ fi
+ done
+ if test "x$DAEMON_SUPERMIN_DIR" = "x"; then
+ AC_MSG_ERROR([non-symlink binary directory not found])
+ fi
+ AC_MSG_RESULT([$DAEMON_SUPERMIN_DIR])
+ AC_SUBST([DAEMON_SUPERMIN_DIR])
fi
AM_CONDITIONAL([INSTALL_DAEMON],[test "x$enable_install_daemon" = "xyes"])
AM_CONDITIONAL([VALGRIND_DAEMON],[test "x$enable_valgrind_daemon" = "xyes"])
--
1.7.6
12 years, 8 months
Attn Fedora Rawhide users
by Richard W.M. Jones
http://pkgs.fedoraproject.org/gitweb/?p=libguestfs.git;a=blob;f=0001-Work...
I have added this patch (not upstream) ^^
This is a workaround for a rather misguided feature called 'usrmove'
which was just dumped without notice into Rawhide, 3 days before the
F17 branch, while everyone was away at FOSDEM.
I still haven't got libguestfs to build after spending some time late
last night updating a VM to the latest Rawhide. With the patch above
there are still some MD tests that fail. That may just be a
coincidence or may be because usrmove has broken mdadm.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
12 years, 8 months
[PATCH] java: Rename JNI target, use JNI_INSTALL_DIR as provided through configure
by Hilko Bengen
This allows us to install the shared object to a different (e.g.
/usr/lib/jni) with less pain.
---
java/Makefile.am | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/java/Makefile.am b/java/Makefile.am
index ef78773..d9db6f4 100644
--- a/java/Makefile.am
+++ b/java/Makefile.am
@@ -67,7 +67,8 @@ libguestfs-${VERSION}.jar: $(libguestfs_jar_class_files)
# JNI source.
-lib_LTLIBRARIES = libguestfs_jni.la
+jnilib_LTLIBRARIES = libguestfs_jni.la
+jnilibdir = $(JNI_INSTALL_DIR)
libguestfs_jni_la_SOURCES = \
com_redhat_et_libguestfs_GuestFS.h \
com_redhat_et_libguestfs_GuestFS.c
--
1.7.9
12 years, 8 months
virt-v2v error - Fedora 16
by DE Clay
Trying to test virt-v2v using ESX. Running Fedora 16 and virt-v2v
0.8.5.
Command invocation:
virt-v2v -ic esx://testhostname/?no_verify=1 -os testpool --network
default testvm
Result:
Invalid configuration of Net::HTTPS
at /usr/share/perl5/vendor_perl/Sys/VirtConvert/Transfer/ESX.pm line 68.
Couldn't find a resolution to this issue on the net. Please assist.
12 years, 8 months
Re: [Libguestfs] [PATCH] hivexml
by Richard W.M. Jones
On Tue, Jan 31, 2012 at 12:21:44PM -0500, Todd Mummert wrote:
> I've made some changes to hivexml.c, that I think addresses the
> invalid XML that is being generated (as of version 1.3.3). I'm only
> addressing invalid XML characters in string values and string-lists.
> As I saw mentioned in earlier forum messages
> (https://www.redhat.com/archives/libguestfs/2011-September/msg00082.html),
> there could be invalid XML character issues in keys as well, but that
> is not addressed in this patch.
>
> Secondly, I slightly modified the string element in that I used a
> value attribute to more closely align with the earlier change that
> Alex did to singular string values.
>
> I've addressed the three of you because you all commented on the
> earlier patch, and I would like to get your feedback on mine. If
> you'd like me to post to the libguestfs mailing list, I could do so...
> let me know if there are patch standards that I should use.
>
> The approach I took was toI use XMLisCharQ() to check each UTF-8
> string value in value_string and value_mulitple_string.
>
>
>
> The issue I encountered was that the following UTF-8 string was
> occurring in a clean Win7 install --
>
> e689a4 02 eb8288c 7937 46 5
>
> The 02 (^B) is an invalid XML character in the 1.0 spec, and was
> causing xmllint to fail in the following manner
>
> [hivex-1.3.3-orig]# xmllint xmlout.orig
>
> xmlout.orig:2: parser error : PCDATA invalid Char value 2
> 18T02:23:42Z</mtime><value type="string-list" key="Autorecover MOFs"><string>æ¤
> ^
>
>
> After the patch, ...with all the surrounding stuff cut away
> [hivex-1.3.3-new]# xmllint xmlout.new | tidy -raw -xml -i
>
> <?xml version="1.0" encoding="utf-8"?>
> <hive>
> <mtime>2011-02-18T02:23:42Z</mtime>
> <value type="string-list" key="Autorecover MOFs">
> <string encoding="base64" value="5omkAuuCiMeTdGU=" />
> </value>
> </hive>
>
>
> And the patch itself...
>
> [hivex]# cat hivexml.patch
> diff -uprN hivex-1.3.3-orig/xml/hivexml.c hivex-1.3.3-new/xml/hivexml.c
> --- hivex-1.3.3-orig/xml/hivexml.c 2011-09-22 09:17:09.000000000 -0400
> +++ hivex-1.3.3-new/xml/hivexml.c 2012-01-30 23:39:14.995639422 -0500
> @@ -33,6 +33,7 @@
> #endif
>
> #include <libxml/xmlwriter.h>
> +#include <libxml/chvalid.h>
>
> #include "hivex.h"
>
> @@ -209,6 +210,22 @@ filetime_to_8601 (int64_t windows_ticks)
> }
>
> static int
> +isValidXMLString(const char *string)
Can we call this is_valid_xml_string? I hate camel-casing.
> +{
> + int c;
> + int len = strlen(string);
> + int pos = 0;
> + int charlen = len;
> + while ((c = xmlGetUTF8Char(string+pos, &charlen)) >= 0) {
> + if (xmlIsCharQ(c) == 0)
> + return 0;
> + pos += charlen;
> + charlen = len - pos;
> + }
> + return 1;
> +}
> +
> +static int
> node_start (hive_h *h, void *writer_v, hive_node_h node, const char *name)
> {
> int64_t last_modified;
> @@ -265,6 +282,20 @@ end_value (xmlTextWriterPtr writer)
> XML_CHECK (xmlTextWriterEndElement, (writer));
> }
>
> +static void
> +start_string(xmlTextWriterPtr writer, const char *encoding)
> +{
> + XML_CHECK (xmlTextWriterStartElement, (writer, BAD_CAST "string"));
> + if (encoding)
> + XML_CHECK (xmlTextWriterWriteAttribute, (writer, BAD_CAST
> "encoding", BAD_CAST encoding));
> +}
> +
> +static void
> +end_string(xmlTextWriterPtr writer)
> +{
> + XML_CHECK (xmlTextWriterEndElement, (writer));
> +}
> +
> static int
> value_string (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
> hive_type t, size_t len, const char *key, const char *str)
> @@ -292,9 +323,14 @@ value_string (hive_h *h, void *writer_v,
> type = "unknown";
> }
>
> - start_value (writer, key, type, NULL);
> + int validXML = isValidXMLString(str);
> + start_value (writer, key, type, validXML ? NULL : "base64");
> XML_CHECK (xmlTextWriterStartAttribute, (writer, BAD_CAST "value"));
> - XML_CHECK (xmlTextWriterWriteString, (writer, BAD_CAST str));
> + if (validXML)
> + XML_CHECK (xmlTextWriterWriteString, (writer, BAD_CAST str));
> + else
> + XML_CHECK (xmlTextWriterWriteBase64, (writer, str, 0, strlen(str)));
> +
> XML_CHECK (xmlTextWriterEndAttribute, (writer));
> end_value (writer);
> return 0;
> @@ -310,9 +346,14 @@ value_multiple_strings (hive_h *h, void
>
> size_t i;
> for (i = 0; argv[i] != NULL; ++i) {
> - XML_CHECK (xmlTextWriterStartElement, (writer, BAD_CAST "string"));
> - XML_CHECK (xmlTextWriterWriteString, (writer, BAD_CAST argv[i]));
> - XML_CHECK (xmlTextWriterEndElement, (writer));
> + int validXML = isValidXMLString(argv[i]);
> + start_string(writer, validXML ? NULL : "base64");
> + XML_CHECK (xmlTextWriterStartAttribute, (writer, BAD_CAST "value"));
> + if (validXML)
> + XML_CHECK (xmlTextWriterWriteString, (writer, BAD_CAST argv[i]));
> + else
> + XML_CHECK (xmlTextWriterWriteBase64, (writer, argv[i], 0,
> strlen(argv[i])));
> + end_string(writer);
> }
>
> end_value (writer);
> [hivex]#
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
12 years, 8 months
[PATCH] Clarify the error message when unavailable functions are called (RHBZ#679737).
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
Callers are supposed to use the availability API to check for
functions that may not be available in particular builds of
libguestfs. If they don't do this, currently they tend to get obscure
error messages, eg:
libguestfs: error: zerofree: /dev/vda1: zerofree: No such file or directory
This commit changes the error message to explain what callers ought to
be doing instead:
libguestfs: error: zerofree: feature 'zerofree' is not available in this
build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for
how to check for the availability of features.
This patch makes the stubs check for availability. The stub code
changes to:
static void
zerofree_stub (XDR *xdr_in)
{
[...]
/* The caller should have checked before calling this. */
if (! optgroup_zerofree_available ()) {
reply_with_error ("feature '%s' is not available in this\n"
"build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\n"
"how to check for the availability of features.",
"zerofree");
goto done;
}
[...]
---
daemon/augeas.c | 158 +++++++++++++++++++++++++++--------------
daemon/daemon.h | 10 ---
daemon/inotify.c | 81 +++++++++++++--------
daemon/mknod.c | 45 +++++++++---
daemon/realpath.c | 26 +++++--
daemon/selinux.c | 40 ++++++++---
daemon/xattr.c | 23 ++++---
generator/generator_daemon.ml | 24 ++++++-
8 files changed, 271 insertions(+), 136 deletions(-)
diff --git a/daemon/augeas.c b/daemon/augeas.c
index f52c091..4a09f57 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -63,19 +63,11 @@ optgroup_augeas_available (void)
{
return 1;
}
-#else /* !HAVE_AUGEAS */
-int
-optgroup_augeas_available (void)
-{
- return 0;
-}
-#endif
/* We need to rewrite the root path so it is based at /sysroot. */
int
do_aug_init (const char *root, int flags)
{
-#ifdef HAVE_AUGEAS
char *buf;
if (aug) {
@@ -98,24 +90,17 @@ do_aug_init (const char *root, int flags)
}
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
do_aug_close (void)
{
-#ifdef HAVE_AUGEAS
NEED_AUG(-1);
aug_close (aug);
aug = NULL;
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
@@ -133,7 +118,8 @@ do_aug_defvar (const char *name, const char *expr)
}
return r;
#else
- NOT_AVAILABLE (-1);
+ reply_with_error ("function not available");
+ return -1;
#endif
}
@@ -163,14 +149,14 @@ do_aug_defnode (const char *name, const char *expr, const char *val)
return r;
#else
- NOT_AVAILABLE (NULL);
+ reply_with_error ("function not available");
+ return NULL;
#endif
}
char *
do_aug_get (const char *path)
{
-#ifdef HAVE_AUGEAS
const char *value = NULL;
char *v;
int r;
@@ -204,15 +190,11 @@ do_aug_get (const char *path)
}
return v; /* Caller frees. */
-#else
- NOT_AVAILABLE (NULL);
-#endif
}
int
do_aug_set (const char *path, const char *val)
{
-#ifdef HAVE_AUGEAS
int r;
NEED_AUG (-1);
@@ -224,15 +206,11 @@ do_aug_set (const char *path, const char *val)
}
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
do_aug_clear (const char *path)
{
-#ifdef HAVE_AUGEAS
int r;
NEED_AUG (-1);
@@ -244,15 +222,11 @@ do_aug_clear (const char *path)
}
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
do_aug_insert (const char *path, const char *label, int before)
{
-#ifdef HAVE_AUGEAS
int r;
NEED_AUG (-1);
@@ -264,15 +238,11 @@ do_aug_insert (const char *path, const char *label, int before)
}
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
do_aug_rm (const char *path)
{
-#ifdef HAVE_AUGEAS
int r;
NEED_AUG (-1);
@@ -284,15 +254,11 @@ do_aug_rm (const char *path)
}
return r;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
do_aug_mv (const char *src, const char *dest)
{
-#ifdef HAVE_AUGEAS
int r;
NEED_AUG (-1);
@@ -304,15 +270,11 @@ do_aug_mv (const char *src, const char *dest)
}
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
char **
do_aug_match (const char *path)
{
-#ifdef HAVE_AUGEAS
char **matches = NULL;
void *vp;
int r;
@@ -338,15 +300,11 @@ do_aug_match (const char *path)
matches[r] = NULL;
return matches; /* Caller frees. */
-#else
- NOT_AVAILABLE (NULL);
-#endif
}
int
do_aug_save (void)
{
-#ifdef HAVE_AUGEAS
NEED_AUG (-1);
if (aug_save (aug) == -1) {
@@ -355,9 +313,6 @@ do_aug_save (void)
}
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
@@ -373,7 +328,8 @@ do_aug_load (void)
return 0;
#else
- NOT_AVAILABLE (-1);
+ reply_with_error ("function not available");
+ return -1;
#endif
}
@@ -381,7 +337,6 @@ do_aug_load (void)
char **
do_aug_ls (const char *path)
{
-#ifdef HAVE_AUGEAS
char **matches;
char *buf;
int len;
@@ -420,7 +375,102 @@ do_aug_ls (const char *path)
sort_strings (matches, count_strings ((void *) matches));
return matches; /* Caller frees. */
-#else
- NOT_AVAILABLE (NULL);
-#endif
}
+
+#else /* !HAVE_AUGEAS */
+
+/* Note that the wrapper code (daemon/stubs.c) ensures that the
+ * functions below are never called because optgroup_augeas_available
+ * returns false.
+ */
+int
+optgroup_augeas_available (void)
+{
+ return 0;
+}
+
+int
+do_aug_init (const char *root, int flags)
+{
+ abort ();
+}
+
+int
+do_aug_close (void)
+{
+ abort ();
+}
+
+int
+do_aug_defvar (const char *name, const char *expr)
+{
+ abort ();
+}
+
+guestfs_int_int_bool *
+do_aug_defnode (const char *name, const char *expr, const char *val)
+{
+ abort ();
+}
+
+char *
+do_aug_get (const char *path)
+{
+ abort ();
+}
+
+int
+do_aug_set (const char *path, const char *val)
+{
+ abort ();
+}
+
+int
+do_aug_clear (const char *path)
+{
+ abort ();
+}
+
+int
+do_aug_insert (const char *path, const char *label, int before)
+{
+ abort ();
+}
+
+int
+do_aug_rm (const char *path)
+{
+ abort ();
+}
+
+int
+do_aug_mv (const char *src, const char *dest)
+{
+ abort ();
+}
+
+char **
+do_aug_match (const char *path)
+{
+ abort ();
+}
+
+int
+do_aug_save (void)
+{
+ abort ();
+}
+
+int
+do_aug_load (void)
+{
+ abort ();
+}
+
+char **
+do_aug_ls (const char *path)
+{
+ abort ();
+}
+
+#endif
diff --git a/daemon/daemon.h b/daemon/daemon.h
index babe5bc..b518f92 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -331,16 +331,6 @@ is_zero (const char *buffer, size_t size)
} \
while (0)
-/* Marks functions which are not available.
- * NB. Cannot be used for FileIn functions.
- */
-#define NOT_AVAILABLE(errcode) \
- do { \
- reply_with_error ("%s: function not available", __func__); \
- return (errcode); \
- } \
- while (0)
-
#ifndef __attribute__
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
# define __attribute__(x) /* empty */
diff --git a/daemon/inotify.c b/daemon/inotify.c
index add1f14..df6b2e8 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -56,13 +56,6 @@ optgroup_inotify_available (void)
{
return 1;
}
-#else /* !HAVE_SYS_INOTIFY_H */
-int
-optgroup_inotify_available (void)
-{
- return 0;
-}
-#endif
/* Because inotify_init does NEED_ROOT, NEED_INOTIFY implies NEED_ROOT. */
#define NEED_INOTIFY(errcode) \
@@ -78,7 +71,6 @@ optgroup_inotify_available (void)
int
do_inotify_init (int max_events)
{
-#ifdef HAVE_SYS_INOTIFY_H
FILE *fp;
NEED_ROOT (, return -1);
@@ -129,15 +121,11 @@ do_inotify_init (int max_events)
#endif
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
do_inotify_close (void)
{
-#ifdef HAVE_SYS_INOTIFY_H
NEED_INOTIFY (-1);
if (inotify_fd == -1) {
@@ -154,15 +142,11 @@ do_inotify_close (void)
inotify_posn = 0;
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int64_t
do_inotify_add_watch (const char *path, int mask)
{
-#ifdef HAVE_SYS_INOTIFY_H
int64_t r;
char *buf;
@@ -182,15 +166,11 @@ do_inotify_add_watch (const char *path, int mask)
}
return r;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
do_inotify_rm_watch (int wd)
{
-#ifdef HAVE_SYS_INOTIFY_H
NEED_INOTIFY (-1);
if (inotify_rm_watch (inotify_fd, wd) == -1) {
@@ -199,15 +179,11 @@ do_inotify_rm_watch (int wd)
}
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
guestfs_int_inotify_event_list *
do_inotify_read (void)
{
-#ifdef HAVE_SYS_INOTIFY_H
int space;
guestfs_int_inotify_event_list *ret;
@@ -313,15 +289,11 @@ do_inotify_read (void)
xdr_free ((xdrproc_t) xdr_guestfs_int_inotify_event_list, (char *) ret);
free (ret);
return NULL;
-#else
- NOT_AVAILABLE (NULL);
-#endif
}
char **
do_inotify_files (void)
{
-#ifdef HAVE_SYS_INOTIFY_H
char **ret = NULL;
int size = 0, alloc = 0;
unsigned int i;
@@ -404,7 +376,54 @@ do_inotify_files (void)
unlink (tempfile);
return NULL;
-#else
- NOT_AVAILABLE (NULL);
-#endif
}
+
+#else /* !HAVE_SYS_INOTIFY_H */
+
+/* Note that the wrapper code (daemon/stubs.c) ensures that the
+ * functions below are never called because optgroup_inotify_available
+ * returns false.
+ */
+int
+optgroup_inotify_available (void)
+{
+ return 0;
+}
+
+int
+do_inotify_init (int max_events)
+{
+ abort ();
+}
+
+int
+do_inotify_close (void)
+{
+ abort ();
+}
+
+int64_t
+do_inotify_add_watch (const char *path, int mask)
+{
+ abort ();
+}
+
+int
+do_inotify_rm_watch (int wd)
+{
+ abort ();
+}
+
+guestfs_int_inotify_event_list *
+do_inotify_read (void)
+{
+ abort ();
+}
+
+char **
+do_inotify_files (void)
+{
+ abort ();
+}
+
+#endif
diff --git a/daemon/mknod.c b/daemon/mknod.c
index d5b8467..6e678fd 100644
--- a/daemon/mknod.c
+++ b/daemon/mknod.c
@@ -37,18 +37,10 @@ optgroup_mknod_available (void)
{
return 1;
}
-#else
-int
-optgroup_mknod_available (void)
-{
- return 0;
-}
-#endif
int
do_mknod (int mode, int devmajor, int devminor, const char *path)
{
-#ifdef HAVE_MKNOD
int r;
if (mode < 0) {
@@ -66,9 +58,6 @@ do_mknod (int mode, int devmajor, int devminor, const char *path)
}
return 0;
-#else
- NOT_AVAILABLE (-1);
-#endif
}
int
@@ -88,3 +77,37 @@ do_mknod_c (int mode, int devmajor, int devminor, const char *path)
{
return do_mknod (mode | S_IFCHR, devmajor, devminor, path);
}
+
+#else
+
+int
+optgroup_mknod_available (void)
+{
+ return 0;
+}
+
+int
+do_mknod (int mode, int devmajor, int devminor, const char *path)
+{
+ abort ();
+}
+
+int
+do_mkfifo (int mode, const char *path)
+{
+ abort ();
+}
+
+int
+do_mknod_b (int mode, int devmajor, int devminor, const char *path)
+{
+ abort ();
+}
+
+int
+do_mknod_c (int mode, int devmajor, int devminor, const char *path)
+{
+ abort ();
+}
+
+#endif
diff --git a/daemon/realpath.c b/daemon/realpath.c
index 8ec9674..126ef19 100644
--- a/daemon/realpath.c
+++ b/daemon/realpath.c
@@ -36,20 +36,17 @@
#define NAME_MAX FILENAME_MAX
#endif
+#ifdef HAVE_REALPATH
+
int
optgroup_realpath_available (void)
{
-#ifdef HAVE_REALPATH
return 1;
-#else
- return 0;
-#endif
}
char *
do_realpath (const char *path)
{
-#ifdef HAVE_REALPATH
char *ret;
CHROOT_IN;
@@ -61,11 +58,24 @@ do_realpath (const char *path)
}
return ret; /* caller frees */
-#else
- NOT_AVAILABLE (NULL);
-#endif
}
+#else /* !HAVE_REALPATH */
+
+int
+optgroup_realpath_available (void)
+{
+ return 0;
+}
+
+char *
+do_realpath (const char *path)
+{
+ abort ();
+}
+
+#endif /* !HAVE_REALPATH */
+
static int find_path_element (int fd_cwd, char *name, size_t *name_len_ret);
char *
diff --git a/daemon/selinux.c b/daemon/selinux.c
index 2db05ee..40590e1 100644
--- a/daemon/selinux.c
+++ b/daemon/selinux.c
@@ -32,18 +32,12 @@
#include "optgroups.h"
#if defined(HAVE_LIBSELINUX)
+
int
optgroup_selinux_available (void)
{
return 1;
}
-#else /* !HAVE_LIBSELINUX */
-int
-optgroup_selinux_available (void)
-{
- return 0;
-}
-#endif /* !HAVE_LIBSELINUX */
/* setcon is only valid under the following circumstances:
* - single threaded
@@ -52,7 +46,7 @@ optgroup_selinux_available (void)
int
do_setcon (const char *context)
{
-#if defined(HAVE_LIBSELINUX) && defined(HAVE_SETCON)
+#if defined(HAVE_SETCON)
if (setcon ((char *) context) == -1) {
reply_with_perror ("setcon");
return -1;
@@ -60,14 +54,15 @@ do_setcon (const char *context)
return 0;
#else
- NOT_AVAILABLE (-1);
+ reply_with_error ("function not available");
+ return -1;
#endif
}
char *
do_getcon (void)
{
-#if defined(HAVE_LIBSELINUX) && defined(HAVE_GETCON)
+#if defined(HAVE_GETCON)
security_context_t context;
char *r;
@@ -85,6 +80,29 @@ do_getcon (void)
return r; /* caller frees */
#else
- NOT_AVAILABLE (NULL);
+ reply_with_error ("function not available");
+ return NULL;
#endif
}
+
+#else /* !HAVE_LIBSELINUX */
+
+int
+optgroup_selinux_available (void)
+{
+ return 0;
+}
+
+int
+do_setcon (const char *context)
+{
+ abort ();
+}
+
+char *
+do_getcon (void)
+{
+ abort ();
+}
+
+#endif /* !HAVE_LIBSELINUX */
diff --git a/daemon/xattr.c b/daemon/xattr.c
index 2445748..92d0cf1 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -511,6 +511,11 @@ do_lgetxattr (const char *path, const char *name, size_t *size_r)
}
#else /* no xattr.h */
+
+/* Note that the wrapper code (daemon/stubs.c) ensures that the
+ * functions below are never called because
+ * optgroup_linuxxattrs_available returns false.
+ */
int
optgroup_linuxxattrs_available (void)
{
@@ -520,55 +525,55 @@ optgroup_linuxxattrs_available (void)
guestfs_int_xattr_list *
do_getxattrs (const char *path)
{
- NOT_AVAILABLE (NULL);
+ abort ();
}
guestfs_int_xattr_list *
do_lgetxattrs (const char *path)
{
- NOT_AVAILABLE (NULL);
+ abort ();
}
int
do_setxattr (const char *xattr, const char *val, int vallen, const char *path)
{
- NOT_AVAILABLE (-1);
+ abort ();
}
int
do_lsetxattr (const char *xattr, const char *val, int vallen, const char *path)
{
- NOT_AVAILABLE (-1);
+ abort ();
}
int
do_removexattr (const char *xattr, const char *path)
{
- NOT_AVAILABLE (-1);
+ abort ();
}
int
do_lremovexattr (const char *xattr, const char *path)
{
- NOT_AVAILABLE (-1);
+ abort ();
}
guestfs_int_xattr_list *
do_lxattrlist (const char *path, char *const *names)
{
- NOT_AVAILABLE (NULL);
+ abort ();
}
char *
do_getxattr (const char *path, const char *name, size_t *size_r)
{
- NOT_AVAILABLE (NULL);
+ abort ();
}
char *
do_lgetxattr (const char *path, const char *name, size_t *size_r)
{
- NOT_AVAILABLE (NULL);
+ abort ();
}
#endif /* no xattr.h */
diff --git a/generator/generator_daemon.ml b/generator/generator_daemon.ml
index 88cc8bf..0eb2446 100644
--- a/generator/generator_daemon.ml
+++ b/generator/generator_daemon.ml
@@ -75,12 +75,14 @@ and generate_daemon_actions () =
pr "#include \"c-ctype.h\"\n";
pr "#include \"guestfs_protocol.h\"\n";
pr "#include \"actions.h\"\n";
+ pr "#include \"optgroups.h\"\n";
pr "\n";
List.iter (
- fun (name, (ret, args, optargs), _, _, _, _, _) ->
+ fun (name, (ret, args, optargs), _, flags, _, _, _) ->
(* Generate server-side stubs. *)
- pr "static void %s_stub (XDR *xdr_in)\n" name;
+ pr "static void\n";
+ pr "%s_stub (XDR *xdr_in)\n" name;
pr "{\n";
(match ret with
| RErr | RInt _ -> pr " int r;\n"
@@ -122,6 +124,24 @@ and generate_daemon_actions () =
let is_filein =
List.exists (function FileIn _ -> true | _ -> false) args in
+ (* Reject Optional functions that are not available (RHBZ#679737). *)
+ List.iter (
+ function
+ | Optional group ->
+ pr " /* The caller should have checked before calling this. */\n";
+ pr " if (! optgroup_%s_available ()) {\n" group;
+ if is_filein then
+ pr " cancel_receive ();\n";
+ pr " reply_with_error (\"feature '%%s' is not available in this\\n\"\n";
+ pr " \"build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\\n\"\n";
+ pr " \"how to check for the availability of features.\",\n";
+ pr " \"%s\");\n" group;
+ pr " goto done;\n";
+ pr " }\n";
+ pr "\n"
+ | _ -> ()
+ ) flags;
+
(* Reject unknown optional arguments.
* Note this code is included even for calls with no optional
* args because the caller must not pass optargs_bitmask != 0
--
1.7.6
12 years, 8 months
[PATCH] Clarify the error message when unavailable functions are called (RHBZ#679737).
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
Callers are supposed to use the availability API to check for
functions that may not be available in particular builds of
libguestfs. If they don't do this, currently they tend to get obscure
error messages, eg:
libguestfs: error: zerofree: /dev/vda1: zerofree: No such file or directory
This commit changes the error message to explain what callers ought to
be doing instead:
libguestfs: error: zerofree: feature 'zerofree' is not available in this
build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for
how to check for the availability of features.
---
daemon/augeas.c | 30 ++++++++++++------------
daemon/btrfs.c | 4 ++-
daemon/daemon.h | 29 +++++++++++++++++------
daemon/grub.c | 2 +
daemon/inotify.c | 12 +++++-----
daemon/luks.c | 16 ++++++++++++-
daemon/lvm.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++-
daemon/md.c | 10 +++++++-
daemon/mknod.c | 4 +-
daemon/modprobe.c | 8 +++++-
daemon/ntfs.c | 8 ++++++
daemon/realpath.c | 2 +-
daemon/scrub.c | 8 +++++-
daemon/selinux.c | 6 ++--
daemon/swap.c | 8 +++++-
daemon/tar.c | 2 +
daemon/xattr.c | 18 +++++++-------
daemon/zerofree.c | 4 ++-
18 files changed, 181 insertions(+), 54 deletions(-)
diff --git a/daemon/augeas.c b/daemon/augeas.c
index f52c091..135212e 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -99,7 +99,7 @@ do_aug_init (const char *root, int flags)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -114,7 +114,7 @@ do_aug_close (void)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -133,7 +133,7 @@ do_aug_defvar (const char *name, const char *expr)
}
return r;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -163,7 +163,7 @@ do_aug_defnode (const char *name, const char *expr, const char *val)
return r;
#else
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (augeas, NULL);
#endif
}
@@ -205,7 +205,7 @@ do_aug_get (const char *path)
return v; /* Caller frees. */
#else
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (augeas, NULL);
#endif
}
@@ -225,7 +225,7 @@ do_aug_set (const char *path, const char *val)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -245,7 +245,7 @@ do_aug_clear (const char *path)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -265,7 +265,7 @@ do_aug_insert (const char *path, const char *label, int before)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -285,7 +285,7 @@ do_aug_rm (const char *path)
return r;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -305,7 +305,7 @@ do_aug_mv (const char *src, const char *dest)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -339,7 +339,7 @@ do_aug_match (const char *path)
return matches; /* Caller frees. */
#else
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (augeas, NULL);
#endif
}
@@ -356,7 +356,7 @@ do_aug_save (void)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -373,7 +373,7 @@ do_aug_load (void)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (augeas, -1);
#endif
}
@@ -421,6 +421,6 @@ do_aug_ls (const char *path)
sort_strings (matches, count_strings ((void *) matches));
return matches; /* Caller frees. */
#else
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (augeas, NULL);
#endif
}
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index a20ee08..88a7386 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2011 Red Hat Inc.
+ * Copyright (C) 2011-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -47,6 +47,8 @@ do_btrfs_filesystem_resize (const char *filesystem, int64_t size)
size_t i = 0;
char size_str[32];
+ IF_NOT_AVAILABLE_ERROR (btrfs, -1);
+
ADD_ARG (argv, i, "btrfs");
ADD_ARG (argv, i, "filesystem");
ADD_ARG (argv, i, "resize");
diff --git a/daemon/daemon.h b/daemon/daemon.h
index babe5bc..051317f 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -331,15 +331,28 @@ is_zero (const char *buffer, size_t size)
} \
while (0)
-/* Marks functions which are not available.
- * NB. Cannot be used for FileIn functions.
+/* Better error messages for functions which may not be available
+ * (RHBZ#679737). Use NOT_AVAILABLE if the function is definitely not
+ * available at this point, or IF_NOT_AVAILABLE_ERROR to first check
+ * if the optgroup is available before printing the error.
+ *
+ * NB: (1) 'feature' parameter is a bareword, not in double quotes.
+ * (2) Cannot be used for FileIn functions.
*/
-#define NOT_AVAILABLE(errcode) \
- do { \
- reply_with_error ("%s: function not available", __func__); \
- return (errcode); \
- } \
- while (0)
+#define NOT_AVAILABLE(feature,errcode) \
+ do { \
+ reply_with_error ("feature '%s' is not available in this\n" \
+ "build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\n" \
+ "how to check for the availability of features.", \
+ #feature); \
+ return (errcode); \
+ } while (0)
+
+#define IF_NOT_AVAILABLE_ERROR(feature,errcode) \
+ do { \
+ if (! optgroup_##feature##_available ()) \
+ NOT_AVAILABLE(feature,errcode); \
+ } while (0)
#ifndef __attribute__
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
diff --git a/daemon/grub.c b/daemon/grub.c
index 9cd4f6e..bf3e07f 100644
--- a/daemon/grub.c
+++ b/daemon/grub.c
@@ -39,6 +39,8 @@ do_grub_install (const char *root, const char *device)
char *err;
char *buf;
+ IF_NOT_AVAILABLE_ERROR (grub, -1);
+
if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) {
reply_with_perror ("asprintf");
return -1;
diff --git a/daemon/inotify.c b/daemon/inotify.c
index add1f14..bafc336 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -130,7 +130,7 @@ do_inotify_init (int max_events)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (inotify, -1);
#endif
}
@@ -155,7 +155,7 @@ do_inotify_close (void)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (inotify, -1);
#endif
}
@@ -183,7 +183,7 @@ do_inotify_add_watch (const char *path, int mask)
return r;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (inotify, -1);
#endif
}
@@ -200,7 +200,7 @@ do_inotify_rm_watch (int wd)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (inotify, -1);
#endif
}
@@ -314,7 +314,7 @@ do_inotify_read (void)
free (ret);
return NULL;
#else
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (inotify, NULL);
#endif
}
@@ -405,6 +405,6 @@ do_inotify_files (void)
unlink (tempfile);
return NULL;
#else
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (inotify, NULL);
#endif
}
diff --git a/daemon/luks.c b/daemon/luks.c
index 02620ef..148a0ab 100644
--- a/daemon/luks.c
+++ b/daemon/luks.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2010 Red Hat Inc.
+ * Copyright (C) 2010-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -129,18 +129,24 @@ luks_open (const char *device, const char *key, const char *mapname,
int
do_luks_open (const char *device, const char *key, const char *mapname)
{
+ IF_NOT_AVAILABLE_ERROR (luks, -1);
+
return luks_open (device, key, mapname, 0);
}
int
do_luks_open_ro (const char *device, const char *key, const char *mapname)
{
+ IF_NOT_AVAILABLE_ERROR (luks, -1);
+
return luks_open (device, key, mapname, 1);
}
int
do_luks_close (const char *device)
{
+ IF_NOT_AVAILABLE_ERROR (luks, -1);
+
/* Must be /dev/mapper/... */
if (! STRPREFIX (device, "/dev/mapper/")) {
reply_with_error ("luks_close: you must call this on the /dev/mapper device created by luks_open");
@@ -210,6 +216,8 @@ luks_format (const char *device, const char *key, int keyslot,
int
do_luks_format (const char *device, const char *key, int keyslot)
{
+ IF_NOT_AVAILABLE_ERROR (luks, -1);
+
return luks_format (device, key, keyslot, NULL);
}
@@ -217,6 +225,8 @@ int
do_luks_format_cipher (const char *device, const char *key, int keyslot,
const char *cipher)
{
+ IF_NOT_AVAILABLE_ERROR (luks, -1);
+
return luks_format (device, key, keyslot, cipher);
}
@@ -224,6 +234,8 @@ int
do_luks_add_key (const char *device, const char *key, const char *newkey,
int keyslot)
{
+ IF_NOT_AVAILABLE_ERROR (luks, -1);
+
char *keyfile = write_key_to_temp (key);
if (!keyfile)
return -1;
@@ -269,6 +281,8 @@ do_luks_add_key (const char *device, const char *key, const char *newkey,
int
do_luks_kill_slot (const char *device, const char *key, int keyslot)
{
+ IF_NOT_AVAILABLE_ERROR (luks, -1);
+
char *tempfile = write_key_to_temp (key);
if (!tempfile)
return -1;
diff --git a/daemon/lvm.c b/daemon/lvm.c
index 9a71c65..d16cd15 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -102,6 +102,8 @@ do_pvs (void)
char *out, *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
r = command (&out, &err,
"lvm", "pvs", "-o", "pv_name", "--noheadings", NULL);
if (r == -1) {
@@ -122,6 +124,8 @@ do_vgs (void)
char *out, *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
r = command (&out, &err,
"lvm", "vgs", "-o", "vg_name", "--noheadings", NULL);
if (r == -1) {
@@ -142,6 +146,8 @@ do_lvs (void)
char *out, *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
r = command (&out, &err,
"lvm", "lvs",
"-o", "vg_name,lv_name", "--noheadings",
@@ -165,18 +171,24 @@ do_lvs (void)
guestfs_int_lvm_pv_list *
do_pvs_full (void)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
return parse_command_line_pvs ();
}
guestfs_int_lvm_vg_list *
do_vgs_full (void)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
return parse_command_line_vgs ();
}
guestfs_int_lvm_lv_list *
do_lvs_full (void)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
return parse_command_line_lvs ();
}
@@ -186,6 +198,8 @@ do_pvcreate (const char *device)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
r = command (NULL, &err,
"lvm", "pvcreate", device, NULL);
if (r == -1) {
@@ -208,6 +222,8 @@ do_vgcreate (const char *volgroup, char *const *physvols)
int r, argc, i;
const char **argv;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
argc = count_strings (physvols) + 3;
argv = malloc (sizeof (char *) * (argc + 1));
if (argv == NULL) {
@@ -243,6 +259,8 @@ do_lvcreate (const char *logvol, const char *volgroup, int mbytes)
int r;
char size[64];
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
@@ -268,6 +286,8 @@ do_lvresize (const char *logvol, int mbytes)
int r;
char size[64];
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
@@ -289,6 +309,8 @@ do_lvresize_free (const char *logvol, int percent)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
if (percent < 0 || percent > 100) {
reply_with_error ("percentage must be [0..100] (was %d)", percent);
return -1;
@@ -319,6 +341,8 @@ do_lvm_remove_all (void)
int i, r;
char *err;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
/* Remove LVs. */
xs = do_lvs ();
if (xs == NULL)
@@ -392,6 +416,8 @@ do_lvremove (const char *device)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
r = command (NULL, &err,
"lvm", "lvremove", "-f", device, NULL);
if (r == -1) {
@@ -413,6 +439,8 @@ do_vgremove (const char *device)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
r = command (NULL, &err,
"lvm", "vgremove", "-f", device, NULL);
if (r == -1) {
@@ -434,6 +462,8 @@ do_pvremove (const char *device)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
r = command (NULL, &err,
"lvm", "pvremove", "-ff", device, NULL);
if (r == -1) {
@@ -455,6 +485,8 @@ do_pvresize (const char *device)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
r = command (NULL, &err,
"lvm", "pvresize", device, NULL);
if (r == -1) {
@@ -472,8 +504,10 @@ do_pvresize_size (const char *device, int64_t size)
{
char *err;
int r;
-
char buf[32];
+
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
snprintf (buf, sizeof buf, "%" PRIi64 "b", size);
r = command (NULL, &err,
@@ -497,6 +531,8 @@ do_vg_activate (int activate, char *const *volgroups)
int r, i, argc;
const char **argv;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
argc = count_strings (volgroups) + 4;
argv = malloc (sizeof (char *) * (argc+1));
if (argv == NULL) {
@@ -540,6 +576,8 @@ do_lvrename (const char *logvol, const char *newlogvol)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
r = command (NULL, &err,
"lvm", "lvrename",
logvol, newlogvol, NULL);
@@ -562,6 +600,8 @@ do_vgrename (const char *volgroup, const char *newvolgroup)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
r = command (NULL, &err,
"lvm", "vgrename",
volgroup, newvolgroup, NULL);
@@ -603,18 +643,24 @@ get_lvm_field (const char *cmd, const char *field, const char *device)
char *
do_pvuuid (const char *device)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
return get_lvm_field ("pvs", "pv_uuid", device);
}
char *
do_vguuid (const char *vgname)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
return get_lvm_field ("vgs", "vg_uuid", vgname);
}
char *
do_lvuuid (const char *device)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
return get_lvm_field ("lvs", "lv_uuid", device);
}
@@ -652,12 +698,16 @@ get_lvm_fields (const char *cmd, const char *field, const char *device)
char **
do_vgpvuuids (const char *vgname)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
return get_lvm_fields ("vgs", "pv_uuid", vgname);
}
char **
do_vglvuuids (const char *vgname)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
return get_lvm_fields ("vgs", "lv_uuid", vgname);
}
@@ -667,6 +717,8 @@ do_vgscan (void)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
r = command (NULL, &err,
"lvm", "vgscan", NULL);
if (r == -1) {
@@ -745,6 +797,8 @@ lv_canonical (const char *device, char **ret)
int
do_is_lv (const char *device)
{
+ IF_NOT_AVAILABLE_ERROR (lvm2, -1);
+
return lv_canonical (device, NULL);
}
@@ -753,7 +807,11 @@ char *
do_lvm_canonical_lv_name (const char *device)
{
char *canonical;
- int r = lv_canonical (device, &canonical);
+ int r;
+
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
+ r = lv_canonical (device, &canonical);
if (r == -1)
return NULL;
@@ -775,6 +833,8 @@ do_list_dm_devices (void)
DIR *dir;
int r;
+ IF_NOT_AVAILABLE_ERROR (lvm2, NULL);
+
dir = opendir ("/dev/mapper");
if (!dir) {
reply_with_perror ("opendir: /dev/mapper");
diff --git a/daemon/md.c b/daemon/md.c
index 41e2c75..fb3a4a7 100644
--- a/daemon/md.c
+++ b/daemon/md.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2011 Red Hat Inc.
+ * Copyright (C) 2011-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -62,6 +62,8 @@ do_md_create (const char *name, char *const *devices,
char *err;
uint64_t umissingbitmap = (uint64_t) missingbitmap;
+ IF_NOT_AVAILABLE_ERROR (mdadm, -1);
+
/* Check the optional parameters and set defaults where appropriate. */
if (!(optargs_bitmask & GUESTFS_MD_CREATE_MISSINGBITMAP_BITMASK))
umissingbitmap = 0;
@@ -184,6 +186,8 @@ do_list_md_devices (void)
int size = 0, alloc = 0;
glob_t mds;
+ IF_NOT_AVAILABLE_ERROR (mdadm, NULL);
+
memset(&mds, 0, sizeof(mds));
#define PREFIX "/sys/block/md"
@@ -244,6 +248,8 @@ do_md_detail(const char *md)
char **ret = NULL;
int size = 0, alloc = 0;
+ IF_NOT_AVAILABLE_ERROR (mdadm, NULL);
+
const char *mdadm[] = { "mdadm", "-D", "--export", md, NULL };
r = commandv (&out, &err, mdadm);
if (r == -1) {
@@ -320,6 +326,8 @@ do_md_stop(const char *md)
int r;
char *err = NULL;
+ IF_NOT_AVAILABLE_ERROR (mdadm, -1);
+
const char *mdadm[] = { "mdadm", "--stop", md, NULL};
r = commandv(NULL, &err, mdadm);
if (r == -1) {
diff --git a/daemon/mknod.c b/daemon/mknod.c
index d5b8467..d13414b 100644
--- a/daemon/mknod.c
+++ b/daemon/mknod.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -67,7 +67,7 @@ do_mknod (int mode, int devmajor, int devminor, const char *path)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (mknod, -1);
#endif
}
diff --git a/daemon/modprobe.c b/daemon/modprobe.c
index 1063043..d7c5656 100644
--- a/daemon/modprobe.c
+++ b/daemon/modprobe.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,7 +35,11 @@ int
do_modprobe (const char *module)
{
char *err;
- int r = command (NULL, &err, "modprobe", module, NULL);
+ int r;
+
+ IF_NOT_AVAILABLE_ERROR (linuxmodules, -1);
+
+ r = command (NULL, &err, "modprobe", module, NULL);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/ntfs.c b/daemon/ntfs.c
index e8be344..b6dec83 100644
--- a/daemon/ntfs.c
+++ b/daemon/ntfs.c
@@ -49,6 +49,8 @@ do_ntfs_3g_probe (int rw, const char *device)
int r;
const char *rw_flag;
+ IF_NOT_AVAILABLE_ERROR (ntfs3g, -1);
+
rw_flag = rw ? "-w" : "-r";
r = commandr (NULL, &err, "ntfs-3g.probe", rw_flag, device, NULL);
@@ -72,6 +74,8 @@ do_ntfsresize_opts (const char *device, int64_t size, int force)
size_t i = 0;
char size_str[32];
+ IF_NOT_AVAILABLE_ERROR (ntfsprogs, -1);
+
ADD_ARG (argv, i, "ntfsresize");
ADD_ARG (argv, i, "-P");
@@ -106,12 +110,16 @@ do_ntfsresize_opts (const char *device, int64_t size, int force)
int
do_ntfsresize (const char *device)
{
+ IF_NOT_AVAILABLE_ERROR (ntfsprogs, -1);
+
return do_ntfsresize_opts (device, 0, 0);
}
int
do_ntfsresize_size (const char *device, int64_t size)
{
+ IF_NOT_AVAILABLE_ERROR (ntfsprogs, -1);
+
optargs_bitmask = GUESTFS_NTFSRESIZE_OPTS_SIZE_BITMASK;
return do_ntfsresize_opts (device, size, 0);
}
diff --git a/daemon/realpath.c b/daemon/realpath.c
index 8ec9674..a42aec3 100644
--- a/daemon/realpath.c
+++ b/daemon/realpath.c
@@ -62,7 +62,7 @@ do_realpath (const char *path)
return ret; /* caller frees */
#else
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (realpath, NULL);
#endif
}
diff --git a/daemon/scrub.c b/daemon/scrub.c
index 2cef69d..48ddd35 100644
--- a/daemon/scrub.c
+++ b/daemon/scrub.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,6 +40,8 @@ do_scrub_device (const char *device)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (scrub, -1);
+
r = command (NULL, &err, "scrub", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
@@ -59,6 +61,8 @@ do_scrub_file (const char *file)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (scrub, -1);
+
/* Make the path relative to /sysroot. */
buf = sysroot_path (file);
if (!buf) {
@@ -86,6 +90,8 @@ do_scrub_freespace (const char *dir)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (scrub, -1);
+
/* Make the path relative to /sysroot. */
buf = sysroot_path (dir);
if (!buf) {
diff --git a/daemon/selinux.c b/daemon/selinux.c
index 2db05ee..9c52781 100644
--- a/daemon/selinux.c
+++ b/daemon/selinux.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -60,7 +60,7 @@ do_setcon (const char *context)
return 0;
#else
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (selinux, -1);
#endif
}
@@ -85,6 +85,6 @@ do_getcon (void)
return r; /* caller frees */
#else
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (selinux, NULL);
#endif
}
diff --git a/daemon/swap.c b/daemon/swap.c
index 51dbbe4..4891470 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -99,6 +99,8 @@ do_mkswap_L (const char *label, const char *device)
int
do_mkswap_U (const char *uuid, const char *device)
{
+ IF_NOT_AVAILABLE_ERROR (linuxfsuuid, -1);
+
return mkswap (device, "-U", uuid);
}
@@ -219,11 +221,15 @@ do_swapoff_label (const char *label)
int
do_swapon_uuid (const char *uuid)
{
+ IF_NOT_AVAILABLE_ERROR (linuxfsuuid, -1);
+
return swaponoff ("swapon", "-U", uuid);
}
int
do_swapoff_uuid (const char *uuid)
{
+ IF_NOT_AVAILABLE_ERROR (linuxfsuuid, -1);
+
return swaponoff ("swapoff", "-U", uuid);
}
diff --git a/daemon/tar.c b/daemon/tar.c
index 9295f0d..79c9ac4 100644
--- a/daemon/tar.c
+++ b/daemon/tar.c
@@ -247,5 +247,7 @@ do_tgz_out (const char *dir)
int
do_txz_out (const char *dir)
{
+ IF_NOT_AVAILABLE_ERROR (xz, -1);
+
return do_tXz_out (dir, "J");
}
diff --git a/daemon/xattr.c b/daemon/xattr.c
index 2445748..1b98555 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -520,55 +520,55 @@ optgroup_linuxxattrs_available (void)
guestfs_int_xattr_list *
do_getxattrs (const char *path)
{
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (linuxxattrs, NULL);
}
guestfs_int_xattr_list *
do_lgetxattrs (const char *path)
{
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (linuxxattrs, NULL);
}
int
do_setxattr (const char *xattr, const char *val, int vallen, const char *path)
{
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (linuxxattrs, -1);
}
int
do_lsetxattr (const char *xattr, const char *val, int vallen, const char *path)
{
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (linuxxattrs, -1);
}
int
do_removexattr (const char *xattr, const char *path)
{
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (linuxxattrs, -1);
}
int
do_lremovexattr (const char *xattr, const char *path)
{
- NOT_AVAILABLE (-1);
+ NOT_AVAILABLE (linuxxattrs, -1);
}
guestfs_int_xattr_list *
do_lxattrlist (const char *path, char *const *names)
{
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (linuxxattrs, NULL);
}
char *
do_getxattr (const char *path, const char *name, size_t *size_r)
{
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (linuxxattrs, NULL);
}
char *
do_lgetxattr (const char *path, const char *name, size_t *size_r)
{
- NOT_AVAILABLE (NULL);
+ NOT_AVAILABLE (linuxxattrs, NULL);
}
#endif /* no xattr.h */
diff --git a/daemon/zerofree.c b/daemon/zerofree.c
index e9be8fc..bc1b7ff 100644
--- a/daemon/zerofree.c
+++ b/daemon/zerofree.c
@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,6 +40,8 @@ do_zerofree (const char *device)
char *err;
int r;
+ IF_NOT_AVAILABLE_ERROR (zerofree, -1);
+
r = command (NULL, &err, "zerofree", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
--
1.7.6
12 years, 8 months