@@ -2005,7 +2005,7 @@ char *qemu_find_file(int type, const char *name)
2005
2005
return NULL ;
2006
2006
}
2007
2007
2008
- void qemu_add_data_dir (const char * path )
2008
+ void qemu_add_data_dir (char * path )
2009
2009
{
2010
2010
int i ;
2011
2011
@@ -2017,10 +2017,11 @@ void qemu_add_data_dir(const char *path)
2017
2017
}
2018
2018
for (i = 0 ; i < data_dir_idx ; i ++ ) {
2019
2019
if (strcmp (data_dir [i ], path ) == 0 ) {
2020
- return ; /* duplicate */
2020
+ g_free (path ); /* duplicate */
2021
+ return ;
2021
2022
}
2022
2023
}
2023
- data_dir [data_dir_idx ++ ] = g_strdup ( path ) ;
2024
+ data_dir [data_dir_idx ++ ] = path ;
2024
2025
}
2025
2026
2026
2027
static inline bool nonempty_str (const char * str )
@@ -2829,6 +2830,26 @@ static void create_default_memdev(MachineState *ms, const char *path)
2829
2830
& error_fatal );
2830
2831
}
2831
2832
2833
+ /*
2834
+ * Find a likely location for support files using the location of the binary.
2835
+ * When running from the build tree this will be "$bindir/pc-bios".
2836
+ * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated).
2837
+ *
2838
+ * The caller must use g_free() to free the returned data when it is
2839
+ * no longer required.
2840
+ */
2841
+ static char * find_datadir (void )
2842
+ {
2843
+ g_autofree char * dir = NULL ;
2844
+
2845
+ dir = g_build_filename (qemu_get_exec_dir (), "pc-bios" , NULL );
2846
+ if (g_file_test (dir , G_FILE_TEST_IS_DIR )) {
2847
+ return g_steal_pointer (& dir );
2848
+ }
2849
+
2850
+ return get_relocated_path (CONFIG_QEMU_DATADIR );
2851
+ }
2852
+
2832
2853
void qemu_init (int argc , char * * argv , char * * envp )
2833
2854
{
2834
2855
int i ;
@@ -2862,7 +2883,7 @@ void qemu_init(int argc, char **argv, char **envp)
2862
2883
Error * main_loop_err = NULL ;
2863
2884
Error * err = NULL ;
2864
2885
bool list_data_dirs = false;
2865
- char * dir , * * dirs ;
2886
+ char * * dirs ;
2866
2887
const char * mem_path = NULL ;
2867
2888
bool have_custom_ram_size ;
2868
2889
BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER (bdo_queue );
@@ -3195,7 +3216,7 @@ void qemu_init(int argc, char **argv, char **envp)
3195
3216
if (is_help_option (optarg )) {
3196
3217
list_data_dirs = true;
3197
3218
} else {
3198
- qemu_add_data_dir (optarg );
3219
+ qemu_add_data_dir (g_strdup ( optarg ) );
3199
3220
}
3200
3221
break ;
3201
3222
case QEMU_OPTION_bios :
@@ -3927,17 +3948,12 @@ void qemu_init(int argc, char **argv, char **envp)
3927
3948
/* add configured firmware directories */
3928
3949
dirs = g_strsplit (CONFIG_QEMU_FIRMWAREPATH , G_SEARCHPATH_SEPARATOR_S , 0 );
3929
3950
for (i = 0 ; dirs [i ] != NULL ; i ++ ) {
3930
- qemu_add_data_dir (dirs [i ]);
3951
+ qemu_add_data_dir (get_relocated_path ( dirs [i ]) );
3931
3952
}
3932
3953
g_strfreev (dirs );
3933
3954
3934
3955
/* try to find datadir relative to the executable path */
3935
- dir = os_find_datadir ();
3936
- qemu_add_data_dir (dir );
3937
- g_free (dir );
3938
-
3939
- /* add the datadir specified when building */
3940
- qemu_add_data_dir (CONFIG_QEMU_DATADIR );
3956
+ qemu_add_data_dir (find_datadir ());
3941
3957
3942
3958
/* -L help lists the data directories and exits. */
3943
3959
if (list_data_dirs ) {
0 commit comments