test "x$POD2TEXT" = "xno" &&
AC_MSG_ERROR([pod2text must be installed])
-dnl Check for QEMU. We only check for the basic 'qemu' program here
-dnl (ie. the i386 full system qemu). But at runtime we might choose
-dnl a different qemu to run, eg. qemu-system-ppc.
-AC_PATH_PROG([QEMU],[qemu],[no],
+dnl Check for QEMU for running binaries on this $host_cpu, fall
+dnl back to basic 'qemu'.
+AC_PATH_PROGS([QEMU],[qemu-system-$host_cpu qemu],[no],
[$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin])
test "x$QEMU" = "xno" && AC_MSG_ERROR([qemu must be installed])
AC_DEFINE_UNQUOTED([QEMU],["$QEMU"],[Location of qemu binary.])
[with_repo=fedora-10])
REPO="$with_repo"
AC_SUBST(REPO)
+AC_DEFINE_UNQUOTED([REPO],["$REPO"],[Name of Fedora repository.])
+
+AC_DEFINE_UNQUOTED([host_cpu],["$host_cpu"],[Host architecture.])
dnl --with-mirror to specify a local Fedora mirror.
AC_ARG_WITH([mirror],
This returns the current out of memory handler.
+=head1 PATH
+
+Libguestfs needs a kernel and initrd.img, which it finds by looking
+along an internal path.
+
+By default it looks for these in the directory C<$libdir/guestfs>
+(eg. C</usr/local/lib/guestfs> or C</usr/lib64/guestfs>).
+
+Use C<guestfs_set_path> or set the environment variable
+C<LIBGUESTFS_PATH> to change the directories that libguestfs will
+search in. The value is a colon-separated list of paths. The current
+directory is I<not> searched unless the path contains an empty element
+or C<.>. For example C<LIBGUESTFS_PATH=:/usr/lib/guestfs> would
+search the current directory and then C</usr/lib/guestfs>.
+
+=head2 guestfs_set_path
+
+ void guestfs_set_path (guestfs_h *handle, const char *path);
+
+Set the path that libguestfs searches for kernel and initrd.img.
+
+The default is C<$libdir/guestfs> unless overridden by setting
+C<LIBGUESTFS_PATH> environment variable.
+
+The string C<path> is stashed in the libguestfs handle, so the caller
+must make sure it remains valid for the lifetime of the handle.
+
+Setting C<path> to C<NULL> restores the default path.
+
+=head2 guestfs_get_path
+
+ const char *guestfs_get_path (guestfs_h *handle);
+
+Return the current search path.
+
+This is always non-NULL. If it wasn't set already, then this will
+return the default path.
+
=head1 AUTOSYNC
=head2 guestfs_set_autosync
This isn't documented. Please see the libguestfs-select and
libguestfs-glib implementations.
-=head1 SEE ALSO
+=head1 ENVIRONMENT VARIABLES
+
+=over 4
+
+=item LIBGUESTFS_DEBUG
-L<qemu(1)>
+Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages. This
+has the same effect as calling C<guestfs_set_verbose (handle, 1)>.
+=item LIBGUESTFS_PATH
+Set the path that libguestfs uses to search for kernel and initrd.img.
+See the discussion of paths in C<guestfs_set_path> above.
+=back
+
+=head1 SEE ALSO
+L<guestfish(1)>,
+L<qemu(1)>,
+L<febootstrap(1)>,
+L<http://et.redhat.com/~rjones/libguestfs>.
=head1 AUTHORS
#include <config.h>
#define _BSD_SOURCE /* for mkdtemp, usleep */
-#define _GNU_SOURCE /* for vasprintf, GNU strerror_r */
+#define _GNU_SOURCE /* for vasprintf, GNU strerror_r, strchrnul */
#include <stdio.h>
#include <stdlib.h>
int verbose;
int autosync;
+ const char *path;
+
/* Callbacks. */
guestfs_abort_cb abort_cb;
guestfs_error_handler_cb error_cb;
str = getenv ("LIBGUESTFS_DEBUG");
g->verbose = str != NULL && strcmp (str, "1") == 0;
+ str = getenv ("LIBGUESTFS_PATH");
+ g->path = str != NULL ? str : GUESTFS_DEFAULT_PATH;
+ /* XXX We should probably make QEMU configurable as well. */
+
/* Start with large serial numbers so they are easy to spot
* inside the protocol.
*/
return g->autosync;
}
+void
+guestfs_set_path (guestfs_h *g, const char *path)
+{
+ if (path == NULL)
+ g->path = GUESTFS_DEFAULT_PATH;
+ else
+ g->path = path;
+}
+
+const char *
+guestfs_get_path (guestfs_h *g)
+{
+ return g->path;
+}
+
/* Add a string to the current command line. */
static void
incr_cmdline_size (guestfs_h *g)
guestfs_launch (guestfs_h *g)
{
static const char *dir_template = "/tmp/libguestfsXXXXXX";
- int r, i;
+ int r, i, len;
int wfd[2], rfd[2];
int tries;
- /*const char *qemu = QEMU;*/ /* XXX */
- const char *qemu = "/usr/bin/qemu-system-x86_64";
- const char *kernel = "vmlinuz.fedora-10.x86_64";
- const char *initrd = "initramfs.fedora-10.x86_64.img";
+ const char *kernel_name = "vmlinuz." REPO "." host_cpu;
+ const char *initrd_name = "initramfs." REPO "." host_cpu ".img";
+ char *path, *pelem, *pend;
+ char *kernel = NULL, *initrd = NULL;
char unixsock[256];
struct sockaddr_un addr;
- /* XXX Choose which qemu to run. */
- /* XXX Choose initrd, etc. */
-
/* Configured? */
if (!g->cmdline) {
error (g, "you must call guestfs_add_drive before guestfs_launch");
return -1;
}
+ /* Search g->path for the kernel and initrd. */
+ pelem = path = safe_strdup (g, g->path);
+ do {
+ pend = strchrnul (pelem, ':');
+ *pend = '\0';
+ len = pend - pelem;
+
+ /* Empty element or "." means cwd. */
+ if (len == 0 || (len == 1 && *pelem == '.')) {
+ if (g->verbose)
+ fprintf (stderr,
+ "looking for kernel and initrd in current directory\n");
+ if (access (kernel_name, F_OK) == 0 && access (initrd_name, F_OK) == 0) {
+ kernel = safe_strdup (g, kernel_name);
+ initrd = safe_strdup (g, initrd_name);
+ break;
+ }
+ }
+ /* Look at <path>/kernel etc. */
+ else {
+ kernel = safe_malloc (g, len + strlen (kernel_name) + 2);
+ initrd = safe_malloc (g, len + strlen (initrd_name) + 2);
+ sprintf (kernel, "%s/%s", pelem, kernel_name);
+ sprintf (initrd, "%s/%s", pelem, initrd_name);
+
+ if (g->verbose)
+ fprintf (stderr, "looking for %s and %s\n", kernel, initrd);
+
+ if (access (kernel, F_OK) == 0 && access (initrd, F_OK) == 0)
+ break;
+ free (kernel);
+ free (initrd);
+ kernel = initrd = NULL;
+ }
+
+ pelem = pend;
+ } while (*pelem++ != '\0');
+
+ free (path);
+
+ if (kernel == NULL || initrd == NULL) {
+ error (g, "cannot find %s or %s on LIBGUESTFS_PATH (current path = %s)",
+ kernel_name, initrd_name, g->path);
+ goto cleanup0;
+ }
+
/* Make the temporary directory containing the socket. */
if (!g->tmpdir) {
g->tmpdir = safe_strdup (g, dir_template);
if (mkdtemp (g->tmpdir) == NULL) {
perrorf (g, "%s: cannot create temporary directory", dir_template);
- return -1;
+ goto cleanup0;
}
}
if (pipe (wfd) == -1 || pipe (rfd) == -1) {
perrorf (g, "pipe");
- return -1;
+ goto cleanup0;
}
r = fork ();
close (wfd[1]);
close (rfd[0]);
close (rfd[1]);
- return -1;
+ goto cleanup0;
}
if (r == 0) { /* Child (qemu). */
/* Set up the full command line. Do this in the subprocess so we
* don't need to worry about cleaning up.
*/
- g->cmdline[0] = (char *) qemu;
+ g->cmdline[0] = (char *) QEMU;
/* Construct the -net channel parameter for qemu. */
snprintf (vmchannel, sizeof vmchannel,
g->cmdline[g->cmdline_size-1] = NULL;
if (g->verbose) {
- fprintf (stderr, "%s", qemu);
+ fprintf (stderr, "%s", QEMU);
for (i = 0; g->cmdline[i]; ++i)
fprintf (stderr, " %s", g->cmdline[i]);
fprintf (stderr, "\n");
setpgid (0, 0);
#endif
- execv (qemu, g->cmdline); /* Run qemu. */
- perror (qemu);
+ execv (QEMU, g->cmdline); /* Run qemu. */
+ perror (QEMU);
_exit (1);
}
g->start_t = 0;
g->stdout_watch = -1;
g->sock_watch = -1;
+
+ cleanup0:
+ free (kernel);
+ free (initrd);
return -1;
}
}
if (g->verbose)
- fprintf (stderr, "sending SIGTERM to process group %d\n", g->pid);
+ fprintf (stderr, "sending SIGTERM to process %d\n", g->pid);
kill (g->pid, SIGTERM);