Exemple #1
0
int
run_supported (const char *cmd, size_t argc, char *argv[])
{
  /* As a side-effect this also checks that we've called 'launch'. */
  CLEANUP_FREE_STRING_LIST char **groups = guestfs_available_all_groups (g);
  if (groups == NULL)
    return -1;

  /* Temporarily replace the error handler so that messages don't get
   * printed to stderr while we are issuing commands.
   */
  guestfs_push_error_handler (g, NULL, NULL);

  /* Work out the max string length of any group name. */
  size_t i;
  size_t len = 0;
  for (i = 0; groups[i] != NULL; ++i) {
    size_t l = strlen (groups[i]);
    if (l > len)
      len = l;
  }

  for (i = 0; groups[i] != NULL; ++i) {
    char *gg[] = { groups[i], NULL };
    int r = guestfs_available (g, gg);
    const char *str = r == 0 ? _("yes") : _("no");

    printf ("%*s %s\n", (int) len, groups[i], str);
  }

  /* Restore error handler. */
  guestfs_pop_error_handler (g);

  return 0;
}
Exemple #2
0
int
run_supported (const char *cmd, size_t argc, char *argv[])
{
  char **groups;

  /* As a side-effect this also checks that we've called 'launch'. */
  groups = guestfs_available_all_groups (g);
  if (groups == NULL)
    return -1;

  /* Temporarily replace the error handler so that messages don't get
   * printed to stderr while we are issuing commands.
   */
  guestfs_error_handler_cb old_error_cb;
  void *old_error_cb_data;
  old_error_cb = guestfs_get_error_handler (g, &old_error_cb_data);
  guestfs_set_error_handler (g, NULL, NULL);

  /* Work out the max string length of any group name. */
  size_t i;
  size_t len = 0;
  for (i = 0; groups[i] != NULL; ++i) {
    size_t l = strlen (groups[i]);
    if (l > len)
      len = l;
  }

  for (i = 0; groups[i] != NULL; ++i) {
    size_t l = strlen (groups[i]);
    size_t j;
    for (j = 0; j < len-l; ++j)
      putchar (' ');
    printf ("%s", groups[i]);
    putchar (' ');

    char *gg[] = { groups[i], NULL };
    int r = guestfs_available (g, gg);
    if (r == 0)
      printf ("%s", _("yes"));
    else
      printf ("%s", _("no"));
    putchar ('\n');
  }

  /* Free groups list. */
  for (i = 0; groups[i] != NULL; ++i)
    free (groups[i]);
  free (groups);

  /* Restore error handler. */
  guestfs_set_error_handler (g, old_error_cb, old_error_cb_data);

  return 0;
}