forked from systemd/systemd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue OSC ANSI sequence whenever we change "context" of a TTY, i.e. a…
…cquire privs, enter container or VM or similar (systemd#35224) This is mostly a strawman to get a discussion going regarding how to communicate to terminal emulators such as ptyxis about run0 (and nspawn, and vmspawn, and moe) and what it does. It's hierarchical and I think still relatively simple. /cc @chergert
- Loading branch information
Showing
30 changed files
with
1,208 additions
and
49 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# shellcheck shell=bash | ||
# shellcheck disable=SC2016 | ||
# shellcheck disable=SC1003 | ||
|
||
# This file is part of systemd. | ||
# | ||
# systemd is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation; either version 2.1 of the License, or | ||
# (at your option) any later version. | ||
|
||
__systemd_osc_context_escape() { | ||
# Escape according to the OSC 8003 spec. Since this requires shelling out | ||
# to 'sed' we'll only do it where it's strictly necessary, and skip it when | ||
# processing strings we are pretty sure we won't need it for, such as | ||
# uuids, id128, hostnames, usernames, since they all come with syntax | ||
# requirements that exclude \ and ; anyway. This hence primarily is about | ||
# escaping the current working directory. | ||
echo "$1" | sed -e 's/\\/\\x5x/g' -e 's/;/\\x3b/g' | ||
} | ||
|
||
__systemd_osc_context_common() { | ||
printf ";user=%s;hostname=%s;machineid=%s;bootid=%s;pid=%s" "$USER" "$HOSTNAME" "$(</etc/machine-id)" "$(</proc/sys/kernel/random/boot_id)" "$$" | ||
} | ||
|
||
__systemd_osc_context_precmdline() { | ||
local systemd_exitstatus="$?" | ||
|
||
# Close previous command | ||
if [ -n "${systemd_osc_context_cmd_id:-}" ]; then | ||
if [ "$systemd_exitstatus" -ge 127 ]; then | ||
printf "\033]8003;end=%s;exit=interrupt;signal=%s\033\\" "$systemd_osc_context_cmd_id" $((systemd_exitstatus-127)) | ||
elif [ "$systemd_exitstatus" -ne 0 ]; then | ||
printf "\033]8003;end=%s;exit=failure;status=%s\033\\" "$systemd_osc_context_cmd_id" $((systemd_exitstatus)) | ||
else | ||
printf "\033]8003;end=%s;exit=success\033\\" "$systemd_osc_context_cmd_id" | ||
fi | ||
fi | ||
|
||
# Prepare a context ID for this shell if we have none | ||
if [ -z "${systemd_osc_context_shell_id:-}" ]; then | ||
read -r systemd_osc_context_shell_id </proc/sys/kernel/random/uuid | ||
fi | ||
|
||
# Create or update the shell session | ||
printf "\033]8003;start=%s%s;type=shell;cwd=%s\033\\" "$systemd_osc_context_shell_id" "$(__systemd_osc_context_common)" "$(__systemd_osc_context_escape "$PWD")" | ||
|
||
# Prepare cmd id for next command | ||
read -r systemd_osc_context_cmd_id </proc/sys/kernel/random/uuid | ||
} | ||
|
||
if [[ -n "${BASH_VERSION:-}" ]]; then | ||
# Whenever a new prompt is shown close the previous command, and prepare new command | ||
PROMPT_COMMAND+=(__systemd_osc_context_precmdline) | ||
|
||
# PS0 is shown right after a prompt completed, but before the command is executed | ||
PS0='\033]8003;start=$systemd_osc_context_cmd_id$(__systemd_osc_context_common);type=command;cwd=$(__systemd_osc_context_escape "$PWD")\033\\'"${PS0:-}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
install_data('70-systemd-shell-extra.sh', install_dir : shellprofiledir.startswith('/usr/') ? shellprofiledir : libexecdir / 'profile.d') | ||
install_data('80-systemd-osc-context.sh', install_dir : shellprofiledir.startswith('/usr/') ? shellprofiledir : libexecdir / 'profile.d') | ||
|
||
if conf.get('LINK_SHELL_EXTRA_DROPIN') == 1 | ||
install_emptydir(shellprofiledir) | ||
|
||
meson.add_install_script(sh, '-c', | ||
ln_s.format(libexecdir / 'profile.d' / '70-systemd-shell-extra.sh', shellprofiledir / '70-systemd-shell-extra.sh')) | ||
endif | ||
|
||
if conf.get('LINK_OSC_CONTEXT_DROPIN') == 1 | ||
install_emptydir(shellprofiledir) | ||
|
||
meson.add_install_script(sh, '-c', | ||
ln_s.format(libexecdir / 'profile.d' / '80-systemd-osc-context.sh', shellprofiledir / '80-systemd-osc-context.sh')) | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.