Use setEnvrionmentVariable() to set SpecialFolder (#475) accepted/tizen/unified/20230725.013007
author조웅석/MDE Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Mon, 24 Jul 2023 04:34:59 +0000 (13:34 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 24 Jul 2023 04:34:59 +0000 (13:34 +0900)
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.

NativeLauncher/launcher/lib/core_runtime.cc

index 6f4ab5a..07ec8e9 100644 (file)
@@ -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<char *>(path), 1);
+               if (setEnvironmentVariable) {
+                       setEnvironmentVariable(key, const_cast<char *>(path));
+               } else {
+                       _ERR("coreclr is not initialized!. setEnvironmentVariable() function is not ready!");
+                       _exit(0);
+               }
                free(path);
        }
 }
@@ -428,12 +433,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') {
@@ -477,6 +476,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");