Skip to content

Commit 9d7b9a9

Browse files
author
Laszlo Ersek
committed
"all_disks", "all_removable": eliminate
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 <[email protected]> Message-Id: <[email protected]> Acked-by: Richard W.M. Jones <[email protected]>
1 parent c65124e commit 9d7b9a9

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

disks.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636

3737
#include "p2v.h"
3838

39-
char **all_disks;
40-
char **all_removable;
41-
4239
/**
4340
* Get parent device of a partition.
4441
*
@@ -107,11 +104,11 @@ device_contains (const char *dev, dev_t root_device)
107104
}
108105

109106
/**
110-
* Enumerate all disks in F</sys/block> and add them to the global
111-
* C<all_disks> and C<all_removable> arrays.
107+
* Enumerate all disks in F</sys/block> and return them in the C<disks> and
108+
* C<removable> arrays.
112109
*/
113110
void
114-
find_all_disks (void)
111+
find_all_disks (char ***disks, char ***removable)
115112
{
116113
DIR *dir;
117114
struct dirent *d;
@@ -184,6 +181,6 @@ find_all_disks (void)
184181
if (ret_removable)
185182
qsort (ret_removable, nr_removable, sizeof (char *), compare_strings);
186183

187-
all_disks = ret_disks;
188-
all_removable = ret_removable;
184+
*disks = ret_disks;
185+
*removable = ret_removable;
189186
}

main.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ main (int argc, char *argv[])
131131
int cmdline_source = 0;
132132
struct config *config = new_config ();
133133
const char *test_disk = NULL;
134+
char **disks, **removable;
134135

135136
setlocale (LC_ALL, "");
136137
bindtextdomain (PACKAGE, LOCALEBASEDIR);
@@ -219,18 +220,19 @@ main (int argc, char *argv[])
219220
/* For testing and debugging purposes, you can use
220221
* --test-disk=/path/to/disk.img
221222
*/
222-
all_disks = malloc (2 * sizeof (char *));
223-
if (all_disks == NULL)
223+
disks = malloc (2 * sizeof (char *));
224+
if (disks == NULL)
224225
error (EXIT_FAILURE, errno, "malloc");
225-
all_disks[0] = strdup (test_disk);
226-
if (all_disks[0] == NULL)
226+
disks[0] = strdup (test_disk);
227+
if (disks[0] == NULL)
227228
error (EXIT_FAILURE, errno, "strdup");
228-
all_disks[1] = NULL;
229+
disks[1] = NULL;
230+
231+
removable = NULL;
229232
} else
230-
find_all_disks ();
233+
find_all_disks (&disks, &removable);
231234

232-
set_config_defaults (config, (const char **)all_disks,
233-
(const char **)all_removable);
235+
set_config_defaults (config, (const char **)disks, (const char **)removable);
234236

235237
/* Parse /proc/cmdline (if it exists) or use the --cmdline parameter
236238
* to initialize the configuration. This allows defaults to be pass
@@ -256,11 +258,12 @@ main (int argc, char *argv[])
256258
error (EXIT_FAILURE, 0,
257259
_("gtk_init_check returned false, indicating that\n"
258260
"a GUI is not possible on this host. Check X11, $DISPLAY etc."));
259-
gui_conversion (config, (const char **)all_disks,
260-
(const char **)all_removable);
261+
gui_conversion (config, (const char **)disks, (const char **)removable);
261262
}
262263

263264
guestfs_int_free_string_list (cmdline);
265+
guestfs_int_free_string_list (removable);
266+
guestfs_int_free_string_list (disks);
264267
free_config (config);
265268

266269
exit (EXIT_SUCCESS);

p2v.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,8 @@ struct cpu_topo {
6666
extern void get_cpu_topology (struct cpu_topo *topo);
6767
extern void get_cpu_config (struct cpu_config *);
6868

69-
/* disks.c
70-
*
71-
* All disks / removable media discovered (possibly with one call to
72-
* find_all_disks()) when the program started. Do not change these, or call
73-
* find_all_disks() more than once.
74-
*/
75-
extern char **all_disks;
76-
extern char **all_removable;
77-
extern void find_all_disks (void);
69+
/* disks.c */
70+
extern void find_all_disks (char ***disks, char ***removable);
7871

7972
/* rtc.c */
8073
extern void get_rtc_config (struct rtc_config *);

0 commit comments

Comments
 (0)