]> git.ipfire.org Git - thirdparty/systemd.git/commit
profile/systemd-osc-context: also escape $USER and $HOSTNAME 43091/head
authorRasmus Villemoes <rv@rasmusvillemoes.dk>
Tue, 21 Jul 2026 08:43:22 +0000 (10:43 +0200)
committerRasmus Villemoes <rv@rasmusvillemoes.dk>
Tue, 21 Jul 2026 09:21:00 +0000 (11:21 +0200)
commit8c6f1c4a210966c963e98acae4f632ce834e1cd6
tree51a748913894efc882ef54b25c37c02f4c63c5ea
parentccace17d2f72b8fce558ea773c932be70bc09bc0
profile/systemd-osc-context: also escape $USER and $HOSTNAME

Claude pointed out that while rather unlikely, it is possible for the USER and
HOSTNAME environment variables to contain problematic characters that require
escaping. Now that that escaping no longer involves the fork+exec overhead of
calling sed, let's ensure those fields do get put through the escape routine.

Refactor __systemd_osc_context_escape so that it not only takes the value and
prints that, but also the format specifier used for emitting the field. That
way, we avoid an extra subshell (i.e. fork+pipe and all that overhead), and
combined with the previous commit, we now only spawn one subshell instead of
two per start= sequence.

That could be reduced to zero, if the "callers" were rewritten to something
like

    printf "\033]3008;start=%.64s;type=shell" "$systemd_osc_context_shell_id"
    __systemd_osc_context_common
    printf "\033\\"

but that will mean that the sequence is not emitted with a single write()
system call [which isn't really guaranteed currently either, just very likely],
so some background process could end up writing to the middle of the sequence,
thus losing that output and mangling the OSC3008 info. This in turn could be
overcome by building the whole sequence in a shell variable using 'printf -v'
and only printing at the end, but that would be a somewhat invasive change.
profile.d/80-systemd-osc-context.sh