mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-10 13:04:03 +03:00
Use XDG_RUNTIME_DIR to store control master sockets
On Linux this has the advantage that the dir is auto cleaned on reboot
This commit is contained in:
parent
384c56f834
commit
31d9db7e74
@ -57,6 +57,12 @@ Variables that influence kitty behavior
|
||||
Controls where kitty stores cache files. Defaults to :file:`~/.cache/kitty`
|
||||
or :file:`~/Library/Caches/kitty` on macOS.
|
||||
|
||||
.. envvar:: KITTY_RUNTIME_DIRECTORY
|
||||
|
||||
Controls where kitty stores runtime files like sockets. Defaults to
|
||||
the :code:`XDG_RUNTIME_DIR` environment variable if that is defined
|
||||
otherwise the run directory inside the kitty cache directory is used.
|
||||
|
||||
.. envvar:: VISUAL
|
||||
|
||||
The terminal editor (such as ``vi`` or ``nano``) kitty uses, when, for
|
||||
|
@ -23,7 +23,10 @@ from typing import (
|
||||
Tuple, Union
|
||||
)
|
||||
|
||||
from kitty.constants import cache_dir, shell_integration_dir, terminfo_dir
|
||||
from kitty.constants import (
|
||||
cache_dir, runtime_dir, shell_integration_dir, ssh_control_master_template,
|
||||
terminfo_dir
|
||||
)
|
||||
from kitty.fast_data_types import get_options
|
||||
from kitty.shm import SharedMemory
|
||||
from kitty.utils import SSHConnectionData
|
||||
@ -442,7 +445,7 @@ def get_remote_command(
|
||||
|
||||
|
||||
def connection_sharing_args(opts: SSHOptions, kitty_pid: int) -> List[str]:
|
||||
cp = os.path.join(cache_dir(), 'ssh', f'{kitty_pid}-master-%C')
|
||||
cp = os.path.join(runtime_dir(), ssh_control_master_template.format(kitty_pid=kitty_pid, ssh_placeholder='%C'))
|
||||
ans: List[str] = [
|
||||
'-o', 'ControlMaster=auto',
|
||||
'-o', f'ControlPath={cp}',
|
||||
|
@ -137,6 +137,19 @@ def cache_dir() -> str:
|
||||
return candidate
|
||||
|
||||
|
||||
@run_once
|
||||
def runtime_dir() -> str:
|
||||
if 'KITTY_RUNTIME_DIRECTORY' in os.environ:
|
||||
candidate = os.path.abspath(os.environ['KITTY_RUNTIME_DIRECTORY'])
|
||||
elif 'XDG_RUNTIME_DIR' in os.environ:
|
||||
candidate = os.path.abspath(os.environ['XDG_RUNTIME_DIR'])
|
||||
else:
|
||||
candidate = os.path.join(cache_dir(), 'run')
|
||||
os.makedirs(candidate, exist_ok=True)
|
||||
os.chmod(candidate, 0o700)
|
||||
return candidate
|
||||
|
||||
|
||||
def wakeup() -> None:
|
||||
from .fast_data_types import get_boss
|
||||
b = get_boss()
|
||||
@ -154,6 +167,7 @@ except KeyError:
|
||||
with suppress(Exception):
|
||||
print('Failed to read login shell via getpwuid() for current user, falling back to /bin/sh', file=sys.stderr)
|
||||
shell_path = '/bin/sh'
|
||||
ssh_control_master_template = 'ssh-kitten-{kitty_pid}-master-{ssh_placeholder}'
|
||||
|
||||
|
||||
def glfw_path(module: str) -> str:
|
||||
|
@ -16,8 +16,9 @@ from .cli_stub import CLIOptions
|
||||
from .conf.utils import BadLine
|
||||
from .config import cached_values_for
|
||||
from .constants import (
|
||||
appname, beam_cursor_data_file, cache_dir, config_dir, glfw_path, is_macos,
|
||||
is_wayland, kitty_exe, logo_png_file, running_in_kitty
|
||||
appname, beam_cursor_data_file, config_dir, glfw_path, is_macos,
|
||||
is_wayland, kitty_exe, logo_png_file, running_in_kitty, runtime_dir,
|
||||
ssh_control_master_template
|
||||
)
|
||||
from .fast_data_types import (
|
||||
GLFW_IBEAM_CURSOR, GLFW_MOD_ALT, GLFW_MOD_SHIFT, create_os_window,
|
||||
@ -349,7 +350,7 @@ def cleanup_ssh_control_masters() -> None:
|
||||
import glob
|
||||
import subprocess
|
||||
try:
|
||||
files = glob.glob(os.path.join(cache_dir(), 'ssh', f'{os.getpid()}-master-*'))
|
||||
files = glob.glob(os.path.join(runtime_dir(), ssh_control_master_template.format(kitty_pid=os.getpid(), ssh_placeholder='*')))
|
||||
except OSError:
|
||||
return
|
||||
for x in files:
|
||||
|
Loading…
Reference in New Issue
Block a user