From: 조웅석/MDE Lab(SR)/삼성전자 Date: Mon, 24 Jul 2023 04:34:59 +0000 (+0900) Subject: Use setEnvrionmentVariable() to set SpecialFolder (#475) X-Git-Tag: accepted/tizen/7.0/unified/20230725.172607~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72edbfdf8234bca94f0635e534780332305ed654;p=platform%2Fcore%2Fdotnet%2Flauncher.git Use setEnvrionmentVariable() to set SpecialFolder (#475) Storage API which is used to get SpecialFolder(Music, Picture, Video) makes threads internally, and it makes crash when we call setenv() function in the launcher because setenv() is not thread-safe function. So, use setEnvironmentVariable() function which set envrionment variable in the .NET runtime. --- diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index 88b999c..1c7cfb7 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -170,7 +170,12 @@ static void setSpecialFolder(storage_directory_e type, const char* key) error = storage_get_directory(__storageId, type, &path); if (error == STORAGE_ERROR_NONE && path != NULL) { - setenv(key, const_cast(path), 1); + if (setEnvironmentVariable) { + setEnvironmentVariable(key, const_cast(path)); + } else { + _ERR("coreclr is not initialized!. setEnvironmentVariable() function is not ready!"); + _exit(0); + } free(path); } } @@ -433,12 +438,6 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) _INFO("libcoreclr dlopen and dlsym success"); - // Set environment for System.Environment.SpecialFolder - // Below function creates dbus connection by callging storage API. - // If dbus connection is created bofere fork(), forked process cannot use dbus. - // To avoid gdbus blocking issue, below function should be called after fork() - initEnvForSpecialFolder(); - std::string tpa; char* pluginTPA = pluginGetTPA(); if (pluginTPA && pluginTPA[0] != '\0') { @@ -482,6 +481,15 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) removeDebugPipe(); } + + // Set environment for System.Environment.SpecialFolder + // Below function creates dbus connection by callging storage API. + // If dbus connection is created bofere fork(), forked process cannot use dbus. + // To avoid gdbus blocking issue, below function should be called after fork() + // Addtionally, setenv() is not thread-safe function. storage API makes thread internally + // and it makes crash while calling setenv(). So, use setEnvrionmentVariable() instead of setenv() + initEnvForSpecialFolder(); + __initialized = true; _INFO("CoreRuntime initialize success");