Exemplo n.º 1
0
/**
 * Test if the qemu-img info command supports the C<-U> option to
 * disable locking.  The result is memoized in the handle.
 *
 * Note this option was added in qemu 2.11.  We can remove this test
 * when we can assume everyone is using qemu >= 2.11.
 */
static int
qemu_img_supports_U_option (guestfs_h *g)
{
  if (g->qemu_img_supports_U_option >= 0)
    return g->qemu_img_supports_U_option;

  CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
  int r;

  guestfs_int_cmd_add_string_unquoted (cmd,
                                       "qemu-img --help | "
                                       "grep -sqE -- '\\binfo\\b.*-U\\b'");
  r = guestfs_int_cmd_run (cmd);
  if (r == -1)
    return -1;
  if (!WIFEXITED (r)) {
    guestfs_int_external_command_failed (g, r,
                                         "qemu-img info -U option test",
                                         NULL);
    return -1;
  }

  g->qemu_img_supports_U_option = WEXITSTATUS (r) == 0;
  return g->qemu_img_supports_U_option;
}
Exemplo n.º 2
0
/**
 * Test C<guestfs_int_new_command> etc.
 *
 * XXX These tests could be made much more thorough.  So far we simply
 * test that it's not obviously broken.
 */
static void
test_command (void)
{
  guestfs_h *g;
  struct command *cmd;
  int r;

  g = guestfs_create ();
  assert (g);

  /* argv-style */
  cmd = guestfs_int_new_command (g);
  assert (cmd);
  guestfs_int_cmd_add_arg (cmd, "touch");
  guestfs_int_cmd_add_arg (cmd, "test-utils-test-command");
  r = guestfs_int_cmd_run (cmd);
  assert (r == 0);
  guestfs_int_cmd_close (cmd);

  /* system-style */
  cmd = guestfs_int_new_command (g);
  assert (cmd);
  guestfs_int_cmd_add_string_unquoted (cmd, "rm ");
  guestfs_int_cmd_add_string_quoted (cmd, "test-utils-test-command");
  r = guestfs_int_cmd_run (cmd);
  assert (r == 0);
  guestfs_int_cmd_close (cmd);

  guestfs_close (g);
}