static void try_df (const char *name, const char *uuid, const char *dev, int offset) { struct guestfs_statvfs *stat = NULL; guestfs_error_handler_cb old_error_cb; void *old_error_data; if (verbose) fprintf (stderr, "try_df %s %s %d\n", name, dev, offset); /* Try mounting and stating the device. This might reasonably fail, * so don't show errors. */ old_error_cb = guestfs_get_error_handler (g, &old_error_data); guestfs_set_error_handler (g, NULL, NULL); if (guestfs_mount_ro (g, dev, "/") == 0) { stat = guestfs_statvfs (g, "/"); guestfs_umount_all (g); } guestfs_set_error_handler (g, old_error_cb, old_error_data); if (stat) { print_stat (name, uuid, dev, offset, stat); guestfs_free_statvfs (stat); } }
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; }
int run_reopen (const char *cmd, size_t argc, char *argv[]) { guestfs_h *g2; int r; const char *p; guestfs_error_handler_cb cb; void *cb_data; if (argc > 0) { fprintf (stderr, _("'reopen' command takes no parameters\n")); return -1; } if (guestfs_shutdown (g) == -1) return -1; /* Open the new handle first, so we can copy the settings from the * old one to the new one, and also so if it fails we still have an * open handle. */ g2 = guestfs_create (); if (g2 == NULL) { fprintf (stderr, _("reopen: guestfs_create: failed to create handle\n")); return -1; } /* Now copy some of the settings from the old handle. The settings * we copy are those which are set by guestfish itself. */ cb = guestfs_get_error_handler (g, &cb_data); guestfs_set_error_handler (g2, cb, cb_data); r = guestfs_get_verbose (g); if (r >= 0) guestfs_set_verbose (g2, r); r = guestfs_get_trace (g); if (r >= 0) guestfs_set_trace (g2, r); r = guestfs_get_autosync (g); if (r >= 0) guestfs_set_autosync (g2, r); p = guestfs_get_path (g); if (p) guestfs_set_path (g2, p); r = guestfs_get_pgroup (g); if (r >= 0) guestfs_set_pgroup (g2, r); if (progress_bars) guestfs_set_event_callback (g2, progress_callback, GUESTFS_EVENT_PROGRESS, 0, NULL); /* Close the original handle. */ guestfs_close (g); g = g2; /* We don't bother copying event handlers over to the new handle, * but we have to reset the list because they were registered * against the old handle. */ free_event_handlers (); init_event_handlers (); return 0; }