From 43db06ea892cc157324a6b837ca430607441c509 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Wed, 22 Apr 2009 09:00:39 +0100 Subject: Allow qemu binary to be overridden at runtime. --- java/com/redhat/et/libguestfs/GuestFS.java | 50 ++++++++++++++++++++++++++++++ java/com_redhat_et_libguestfs_GuestFS.c | 32 +++++++++++++++++++ 2 files changed, 82 insertions(+) (limited to 'java') diff --git a/java/com/redhat/et/libguestfs/GuestFS.java b/java/com/redhat/et/libguestfs/GuestFS.java index 8c2265e7..119a2df1 100644 --- a/java/com/redhat/et/libguestfs/GuestFS.java +++ b/java/com/redhat/et/libguestfs/GuestFS.java @@ -218,6 +218,56 @@ public class GuestFS { private native void _config (long g, String qemuparam, String qemuvalue) throws LibGuestFSException; + /** + * set the qemu binary + * + * Set the qemu binary that we will use. + * + * The default is chosen when the library was compiled by + * the configure script. + * + * You can also override this by setting the + * "LIBGUESTFS_QEMU" environment variable. + * + * The string "qemu" is stashed in the libguestfs handle, + * so the caller must make sure it remains valid for the + * lifetime of the handle. + * + * Setting "qemu" to "NULL" restores the default qemu + * binary. + * + * @throws LibGuestFSException + */ + public void set_qemu (String qemu) + throws LibGuestFSException + { + if (g == 0) + throw new LibGuestFSException ("set_qemu: handle is closed"); + _set_qemu (g, qemu); + } + private native void _set_qemu (long g, String qemu) + throws LibGuestFSException; + + /** + * get the qemu binary + * + * Return the current qemu binary. + * + * This is always non-NULL. If it wasn't set already, then + * this will return the default qemu binary name. + * + * @throws LibGuestFSException + */ + public String get_qemu () + throws LibGuestFSException + { + if (g == 0) + throw new LibGuestFSException ("get_qemu: handle is closed"); + return _get_qemu (g); + } + private native String _get_qemu (long g) + throws LibGuestFSException; + /** * set the search path * diff --git a/java/com_redhat_et_libguestfs_GuestFS.c b/java/com_redhat_et_libguestfs_GuestFS.c index 51412780..550568b8 100644 --- a/java/com_redhat_et_libguestfs_GuestFS.c +++ b/java/com_redhat_et_libguestfs_GuestFS.c @@ -157,6 +157,38 @@ Java_com_redhat_et_libguestfs_GuestFS__1config } } +JNIEXPORT void JNICALL +Java_com_redhat_et_libguestfs_GuestFS__1set_1qemu + (JNIEnv *env, jobject obj, jlong jg, jstring jqemu) +{ + guestfs_h *g = (guestfs_h *) jg; + int r; + const char *qemu; + + qemu = (*env)->GetStringUTFChars (env, jqemu, NULL); + r = guestfs_set_qemu (g, qemu); + (*env)->ReleaseStringUTFChars (env, jqemu, qemu); + if (r == -1) { + throw_exception (env, guestfs_last_error (g)); + return ; + } +} + +JNIEXPORT jstring JNICALL +Java_com_redhat_et_libguestfs_GuestFS__1get_1qemu + (JNIEnv *env, jobject obj, jlong jg) +{ + guestfs_h *g = (guestfs_h *) jg; + const char *r; + + r = guestfs_get_qemu (g); + if (r == NULL) { + throw_exception (env, guestfs_last_error (g)); + return NULL; + } + return (*env)->NewStringUTF (env, r); +} + JNIEXPORT void JNICALL Java_com_redhat_et_libguestfs_GuestFS__1set_1path (JNIEnv *env, jobject obj, jlong jg, jstring jpath) -- cgit