Set environment variables before executing the application 00/234800/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 29 May 2020 02:07:02 +0000 (11:07 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 29 May 2020 02:07:32 +0000 (11:07 +0900)
To avoid thread-safe issue of setenv() / getenv(), the child process
adds the environment variables to increase buffer size of __environ.

Change-Id: Ia656b8c4cbc2fb5014a1fe399e78dfc9475dbf6d
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/common/src/launchpad_common.c

index 26fce8b..8d2f943 100644 (file)
@@ -40,6 +40,7 @@
 #include <sys/personality.h>
 #include <sys/prctl.h>
 #include <dbus/dbus.h>
+#include <vconf.h>
 
 #include "launchpad_common.h"
 #include "launchpad_types.h"
@@ -726,6 +727,44 @@ static void __set_execution_domain(void)
 }
 #endif /* TIZEN_FEATURE_SET_PERSONALITY_32 */
 
+static void __set_lang_env(void)
+{
+       char *lang;
+
+       lang = vconf_get_str(VCONFKEY_LANGSET);
+       if (!lang)
+               lang = strdup("en_US.UTF-8");
+
+       setenv("LANGUAGE", lang, 1);
+       setenv("LANG", lang, 1);
+       setenv("LC_MESSAGES", lang, 1);
+
+       free(lang);
+}
+
+static void __set_region_env(void)
+{
+       char *region;
+
+       region = vconf_get_str(VCONFKEY_REGIONFORMAT);
+       if (!region)
+               region = strdup("en_US.UTF-8");
+
+       setenv("LC_CTYPE", region, 1);
+       setenv("LC_NUMERIC", region, 1);
+       setenv("LC_TIME", region, 1);
+       setenv("LC_COLLATE", region, 1);
+       setenv("LC_MONETARY", region, 1);
+       setenv("LC_PAPER", region, 1);
+       setenv("LC_NAME", region, 1);
+       setenv("LC_ADDRESS", region, 1);
+       setenv("LC_TELEPHONE", region, 1);
+       setenv("LC_MEASUREMENT", region, 1);
+       setenv("LC_IDENTIFICATION", region, 1);
+
+       free(region);
+}
+
 void _set_env(appinfo_t *menu_info, bundle *kb)
 {
        const char *str;
@@ -763,6 +802,9 @@ void _set_env(appinfo_t *menu_info, bundle *kb)
        snprintf(buf, sizeof(buf), "%d", getpid());
        setenv("AUL_PID", buf, 1);
 
+       __set_lang_env();
+       __set_region_env();
+       setenv("LC_ALL", "C", 1);
 #ifdef TIZEN_FEATURE_SET_PERSONALITY_32
        __set_execution_domain();
 #endif /* TIZEN_FEATURE_SET_PERSONALITY_32 */