diff mbox series

terminal: Show a warning when launched terminal quickly exits

Message ID 20251114-mathieu-too_quick_devshell-v1-1-02b6c6ed9ed6@bootlin.com
State New
Headers show
Series terminal: Show a warning when launched terminal quickly exits | expand

Commit Message

Mathieu Dubois-Briand Nov. 14, 2025, 1:30 p.m. UTC
Terminals quitting in less than one second are likely the result of a
failure to execute the launched command: show a warning including the
command that was launched, so the user can try to debug this.

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
I recently had issues launching devshell because of some environment
variables containing unsupported chars. While my specific issue probably
has to be fixed on the bitbake side [1], it was a bit tricky to
understand because no error was shown and the fail was so quick that I
was never able to see any terminal window popping.

Adding a warning in such a case should help the user to understand what
is going wrong.

[1]: https://lore.kernel.org/r/20251114-mathieu-back_quote_devshell-v1-0-45e83df2f362@bootlin.com
---
 meta/lib/oe/terminal.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)


---
base-commit: e556df28f47e754b53e1f46c97dde2b19fd8fad1
change-id: 20251114-mathieu-too_quick_devshell-c9085d3538f0

Best regards,

Comments

Peter Kjellerstedt Nov. 14, 2025, 3:31 p.m. UTC | #1
> -----Original Message-----
> From: openembedded-core@lists.openembedded.org <openembedded-core@lists.openembedded.org> On Behalf Of Mathieu Dubois-Briand via lists.openembedded.org
> Sent: den 14 november 2025 14:30
> To: openembedded-core@lists.openembedded.org
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>; Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
> Subject: [OE-core] [PATCH] terminal: Show a warning when launched terminal quickly exits
> 
> Terminals quitting in less than one second are likely the result of a
> failure to execute the launched command: show a warning including the
> command that was launched, so the user can try to debug this.
> 
> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
> ---
> I recently had issues launching devshell because of some environment
> variables containing unsupported chars. While my specific issue probably
> has to be fixed on the bitbake side [1], it was a bit tricky to
> understand because no error was shown and the fail was so quick that I
> was never able to see any terminal window popping.
> 
> Adding a warning in such a case should help the user to understand what
> is going wrong.
> 
> [1]: https://lore.kernel.org/r/20251114-mathieu-back_quote_devshell-v1-0-45e83df2f362@bootlin.com
> ---
>  meta/lib/oe/terminal.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
> index 4412bc14c1d1..068269018dbb 100644
> --- a/meta/lib/oe/terminal.py
> +++ b/meta/lib/oe/terminal.py
> @@ -240,6 +240,7 @@ def spawn(name, sh_cmd, title=None, env=None, d=None):
>      import tempfile
>      import time
>      pidfile = tempfile.NamedTemporaryFile(delete = False).name
> +    start_time = None
>      try:
>          sh_cmd = bb.utils.which(os.getenv('PATH'), "oe-gnome-terminal-phonehome") + " " + pidfile + " " + sh_cmd
>          pipe = terminal(sh_cmd, title, env, d)
> @@ -249,6 +250,7 @@ def spawn(name, sh_cmd, title=None, env=None, d=None):
>          if pipe.returncode != 0:
>              raise ExecutionError(sh_cmd, pipe.returncode, output)
> 
> +        start_time = time.time()
>          while os.stat(pidfile).st_size <= 0:
>              time.sleep(0.01)
>              continue
> @@ -262,7 +264,10 @@ def spawn(name, sh_cmd, title=None, env=None, d=None):
>              os.kill(pid, 0)
>              time.sleep(0.1)
>          except OSError:
> -           return
> +            if start_time and (time.time() - start_time < 1):
> +                bb.warn("Terminal \"%s\" started but stopped only after %.2fs while running \"%s\""

"only after" -> "after only"

> +                        % (name, time.time() - start_time, sh_cmd))
> +            return
> 
>  def check_tmux_version(desired):
>      vernum = check_terminal_version("tmux")
> 
> ---
> base-commit: e556df28f47e754b53e1f46c97dde2b19fd8fad1
> change-id: 20251114-mathieu-too_quick_devshell-c9085d3538f0
> 
> Best regards,
> --
> Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>

//Peter
Mathieu Dubois-Briand Nov. 14, 2025, 5:38 p.m. UTC | #2
On Fri Nov 14, 2025 at 4:31 PM CET, Peter Kjellerstedt via lists.openembedded.org wrote:
>> -----Original Message-----
>> From: openembedded-core@lists.openembedded.org <openembedded-core@lists.openembedded.org> On Behalf Of Mathieu Dubois-Briand via lists.openembedded.org
>> Sent: den 14 november 2025 14:30
>> To: openembedded-core@lists.openembedded.org
>> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>; Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
>> Subject: [OE-core] [PATCH] terminal: Show a warning when launched terminal quickly exits
>> 
> ...
>> @@ -262,7 +264,10 @@ def spawn(name, sh_cmd, title=None, env=None, d=None):
>>              os.kill(pid, 0)
>>              time.sleep(0.1)
>>          except OSError:
>> -           return
>> +            if start_time and (time.time() - start_time < 1):
>> +                bb.warn("Terminal \"%s\" started but stopped only after %.2fs while running \"%s\""
>
> "only after" -> "after only"
>

Thanks, I will fix it for next version!
diff mbox series

Patch

diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
index 4412bc14c1d1..068269018dbb 100644
--- a/meta/lib/oe/terminal.py
+++ b/meta/lib/oe/terminal.py
@@ -240,6 +240,7 @@  def spawn(name, sh_cmd, title=None, env=None, d=None):
     import tempfile
     import time
     pidfile = tempfile.NamedTemporaryFile(delete = False).name
+    start_time = None
     try:
         sh_cmd = bb.utils.which(os.getenv('PATH'), "oe-gnome-terminal-phonehome") + " " + pidfile + " " + sh_cmd
         pipe = terminal(sh_cmd, title, env, d)
@@ -249,6 +250,7 @@  def spawn(name, sh_cmd, title=None, env=None, d=None):
         if pipe.returncode != 0:
             raise ExecutionError(sh_cmd, pipe.returncode, output)
 
+        start_time = time.time()
         while os.stat(pidfile).st_size <= 0:
             time.sleep(0.01)
             continue
@@ -262,7 +264,10 @@  def spawn(name, sh_cmd, title=None, env=None, d=None):
             os.kill(pid, 0)
             time.sleep(0.1)
         except OSError:
-           return
+            if start_time and (time.time() - start_time < 1):
+                bb.warn("Terminal \"%s\" started but stopped only after %.2fs while running \"%s\""
+                        % (name, time.time() - start_time, sh_cmd))
+            return
 
 def check_tmux_version(desired):
     vernum = check_terminal_version("tmux")