From 0379cf9284c30fdc5984fdcc15f5f3025c02f545 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=A1=B0=EC=9B=85=EC=84=9D/MDE=20Lab=28SR=29/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Tue, 25 Jul 2023 08:46:24 +0900 Subject: [PATCH] Remove storage API dependency (#477) Use tzplatform_config API to get special folder instead of storage API. storage API makes thread and gdbus connection internally and it can make some error at the loader mode. In this patch, we get special folders (music, image, video) from tzplatform data. Additionally, to allow override speicial folder location with coreclr_env.list, change the initEnvForSpecialFolder() call location. --- NativeLauncher/CMakeLists.txt | 2 +- NativeLauncher/launcher/lib/core_runtime.cc | 65 ++++++++--------------------- packaging/dotnet-launcher.spec | 1 - 3 files changed, 18 insertions(+), 50 deletions(-) diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 0360af7..8492464 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -4,7 +4,7 @@ PROJECT("dotnet-tools") MESSAGE("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer ecore bundle dlog liblaunchpad glib-2.0 libsmack capi-appfw-app-common storage jsoncpp openssl1.1 sqlite3 libtzplatform-config) +PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer ecore bundle dlog liblaunchpad glib-2.0 libsmack capi-appfw-app-common jsoncpp openssl1.1 sqlite3 libtzplatform-config) FOREACH(flag ${${PROJECT_NAME}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index 1c7cfb7..61ea55a 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -35,9 +35,9 @@ #include #include -#include #include #include +#include #include @@ -143,55 +143,28 @@ static void registerSigHandler() } } -static bool storage_cb(int id, storage_type_e type, storage_state_e state, const char *path, void *user_data) -{ - int* tmp = (int*)user_data; - if (type == STORAGE_TYPE_INTERNAL) - { - *tmp = id; - return false; - } - - return true; -} - -static void setSpecialFolder(storage_directory_e type, const char* key) -{ - int error; - char* path = NULL; - static int __storageId = -1; - - if (__storageId < 0) { - error = storage_foreach_device_supported(storage_cb, &__storageId); - if (error != STORAGE_ERROR_NONE) { - return; - } - } - - error = storage_get_directory(__storageId, type, &path); - if (error == STORAGE_ERROR_NONE && path != NULL) { - if (setEnvironmentVariable) { - setEnvironmentVariable(key, const_cast(path)); - } else { - _ERR("coreclr is not initialized!. setEnvironmentVariable() function is not ready!"); - _exit(0); - } - free(path); - } -} - static void initEnvForSpecialFolder() { + const char* path = NULL; if (getenv("XDG_PICTURES_DIR") == NULL) { - setSpecialFolder(STORAGE_DIRECTORY_IMAGES, "XDG_PICTURES_DIR"); + path = tzplatform_getenv(TZ_USER_IMAGES); + if (path) { + setenv("XDG_PICTURES_DIR", path, 1); + } } if (getenv("XDG_MUSIC_DIR") == NULL) { - setSpecialFolder(STORAGE_DIRECTORY_MUSIC, "XDG_MUSIC_DIR"); + path = tzplatform_getenv(TZ_USER_MUSIC); + if (path) { + setenv("XDG_MUSIC_DIR", path, 1); + } } if (getenv("XDG_VIDEOS_DIR") == NULL) { - setSpecialFolder(STORAGE_DIRECTORY_VIDEOS, "XDG_VIDEOS_DIR"); + path = tzplatform_getenv(TZ_USER_VIDEOS); + if (path) { + setenv("XDG_VIDEOS_DIR", path, 1); + } } } @@ -384,6 +357,9 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) // Disable config cache to set environment after coreclr_initialize() putenv(const_cast("COMPlus_DisableConfigCache=1")); + // Set environment variable for System.Environment.SpecialFolder + initEnvForSpecialFolder(); + // read string from external file and set them to environment value. setEnvFromFile(); @@ -482,13 +458,6 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) } - // 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; diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 83533a5..1c36b1e 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -20,7 +20,6 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(capi-appfw-app-common) -BuildRequires: pkgconfig(storage) BuildRequires: pkgconfig(jsoncpp) BuildRequires: pkgconfig(openssl1.1) BuildRequires: pkgconfig(libsystemd) -- 2.7.4