diff options
author | Mika Westerberg <mika.westerberg@iki.fi> | 2009-03-16 14:00:45 +0200 |
---|---|---|
committer | Lauri Leukkunen <lle@rahina.org> | 2009-03-23 01:37:48 +0200 |
commit | 18a064f7bb06bad27a3d67ddf6e2c485bf69f87b (patch) | |
tree | 50cb4b05a987e2b9dc294b75cc70c9e0d65f9b73 | |
parent | b88704b1331c6a7857cc4607d870ef0e58b5170d (diff) |
l10n: message catalogs are now mapped based on active exec policy
- Removed usage of native_app_message_catalog_prefix variable in
exec policy. There is no need for that anymore as we can find
out correct mappings using conditional rules.
- LOCPATH and NLSPATH are cleared always before exec so they don't
get inherited to child unless really needed.
- __SB2_REAL_BINARYNAME is not anymore needed but I left it there
in case there is some future needs for that.
Signed-off-by: Lauri Aarnio <Lauri.Aarnio@iki.fi>
-rw-r--r-- | include/mapping.h | 2 | ||||
-rw-r--r-- | lua_scripts/pathmaps/devel/00_default.lua | 25 | ||||
-rw-r--r-- | lua_scripts/pathmaps/emulate/00_default.lua | 1 | ||||
-rw-r--r-- | luaif/argvenvp.c | 53 | ||||
-rw-r--r-- | preload/interface.master | 9 | ||||
-rw-r--r-- | preload/sb_exec.c | 9 | ||||
-rw-r--r-- | preload/sb_l10n.c | 85 | ||||
-rwxr-xr-x | utils/sb2 | 21 |
8 files changed, 40 insertions, 165 deletions
diff --git a/include/mapping.h b/include/mapping.h index 46fd41c..94ab228 100644 --- a/include/mapping.h +++ b/include/mapping.h @@ -66,8 +66,6 @@ extern char *sb_execve_map_script_interpreter(const char *interpreter, extern int sb_execve_postprocess(char *exec_type, char **mapped_file, char **filename, const char *binary_name, char ***argv, char ***envp); -extern char *sb_query_exec_policy(const char *field_name, - const char *binary_name, const char *real_binary_name); extern char *scratchbox_reverse_path( const char *func_name, const char *full_path); diff --git a/lua_scripts/pathmaps/devel/00_default.lua b/lua_scripts/pathmaps/devel/00_default.lua index a3201e4..c8a1fef 100644 --- a/lua_scripts/pathmaps/devel/00_default.lua +++ b/lua_scripts/pathmaps/devel/00_default.lua @@ -28,7 +28,6 @@ devel_mode_tools_ld_so = nil -- default = not needed devel_mode_tools_ld_library_path = nil -- default = not needed -- localization support for tools devel_mode_locale_path = nil -devel_mode_message_catalog_prefix = nil if ((tools_root ~= nil) and conf_tools_sb2_installed) then if (conf_tools_ld_so ~= nil) then @@ -39,8 +38,6 @@ if ((tools_root ~= nil) and conf_tools_sb2_installed) then if (conf_tools_locale_path ~= nil) then -- use locales from tools devel_mode_locale_path = conf_tools_locale_path - devel_mode_message_catalog_prefix = - conf_tools_message_catalog_prefix end end @@ -59,7 +56,6 @@ exec_policy_tools = { native_app_ld_so_supports_argv0 = conf_tools_ld_so_supports_argv0, native_app_ld_library_path = devel_mode_tools_ld_library_path, native_app_locale_path = devel_mode_locale_path, - native_app_message_catalog_prefix = devel_model_message_catalog_prefix, script_log_level = "debug", script_log_message = "SCRIPT from tools", @@ -73,7 +69,6 @@ exec_policy_tools_perl = { native_app_ld_so_supports_argv0 = conf_tools_ld_so_supports_argv0, native_app_ld_library_path = devel_mode_tools_ld_library_path, native_app_locale_path = devel_mode_locale_path, - native_app_message_catalog_prefix = devel_model_message_catalog_prefix, script_log_level = "debug", script_log_message = "SCRIPT from tools (t.p)", @@ -87,7 +82,6 @@ exec_policy_tools_python = { native_app_ld_so_supports_argv0 = conf_tools_ld_so_supports_argv0, native_app_ld_library_path = devel_mode_tools_ld_library_path, native_app_locale_path = devel_mode_locale_path, - native_app_message_catalog_prefix = devel_model_message_catalog_prefix, script_log_level = "debug", script_log_message = "SCRIPT from tools (t.p)", @@ -124,7 +118,8 @@ exec_policy_target = { name = "Rootstrap", native_app_ld_so = devel_mode_target_ld_so, native_app_ld_so_supports_argv0 = conf_target_ld_so_supports_argv0, - native_app_ld_library_path = devel_mode_target_ld_library_path + native_app_ld_library_path = devel_mode_target_ld_library_path, + native_app_locale_path = conf_target_locale_path, } -- @@ -211,6 +206,20 @@ terminfo_test = { { map_to = target_root, readonly = true } } +-- +-- Message catalogs (LC_MESSAGES) are taken based on +-- active exec policy. +-- +message_catalog_test = { + { if_active_exec_policy_is = "Tools", + map_to = tools, readonly = true }, + { if_active_exec_policy_is = "Rootstrap", + map_to = target_root, readonly = true }, + { if_active_exec_policy_is = "Host", + use_orig_path = true, readonly = true }, + { map_to = target_root, readonly = true } +} + -- =========== Mapping rule chains =========== -- Used when dir = "/usr/share/aclocal": @@ -299,6 +308,8 @@ devel_mode_rules_usr_share = { readonly = true}, {prefix = "/usr/share/terminfo", actions = terminfo_test}, + {prefix = "/usr/share/locale", + actions = message_catalog_test}, -- /usr/share/hildon* (this is a real prefix): -- (was added to map hildon-theme-layout-4) diff --git a/lua_scripts/pathmaps/emulate/00_default.lua b/lua_scripts/pathmaps/emulate/00_default.lua index 82fbe08..f22a1c4 100644 --- a/lua_scripts/pathmaps/emulate/00_default.lua +++ b/lua_scripts/pathmaps/emulate/00_default.lua @@ -223,7 +223,6 @@ local exec_policy_target = { native_app_ld_library_path_suffix = emulate_mode_target_ld_library_path_suffix, native_app_locale_path = conf_target_locale_path, - native_app_message_catalog_prefix = conf_target_message_catalog_prefix, } -- Note that the real path (mapped path) is used when looking up rules! diff --git a/luaif/argvenvp.c b/luaif/argvenvp.c index 6120c15..9c8a360 100644 --- a/luaif/argvenvp.c +++ b/luaif/argvenvp.c @@ -431,56 +431,3 @@ char *sb_execve_map_script_interpreter( release_lua(luaif); return mapped_interpreter; } - -/* - * Tries to find exec_policy for given real_binary_name and return - * field 'field_name' as string. Returned value should be released - * by calling free(3) after it is not needed anymore. - * - * Returns NULL if field or exec_policy was not found. - */ -char *sb_query_exec_policy(const char *field_name, const char *binary_name, - const char *real_binary_name) -{ - struct lua_instance *luaif; - char *result = NULL; - int ret = 0; - - if ((luaif = get_lua()) == NULL) - return (NULL); - - SB_LOG(SB_LOGLEVEL_DEBUG, "sb_query_exec_policy: binary_name=%s, " - "real_binary_name=%s", binary_name, real_binary_name); - - lua_getfield(luaif->lua, LUA_GLOBALSINDEX, "sb_find_exec_policy"); - - lua_pushstring(luaif->lua, binary_name); - lua_pushstring(luaif->lua, real_binary_name); - - /* - * sb_finc_exec_policy(binary_name, real_binary_name) - * returns: err, exec_policy (table) - */ - lua_call(luaif->lua, 2, 2); - - ret = lua_tonumber(luaif->lua, -2); - SB_LOG(SB_LOGLEVEL_DEBUG, "sb_query_exec_policy: ret=%d", ret); - - if (ret) { - const char *field_value; - - /* get string value from index 'field_name' */ - lua_pushstring(luaif->lua, field_name); - lua_gettable(luaif->lua, -2); - if ((field_value = lua_tostring(luaif->lua, -1)) != NULL) { - result = strdup(field_value); - } - lua_pop(luaif->lua, 1); - } - - /* normalize lua stack */ - lua_pop(luaif->lua, 2); - - release_lua(luaif); - return (result); -} diff --git a/preload/interface.master b/preload/interface.master index 75bf8f0..75bead4 100644 --- a/preload/interface.master +++ b/preload/interface.master @@ -548,14 +548,9 @@ GATE: int setrlimit64(SETRLIMIT_ARG1_TYPE resource, const struct rlimit64 *rlp) -- -- We solve this by wrapping all gettext functions that take domainname -- and call explicitly bindtextdomain(3). This way message catalog --- directories will get mapped to correct place. These paths are +-- directories will get mapped to correct place. Are then mapped normally +-- using mapping engine and conditional rules based on active exec policy. -- specified in exec_policy as follows: --- { --- ... --- native_app_message_catalog_prefix = <prefix> --- } --- When this variable is set, we map '/path/to/locales' to --- '<prefix>/path/to/locales'. -- -- TODO: should we wrap also plain gettext() and ngettext()? -- diff --git a/preload/sb_exec.c b/preload/sb_exec.c index d96e804..6d739f2 100644 --- a/preload/sb_exec.c +++ b/preload/sb_exec.c @@ -721,6 +721,15 @@ static char **prepare_envp_for_do_exec(const char *orig_file, sbox_session_varname_prefix_len) == 0) { /* this is user-provided SBOX_SESSION_*, skip it. */ continue; + } else if ((strncmp(*p, "NLSPATH=", 8) == 0) || + (strncmp(*p, "LOCPATH=", 8) == 0)) { + /* + * We need to drop any previously set locale + * paths (set in argvenvp.lua) so that they + * won't get inherited accidentally to child + * process who don't need them. + */ + continue; } my_envp[i++] = strdup(*p); } diff --git a/preload/sb_l10n.c b/preload/sb_l10n.c index c3635c1..0158eea 100644 --- a/preload/sb_l10n.c +++ b/preload/sb_l10n.c @@ -24,96 +24,29 @@ #include "libsb2.h" #include "exported.h" -static char *message_catalog_prefix = NULL; -static int message_catalog_prefix_retrieved = 0; - -static const char *get_message_catalog_prefix(void); static void check_textdomain(const char *); -/* - * Returns message catalog prefix for this binary. This value - * can be used to map text domain paths under target_root or - * tools_root. Returns NULL if there is no such specified. - */ -static const char *get_message_catalog_prefix(void) -{ - if (message_catalog_prefix_retrieved) - return (message_catalog_prefix); - - if (!sb2_global_vars_initialized__) - sb2_initialize_global_variables(); - - /* - * There might be situations when sb2 starts where - * $__SB2_REAL_BINARYNAME is not set. This happens - * on very first exec so we cannot apply any exec - * policy. - */ - if (sbox_real_binary_name == NULL) - return (message_catalog_prefix); - - /* - * Now, try to fetch configured message catalog prefix - * from exec policy. This is normally set to target_root - * or tools_root. Note that we leak memory here as we - * never free the returned string (it could be NULL, though). - */ - message_catalog_prefix = - sb_query_exec_policy("native_app_message_catalog_prefix", - sbox_binary_name, sbox_real_binary_name); - - if (message_catalog_prefix != NULL) { - SB_LOG(SB_LOGLEVEL_DEBUG, - "native_app_message_catalog_prefix='%s'", - message_catalog_prefix); - } - - message_catalog_prefix_retrieved = 1; - return (message_catalog_prefix); -} - -/*ARGSUSED*/ char *bindtextdomain_gate(char *(*realfn)(const char *, const char *), const char *realfn_name, const char *domainname, const char *dirname) { + mapping_results_t res; const char *mapped_dirname = dirname; - const char *message_catalog_prefix = NULL; - char *message_catalog_path = NULL; char *result = NULL; - (void)realfn_name; + clear_mapping_results_struct(&res); - if (dirname == NULL) - goto out; - if ((message_catalog_prefix = get_message_catalog_prefix()) == NULL) - goto out; + if (dirname != NULL) { + sbox_map_path(realfn_name, dirname, 0, &res); + assert(res.mres_result_path != NULL); - /* is it already mapped? */ - if (strstr(dirname, message_catalog_prefix) != NULL) - goto out; /* don't remap */ + mapped_dirname = res.mres_result_path; - /* - * Got message catalog prefix for this binary. Next we - * bind given text domain under that prefix: - * <prefix>/usr/share - * or whatever is was before. - */ - if (dirname[0] == '/') { - (void) asprintf(&message_catalog_path, "%s%s", - message_catalog_prefix, dirname); - } else { - /* TODO: should we even allow relative paths? */ - (void) asprintf(&message_catalog_path, "%s/%s", - message_catalog_prefix, dirname); + SB_LOG(SB_LOGLEVEL_DEBUG, "binding domain %s to %s", + domainname, mapped_dirname); } - - SB_LOG(SB_LOGLEVEL_DEBUG, "binding domain %s to %s", - domainname, message_catalog_path); - mapped_dirname = message_catalog_path; -out: result = (*realfn)(domainname, mapped_dirname); - free(message_catalog_path); + free_mapping_results(&res); return (result); } @@ -674,7 +674,6 @@ function write_locale_paths_to_exec_config() rootdir=$1 generated_locale_path=$2 locale_path_varname=$3 - message_catalog_prefix_varname=$4 # # Check whether $rootdir has localization files @@ -696,18 +695,6 @@ function write_locale_paths_to_exec_config() echo "$locale_path_varname = nil" \ >> $SBOX_SESSION_DIR/exec_config.lua fi - - # - # Message catalogs are ok to run as is straight from - # $rootdir if they exist. - # - if [ -d "$rootdir/usr/share/locale" ]; then - echo "$message_catalog_prefix_varname = \"$rootdir\"" \ - >> $SBOX_SESSION_DIR/exec_config.lua - else - echo "$message_catalog_prefix_varname = nil" \ - >> $SBOX_SESSION_DIR/exec_config.lua - fi } # Write configuration file $SBOX_SESSION_DIR/exec_config.lua @@ -737,8 +724,7 @@ END write_locale_paths_to_exec_config \ $SBOX_TOOLS_ROOT \ $HOME/.scratchbox2/$tools_basename/locales \ - conf_tools_locale_path \ - conf_tools_message_catalog_prefix + conf_tools_locale_path if [ ld_so_found != "yes" ]; then # ld.so from tools can not be used. Add tools' shared @@ -762,7 +748,6 @@ conf_tools_ld_so = nil conf_tools_ld_so_supports_argv0 = false conf_tools_libsb2_dir = nil conf_tools_locale_path = nil -conf_tools_message_catalog_prefix = nil END fi @@ -797,8 +782,7 @@ END write_locale_paths_to_exec_config \ $SBOX_TARGET_ROOT \ $HOME/.scratchbox2/$SBOX_TARGET/locales \ - conf_target_locale_path \ - conf_target_message_catalog_prefix + conf_target_locale_path else # SBOX_CPUTRANSPARENCY_METHOD is set empty, # host CPU != target CPU @@ -810,7 +794,6 @@ conf_target_ld_so = nil conf_target_ld_so_supports_argv0 = false conf_target_libsb2_dir = nil conf_target_locale_path = nil -conf_target_message_catalog_prefix = nil END case "$SBOX_CPUTRANSPARENCY_METHOD" in |