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
=== modified file 'plainbox/plainbox/impl/ctrl.py'
--- plainbox/plainbox/impl/ctrl.py 2015-07-07 08:32:21 +0000
+++ plainbox/plainbox/impl/ctrl.py 2015-09-02 10:07:32 +0000
@@ -734,10 +734,10 @@
734 # Use non-internationalized environment734 # Use non-internationalized environment
735 env['LANG'] = 'C.UTF-8'735 env['LANG'] = 'C.UTF-8'
736 if 'LANGUAGE' in env:736 if 'LANGUAGE' in env:
737 del env['LANGUAGE']737 env['LANGUAGE'] = ''
738 for name in list(env.keys()):738 for name in list(env.keys()):
739 if name.startswith("LC_"):739 if name.startswith("LC_"):
740 del env[name]740 env[name] = ''
741 else:741 else:
742 # Set the per-provider gettext domain and locale directory742 # Set the per-provider gettext domain and locale directory
743 if job.provider.gettext_domain is not None:743 if job.provider.gettext_domain is not None:
744744
=== modified file 'plainbox/plainbox/impl/test_ctrl.py'
--- plainbox/plainbox/impl/test_ctrl.py 2015-08-31 10:05:19 +0000
+++ plainbox/plainbox/impl/test_ctrl.py 2015-09-02 10:07:32 +0000
@@ -694,6 +694,38 @@
694 # Ensure that LANG is reset to C.UTF-8694 # Ensure that LANG is reset to C.UTF-8
695 self.assertEqual(env['LANG'], 'C.UTF-8')695 self.assertEqual(env['LANG'], 'C.UTF-8')
696696
697 @mock.patch.dict('os.environ', clear=True, LANGUAGE='fake_LANGUAGE')
698 def test_get_execution_environment_resets_LANGUAGE(self):
699 # Call the tested method
700 env = self.ctrl.get_execution_environment(
701 self.job, self.job_state, self.config, self.SESSION_DIR,
702 self.NEST_DIR)
703 # Ensure that LANGUAGE exists and is set to ''
704 self.assertEqual(env['LANGUAGE'], '')
705
706 @mock.patch.dict('os.environ', clear=True,
707 LC_IDENTIFICATION='fake_LC_IDENTIFICATION', LC_TIME='fake_LC_TIME',
708 LC_NUMERIC='fake_LC_NUMERIC', LC_PAPER='fake_LC_PAPER',
709 LC_MEASUREMENT='fake_LC_MEASUREMENT', LC_ADDRESS='fake_LC_ADDRESS',
710 LC_MONETARY='fake_LC_MONETARY', LC_NAME='fake_LC_NAME',
711 LC_TELEPHONE='fake_LC_TELEPHONE')
712 def test_get_execution_environment_resets_LC(self):
713 # Call the tested method
714 env = self.ctrl.get_execution_environment(
715 self.job, self.job_state, self.config, self.SESSION_DIR,
716 self.NEST_DIR)
717 # Ensure that different LC_* are set to ''
718 self.assertEqual(env['LC_IDENTIFICATION'], '')
719 self.assertEqual(env['LC_TIME'], '')
720 self.assertEqual(env['LC_NUMERIC'], '')
721 self.assertEqual(env['LC_PAPER'], '')
722 self.assertEqual(env['LC_MEASUREMENT'], '')
723 self.assertEqual(env['LC_ADDRESS'], '')
724 self.assertEqual(env['LC_MONETARY'], '')
725 self.assertEqual(env['LC_NAME'], '')
726 self.assertEqual(env['LC_TELEPHONE'], '')
727
728
697 @mock.patch.dict('os.environ', clear=True, LANG='fake_LANG')729 @mock.patch.dict('os.environ', clear=True, LANG='fake_LANG')
698 def test_get_execution_environment_preserves_LANG_if_requested(self):730 def test_get_execution_environment_preserves_LANG_if_requested(self):
699 self.job.get_flag_set.return_value = {'preserve-locale'}731 self.job.get_flag_set.return_value = {'preserve-locale'}

Subscribers

People subscribed via source and target branches