diff options
author | Ian Campbell <ian.campbell@citrix.com> | 2010-12-03 09:36:47 +0000 |
---|---|---|
committer | Ian Campbell <ian.campbell@citrix.com> | 2010-12-03 09:36:47 +0000 |
commit | c89c726db972722d1e1ef3fd4913a05234c9cc47 (patch) | |
tree | 96e46313dfb8b746fbaafc28ac851ebc002c6538 /tools/libxc/xc_private.c | |
parent | 0ccceacd058c82f9cd747dff5efa92eebaded2fc (diff) | |
download | xen-c89c726db972722d1e1ef3fd4913a05234c9cc47.tar.gz xen-c89c726db972722d1e1ef3fd4913a05234c9cc47.tar.bz2 xen-c89c726db972722d1e1ef3fd4913a05234c9cc47.zip |
libxc: add abitility to dynamically load osdep.
Add a dummy backend which always returns ENOSYS. Mainly as a compile
time testbed rather than because it is a useful backend.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/libxc/xc_private.c')
-rw-r--r-- | tools/libxc/xc_private.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index 03587ba172..72ee07fd34 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -27,10 +27,22 @@ #include <pthread.h> #include <assert.h> +#ifndef __MINIOS__ +#include <dlfcn.h> +#endif + +#define XENCTRL_OSDEP "XENCTRL_OSDEP" + /* * Returns a (shallow) copy of the xc_osdep_info_t for the * active OS interface. * + * On success a handle to the relevant library is opened. The user + * must subsequently call xc_osdep_put_info() when it is + * finished with the library. + * + * Logs IFF xch != NULL. + * * Returns: * 0 - on success * -1 - on error @@ -38,16 +50,65 @@ static int xc_osdep_get_info(xc_interface *xch, xc_osdep_info_t *info) { int rc = -1; +#ifndef __MINIOS__ + const char *lib = getenv(XENCTRL_OSDEP); + xc_osdep_info_t *pinfo; + void *dl_handle = NULL; - *info = xc_osdep_info; + if ( lib != NULL ) + { + if ( getuid() != geteuid() ) + { + if ( xch ) ERROR("cannot use %s=%s with setuid application", XENCTRL_OSDEP, lib); + abort(); + } + if ( getgid() != getegid() ) + { + if ( xch ) ERROR("cannot use %s=%s with setgid application", XENCTRL_OSDEP, lib); + abort(); + } + + dl_handle = dlopen(lib, RTLD_LAZY|RTLD_LOCAL); + if ( !dl_handle ) + { + if ( xch ) ERROR("unable to open osdep library %s: %s", lib, dlerror()); + goto out; + } + + pinfo = dlsym(dl_handle, "xc_osdep_info"); + if ( !pinfo ) + { + if ( xch ) ERROR("unable to find xc_osinteface_info in %s: %s", lib, dlerror()); + goto out; + } + + *info = *pinfo; + info->dl_handle = dl_handle; + } + else +#endif + { + *info = xc_osdep_info; + info->dl_handle = NULL; + } rc = 0; +#ifndef __MINIOS__ +out: + if ( dl_handle && rc == -1 ) + dlclose(dl_handle); +#endif + return rc; } static void xc_osdep_put(xc_osdep_info_t *info) { +#ifndef __MINIOS__ + if ( info->dl_handle ) + dlclose(info->dl_handle); +#endif } static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger, |