Assignments to "all_disks" and "all_removable" are now centralized in main() -- with a side nod to find_all_disks() --, and read accesses of "all_disks" and "all_removable" are also centralized to main(). Replace these global variables with variables that are local to main().
No observable changes. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2124538 Signed-off-by: Laszlo Ersek <ler...@redhat.com> --- p2v.h | 11 ++-------- disks.c | 13 +++++------ main.c | 23 +++++++++++--------- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/p2v.h b/p2v.h index d48b4fcc6611..3a972a474ebf 100644 --- a/p2v.h +++ b/p2v.h @@ -66,15 +66,8 @@ struct cpu_topo { extern void get_cpu_topology (struct cpu_topo *topo); extern void get_cpu_config (struct cpu_config *); -/* disks.c - * - * All disks / removable media discovered (possibly with one call to - * find_all_disks()) when the program started. Do not change these, or call - * find_all_disks() more than once. - */ -extern char **all_disks; -extern char **all_removable; -extern void find_all_disks (void); +/* disks.c */ +extern void find_all_disks (char ***disks, char ***removable); /* rtc.c */ extern void get_rtc_config (struct rtc_config *); diff --git a/disks.c b/disks.c index e9c92b8c69e8..4eb006246d84 100644 --- a/disks.c +++ b/disks.c @@ -36,9 +36,6 @@ #include "p2v.h" -char **all_disks; -char **all_removable; - /** * Get parent device of a partition. * @@ -107,11 +104,11 @@ device_contains (const char *dev, dev_t root_device) } /** - * Enumerate all disks in F</sys/block> and add them to the global - * C<all_disks> and C<all_removable> arrays. + * Enumerate all disks in F</sys/block> and return them in the C<disks> and + * C<removable> arrays. */ void -find_all_disks (void) +find_all_disks (char ***disks, char ***removable) { DIR *dir; struct dirent *d; @@ -184,6 +181,6 @@ find_all_disks (void) if (ret_removable) qsort (ret_removable, nr_removable, sizeof (char *), compare_strings); - all_disks = ret_disks; - all_removable = ret_removable; + *disks = ret_disks; + *removable = ret_removable; } diff --git a/main.c b/main.c index 86820dd27e08..b0e86c591093 100644 --- a/main.c +++ b/main.c @@ -131,6 +131,7 @@ main (int argc, char *argv[]) int cmdline_source = 0; struct config *config = new_config (); const char *test_disk = NULL; + char **disks, **removable; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEBASEDIR); @@ -219,18 +220,19 @@ main (int argc, char *argv[]) /* For testing and debugging purposes, you can use * --test-disk=/path/to/disk.img */ - all_disks = malloc (2 * sizeof (char *)); - if (all_disks == NULL) + disks = malloc (2 * sizeof (char *)); + if (disks == NULL) error (EXIT_FAILURE, errno, "malloc"); - all_disks[0] = strdup (test_disk); - if (all_disks[0] == NULL) + disks[0] = strdup (test_disk); + if (disks[0] == NULL) error (EXIT_FAILURE, errno, "strdup"); - all_disks[1] = NULL; + disks[1] = NULL; + + removable = NULL; } else - find_all_disks (); + find_all_disks (&disks, &removable); - set_config_defaults (config, (const char **)all_disks, - (const char **)all_removable); + set_config_defaults (config, (const char **)disks, (const char **)removable); /* Parse /proc/cmdline (if it exists) or use the --cmdline parameter * to initialize the configuration. This allows defaults to be pass @@ -256,11 +258,12 @@ main (int argc, char *argv[]) error (EXIT_FAILURE, 0, _("gtk_init_check returned false, indicating that\n" "a GUI is not possible on this host. Check X11, $DISPLAY etc.")); - gui_conversion (config, (const char **)all_disks, - (const char **)all_removable); + gui_conversion (config, (const char **)disks, (const char **)removable); } guestfs_int_free_string_list (cmdline); + guestfs_int_free_string_list (removable); + guestfs_int_free_string_list (disks); free_config (config); exit (EXIT_SUCCESS); _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs