mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-09-28 22:16:05 +02:00
fix(ssh-agent): create screen/tmux symlink atomically (#14035)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
This commit is contained in:
co-authored by
Carlo Sala
parent
9112b53fa8
commit
3f84a2ae4a
@@ -101,10 +101,18 @@ if zstyle -t :omz:plugins:ssh-agent agent-forwarding \
|
|||||||
&& [[ -n "$SSH_AUTH_SOCK" ]]; then
|
&& [[ -n "$SSH_AUTH_SOCK" ]]; then
|
||||||
if [[ ! -L "$SSH_AUTH_SOCK" ]]; then
|
if [[ ! -L "$SSH_AUTH_SOCK" ]]; then
|
||||||
if [[ -n "$TERMUX_VERSION" ]]; then
|
if [[ -n "$TERMUX_VERSION" ]]; then
|
||||||
ln -sf "$SSH_AUTH_SOCK" "$PREFIX"/tmp/ssh-agent-$USERNAME-screen
|
_omz_ssh_agent_link="$PREFIX"/tmp/ssh-agent-$USERNAME-screen
|
||||||
else
|
else
|
||||||
ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USERNAME-screen
|
_omz_ssh_agent_link=/tmp/ssh-agent-$USERNAME-screen
|
||||||
fi
|
fi
|
||||||
|
# `ln -sf` unlinks the old symlink and then creates the new one: two
|
||||||
|
# syscalls, no atomic swap. Shells starting concurrently (a tmux window
|
||||||
|
# opening several panes at once) interleave those steps and all but one
|
||||||
|
# fail with "ln: ...: File exists". Stage the link under a PID-unique
|
||||||
|
# name and move it into place, since rename(2) is atomic.
|
||||||
|
command ln -sf "$SSH_AUTH_SOCK" "$_omz_ssh_agent_link.$$" \
|
||||||
|
&& command mv -f "$_omz_ssh_agent_link.$$" "$_omz_ssh_agent_link"
|
||||||
|
unset _omz_ssh_agent_link
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
_start_agent
|
_start_agent
|
||||||
|
|||||||
Reference in New Issue
Block a user