Merge lp:~pieq/checkbox/fix-1484872-env-variables-forced-to-non-international into lp:checkbox

Proposed by Pierre Equoy
Status: Rejected
Rejected by: Zygmunt Krynicki
Proposed branch: lp:~pieq/checkbox/fix-1484872-env-variables-forced-to-non-international
Merge into: lp:checkbox
Diff against target: 59 lines (+34/-2)
2 files modified
plainbox/plainbox/impl/ctrl.py (+2/-2)
plainbox/plainbox/impl/test_ctrl.py (+32/-0)
To merge this branch: bzr merge lp:~pieq/checkbox/fix-1484872-env-variables-forced-to-non-international
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Needs Fixing
Review via email: mp+269873@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

12:11 <@zyga> ePierre: https://code.launchpad.net/~pierre-equoy/checkbox/fix-1484872-env-variables-forced-to-non-international/+merge/269873
12:11 <@zyga> ePierre: can you explain how this works please
12:11 <@zyga> ePierre: deleting an environment variable really really means that that variable is gone in the process we fork off
12:11 < ePierre> zyga, sure
12:11 <@zyga> ePierre: I assume there's something that re-establishes them
12:11 <@zyga> ePierre: but I wonder what that is and so now I'm all ears
12:12 < ePierre> ok so we were checking this with spineau
12:12 < ePierre> zyga, we realized that currently, LANGUAGE is deleted from the env dict that is returned
12:13 < ePierre> zyga, but because of that, when pkexec is called, it is not called with a special value for LANGUAGE
12:13 <@zyga> mmm
12:13 <@zyga> ah, so this is for pkexec
12:13 <@zyga> I think you need to change your patch
12:13 < ePierre> zyga, so pkexec uses the available value in the system env, which is, for a system using Chinese, something like zh_CN:zh
12:13 <@zyga> sudo and pkexec use a "differential" environment
12:13 <@zyga> it's a hack that lets us set the environment in the process that they start
12:14 <@zyga> because they will otherwise change the environment significantly (sudo) or entirely (pkexec)
12:15 <@zyga> ePierre: I think this patch is not right, one sec
12:15 <@zyga> ePierre: can you please go and patch the differential environment
12:16 <@zyga> ePierre: I think it's the more correct approach, the generimc method is correct for non-helper execution controllers
12:16 <@zyga> ePierre: and for both pkexec, sudo and p-t-l you need to do things explicitly (and check all three)
12:16 <@zyga> ePierre: as a test case run a job that runs locale
12:16 <@zyga> as in locale(1)
12:16 <@zyga> and run it with each execution controller
12:17 <@zyga> ePierre: the patch should special case locale variables in differential environment
12:17 <@zyga> ePierre: and make sure to see how each of sudo/pkexec/p-t-l execution controllers work please
12:17 < ePierre> zyga what is p-t-l?
12:18 <@zyga> ePierre: plainbox-trusted-launcher
12:18 < ePierre> ha, the famous trusted launcher, ok
12:18 <@zyga> thanks
12:18 <@zyga> ePierre: ping me if you have any questions, thanks for working on this!
12:18 < ePierre> zyga, ok, thanks

review: Needs Fixing
Revision history for this message
Pierre Equoy (pieq) wrote :

<ePierre> zyga,when you say to patch the differential environment, is it something done by plainbox?
<zyga> ePierre: yes
<zyga> ePierre: it's all in the same module (ctrl.yp)
<zyga> ePierre: just read it and see what happens
<ePierre> zyga, ok
<zyga> ePierre: there's a method there with that word in the name
<ePierre> zyga, yes I found it. I will check this
<zyga> ePierre: start with sudo/pkexec
<zyga> ePierre: it's the easiest to run
<zyga> ePierre: p-t-l is a bit hard to actually start to use as it's meant for systemwide installed packages
<ePierre> zyga, regarding my patch, I replaced existing lines that were removing the keys in the env dict
<ePierre> zyga, was this correct?
<ePierre> (I mean to remove keys from the env dict)
<zyga> ePierre: no, because I think a different solution is needed for each controller
<zyga> ePierre: you only got lucky here :)
<zyga> ePierre: but if the environment was different to start with it would not work
<zyga> ePierre: you need to explicitly reset those keys in the differential environment
<ePierre> zyga, but should I do this in all the three controllers? RootViaPkexecExecutionController, RootViaPTL1ExecutionController and RootViaSudoExecutionController ?
<zyga> ePierre: no, you should add it to their common base class
<zyga> ePierre: iterate, it will be clear
<zyga> ePierre: if you add it to all three the code will be the same
<ePierre> CheckBoxDifferentialExecutionController
<zyga> ePierre: and then you can spot the shared base class
<zyga> ePierre: exactly
<ePierre> zyga, and by “explicitly reset those keys”, you mean I should add the special cases (LANGUAGES, LC_*...) here?
<zyga> ePierre: yeah, that code there tries to compute the delta so that it can be explicitly passed to each of the three controllers
<zyga> ePierre: just make sure the delta always, unconditionally has those language keys

