Skip to content

systemd-run --pty blocks indefinitely when printing in both ExecStartPre/ExecStopPost and main command #32916

Closed

Description

@oxalica

systemd version the issue has been seen with

255.6-1-arch, 255.4

Used distribution

Arch Linux, NixOS unstable

Linux kernel version used

6.9.1-arch1-1, 6.9.0-rc6

CPU architectures issue was seen on

x86_64

Component

systemd-run

Expected behaviour you didn't see

Show outputs from ExecStartPre command, then from ExecStart command, then from ExecStopPost, and finally exit.

Unexpected behaviour you saw

Show outputs from ExecStartPre command, then blocks indefinitely without showing outputs of the main command. It does not exit even after the main command exits or hitting Ctrl-] several times.

Steps to reproduce the problem

$ systemd-run --user --pty --collect --service-type=exec --property=ExecStartPre='/bin/sh -c "echo pre"' -- echo work
Running as unit: run-u4179.service; invocation ID: efce5f29353341febf359cefd4a00faa
Press ^] three times within 1s to disconnect TTY.
pre
<blocks indefinitely, until hitting Ctrl-C. Note that Ctrl-] does not work.>
  • When blocked, hitting Ctrl-] 3 times within 1s also does nothing.
  • When blocked, the main service echo work is already executed and exited. It can be observed by using bash -c 'echo work; sleep 5' as main command and checking htop.
  • It must be both ExecStartPre and the main command printing something into either stdout or stderr. If one of them prints nothing (eg. true or sleep), it does not trigger the issue.
  • ExecStopPost also reproduces. This is actually the original issue I've entered. Because I want to add some cleanup code after the transient service command exits, even when it's stopped abnormally.
  • Use --pipe instead of --pty works as expected. But that is not suitable when the command need an actual PTY.

Additional program output to the terminal or log subsystem illustrating the issue

$ journalctl --user -u run-u4179.service --since=-1h
May 18 20:01:52 invar systemd[1936]: Starting /run/current-system/sw/bin/echo work...
May 18 20:01:52 invar systemd[1936]: Started /run/current-system/sw/bin/echo work.

Backtrace of `systemd-run`:
#0  0x00007f26ed71d1c7 in epoll_wait () from /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6
#1  0x00007f26edad95d5 in sd_event_wait ()
   from /nix/store/7kq9hvrhcy8g1v0jd07nr54279asg9vc-systemd-255.4/lib/systemd/libsystemd-shared-255.so
#2  0x00007f26edadb95b in sd_event_run ()
   from /nix/store/7kq9hvrhcy8g1v0jd07nr54279asg9vc-systemd-255.4/lib/systemd/libsystemd-shared-255.so
#3  0x00007f26edadbb4f in sd_event_loop ()
   from /nix/store/7kq9hvrhcy8g1v0jd07nr54279asg9vc-systemd-255.4/lib/systemd/libsystemd-shared-255.so
#4  0x000055c1d823fc23 in start_transient_service ()
#5  0x000055c1d823ad6a in main ()

Activity

  1. added
    bug 🐛
    on May 19, 2024
  2. added a commit that references this issue on May 19, 2024
    28459ba
  3. added a commit that references this issue on May 28, 2024
    182b80b
  4. added a commit that references this issue on Oct 24, 2024
    369d7d4
  5. added a commit that references this issue on Jan 3, 2025
    e11f7a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛run

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions