<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>3371</bug_id>
          
          <creation_ts>2012-10-31 15:06:39 +0000</creation_ts>
          <short_desc>Terminal (devshell, menuconfig) code broken in latest master</short_desc>
          <delta_ts>2012-12-05 14:57:29 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>core</component>
          <version>1.4</version>
          <rep_platform>All</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>A raw solution, waiting for advices and suggestions</status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>1.4 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Paul Eggleton">bluelightning</reporter>
          <assigned_to name="Chen Qi">Qi.Chen</assigned_to>
          <cc>alexandrux.palalau</cc>
    
    <cc>liezhi.yang</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>Qi.Chen</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>sgw</cc>
    
    <cc>zhenfeng.zhao</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>---</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>27120</commentid>
    <comment_count>0</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2012-10-31 15:06:39 +0000</bug_when>
    <thetext>With latest master if you run bitbake -c devshell &lt;target&gt; or bitbake -c devshell virtual/kernel, you get multiple terminals launched instead of just one. This has been traced back to the following revision - reverting this fixes the problem:

http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=c45a7d127e76a43069f12483b7453a3778ae0126</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27122</commentid>
    <comment_count>1</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2012-10-31 15:10:01 +0000</bug_when>
    <thetext>Oops, that second example should have been bitbake -c menuconfig virtual/kernel.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27180</commentid>
    <comment_count>2</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2012-11-02 06:39:53 +0000</bug_when>
    <thetext>%problem, cause, solution and a raw patch%

A rough analysis about this issue. Any suggestion would be welcome.

problem
-------
1) two terminals are launched instead of one
2) the environment is not correct, &apos;echo $PATH&apos; for a verification

cause
-----
c76da87511d2668479745c2f18b8a9b8116c7489 in OE core changed the default behavior of terminal.bbclass

Problem 1 may be caused by the os.environ not correctly set, as that commit removed &quot;os.environ[export] = str(value)&quot;. 

Problem 2 is caused by passing wrong argument to the oe.terminal.spawn which invokes subprocess.Popen to do the actual job underneath. 
-            oe.terminal.spawn(terminal, command, title, None, d)
+            oe.terminal.spawn(terminal, command, title, env, d)
Changing the default fourth para from &apos;None&apos; to env will override the environment in child process. The environment in child process in no longer the same with its parent which has the correct values for environment variables such as PATH.

solution
--------
Change all things back. The env argument is not needed, and what&apos;s more, it causes trouble.

patch
-----
diff --git a/meta/classes/terminal.bbclass b/meta/classes/terminal.bbclass
index 51846c1..906fa58 100644
--- a/meta/classes/terminal.bbclass
+++ b/meta/classes/terminal.bbclass
@@ -15,19 +15,17 @@ def oe_terminal(command, title, d):
     import oe.data
     import oe.terminal
 
-    env = dict()
-
     for export in oe.data.typed_value(&apos;OE_TERMINAL_EXPORTS&apos;, d):
         value = d.getVar(export, True)
         if value is not None:
-            env[export] = str(value)
+            os.environ[export] = str(value)
 
     terminal = oe.data.typed_value(&apos;OE_TERMINAL&apos;, d).lower()
     if terminal == &apos;none&apos;:
         bb.fatal(&apos;Devshell usage disabled with OE_TERMINAL&apos;)
     elif terminal != &apos;auto&apos;:
         try:
-            oe.terminal.spawn(terminal, command, title, env, d)
+            oe.terminal.spawn(terminal, command, title, None, d)
             return
         except oe.terminal.UnsupportedTerminal:
             bb.warn(&apos;Unsupported terminal &quot;%s&quot;, defaulting to &quot;auto&quot;&apos; %
@@ -36,7 +34,7 @@ def oe_terminal(command, title, d):
             bb.fatal(&apos;Unable to spawn terminal %s: %s&apos; % (terminal, exc))
 
     try:
-        oe.terminal.spawn_preferred(command, title, env, d)
+        oe.terminal.spawn_preferred(command, title, None, d)
     except oe.terminal.NoSupportedTerminals:
         bb.fatal(&apos;No valid terminal found, unable to open devshell&apos;)
     except oe.terminal.ExecutionError as exc:</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27181</commentid>
    <comment_count>3</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2012-11-02 06:50:25 +0000</bug_when>
    <thetext>An explanation of the &apos;env&apos; para in subprocess.Popen:
&quot;If env is not None, it must be a mapping that defines the environment variables for the new process; these are used instead of inheriting the current process’ environment, which is the default behavior.&quot;

From: http://docs.python.org/2/library/subprocess.html#subprocess.Popen</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27193</commentid>
    <comment_count>4</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2012-11-02 10:05:10 +0000</bug_when>
    <thetext>I have to say I think we should just revert the patch in question.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27194</commentid>
    <comment_count>5</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2012-11-02 10:23:24 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; I have to say I think we should just revert the patch in question.

Ah... Yes. Reverting it would be better. Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27362</commentid>
    <comment_count>6</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2012-11-12 16:11:42 +0000</bug_when>
    <thetext>Fixed in master:

http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=05a1f4a5a32c6cc392fa4480732101d668cd6f77
http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=ad9ad06056bb9ee1f9da54d60dfabb3240798018</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27998</commentid>
    <comment_count>7</comment_count>
    <who name="Alexandru Palalau">alexandrux.palalau</who>
    <bug_when>2012-12-05 14:57:29 +0000</bug_when>
    <thetext>Switching to verified</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>