Unmerged revisions

3979. By Pierre Equoy

Force environment into non-internationalized values

Previously, get_execution_environment() method in ctrl.py would set LANG
variable to 'C.UTF-8' but would not do anything to LANGUAGE or LC_* variables.

We change this to make sure these variables are all set to empty strings in
order to force the system to use default (non-internationalized) values.

This allow us to use English regexp in scripts, even on non-English systems.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plainbox/plainbox/impl/ctrl.py'
2--- plainbox/plainbox/impl/ctrl.py 2015-07-07 08:32:21 +0000
3+++ plainbox/plainbox/impl/ctrl.py 2015-09-02 10:07:32 +0000
4@@ -734,10 +734,10 @@
5 # Use non-internationalized environment
6 env['LANG'] = 'C.UTF-8'
7 if 'LANGUAGE' in env:
8- del env['LANGUAGE']
9+ env['LANGUAGE'] = ''
10 for name in list(env.keys()):
11 if name.startswith("LC_"):
12- del env[name]
13+ env[name] = ''
14 else:
15 # Set the per-provider gettext domain and locale directory
16 if job.provider.gettext_domain is not None:
17
18=== modified file 'plainbox/plainbox/impl/test_ctrl.py'
19--- plainbox/plainbox/impl/test_ctrl.py 2015-08-31 10:05:19 +0000
20+++ plainbox/plainbox/impl/test_ctrl.py 2015-09-02 10:07:32 +0000
21@@ -694,6 +694,38 @@
22 # Ensure that LANG is reset to C.UTF-8
23 self.assertEqual(env['LANG'], 'C.UTF-8')
24
25+ @mock.patch.dict('os.environ', clear=True, LANGUAGE='fake_LANGUAGE')
26+ def test_get_execution_environment_resets_LANGUAGE(self):
27+ # Call the tested method
28+ env = self.ctrl.get_execution_environment(
29+ self.job, self.job_state, self.config, self.SESSION_DIR,
30+ self.NEST_DIR)
31+ # Ensure that LANGUAGE exists and is set to ''
32+ self.assertEqual(env['LANGUAGE'], '')
33+
34+ @mock.patch.dict('os.environ', clear=True,
35+ LC_IDENTIFICATION='fake_LC_IDENTIFICATION', LC_TIME='fake_LC_TIME',
36+ LC_NUMERIC='fake_LC_NUMERIC', LC_PAPER='fake_LC_PAPER',
37+ LC_MEASUREMENT='fake_LC_MEASUREMENT', LC_ADDRESS='fake_LC_ADDRESS',
38+ LC_MONETARY='fake_LC_MONETARY', LC_NAME='fake_LC_NAME',
39+ LC_TELEPHONE='fake_LC_TELEPHONE')
40+ def test_get_execution_environment_resets_LC(self):
41+ # Call the tested method
42+ env = self.ctrl.get_execution_environment(
43+ self.job, self.job_state, self.config, self.SESSION_DIR,
44+ self.NEST_DIR)
45+ # Ensure that different LC_* are set to ''
46+ self.assertEqual(env['LC_IDENTIFICATION'], '')
47+ self.assertEqual(env['LC_TIME'], '')
48+ self.assertEqual(env['LC_NUMERIC'], '')
49+ self.assertEqual(env['LC_PAPER'], '')
50+ self.assertEqual(env['LC_MEASUREMENT'], '')
51+ self.assertEqual(env['LC_ADDRESS'], '')
52+ self.assertEqual(env['LC_MONETARY'], '')
53+ self.assertEqual(env['LC_NAME'], '')
54+ self.assertEqual(env['LC_TELEPHONE'], '')
55+
56+
57 @mock.patch.dict('os.environ', clear=True, LANG='fake_LANG')
58 def test_get_execution_environment_preserves_LANG_if_requested(self):
59 self.job.get_flag_set.return_value = {'preserve-locale'}

Subscribers

People subscribed via source and target branches