diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-02-01 12:18:35 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-02-01 15:09:09 +0000 |
commit | 330fbea5b2d6bd7db84f7ea7afe87cf1bcd438e0 (patch) | |
tree | 5a1c1de5498303ace3de64f771ccba949f202df0 /daemon/selinux.c | |
parent | 90d6386c13edcb479113889bbd3cedf83c2e6277 (diff) | |
download | libguestfs-330fbea5b2d6bd7db84f7ea7afe87cf1bcd438e0.tar.gz libguestfs-330fbea5b2d6bd7db84f7ea7afe87cf1bcd438e0.tar.xz libguestfs-330fbea5b2d6bd7db84f7ea7afe87cf1bcd438e0.zip |
Clarify the error message when unavailable functions are called (RHBZ#679737).
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;
}
[...]
Diffstat (limited to 'daemon/selinux.c')
-rw-r--r-- | daemon/selinux.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/daemon/selinux.c b/daemon/selinux.c index 2db05ee8..40590e15 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 */ |