mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-10-21 04:32:05 +00:00
Linux only allow single instance socket use by same user
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
This commit is contained in:
parent
dcedd186de
commit
c85bcda29c
7 changed files with 150 additions and 29 deletions
53
kitty_tests/single_instance.py
Normal file
53
kitty_tests/single_instance.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python
|
||||
# License: GPL v3 Copyright: 2026, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
from contextlib import closing
|
||||
|
||||
from kitty.constants import kitty_exe
|
||||
|
||||
from .base import BaseTest
|
||||
|
||||
|
||||
class TestSingleInstance(BaseTest):
|
||||
def test_single_instance_client(self):
|
||||
# Test that a client can talk to a single instance socket belonging to
|
||||
# the same user. The abstract socket namespace used below exists only
|
||||
# on Linux.
|
||||
if not sys.platform.startswith('linux'):
|
||||
self.skipTest('Abstract UNIX sockets are only available on Linux')
|
||||
group = f'test-{os.getpid()}'
|
||||
with closing(socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)) as server:
|
||||
server.bind('\0' + f'kitty-ipc-{os.geteuid()}-{group}')
|
||||
server.listen()
|
||||
env = os.environ.copy()
|
||||
env['KITTY_SINGLE_INSTANCE_TEST'] = 'xyz'
|
||||
p = subprocess.Popen(
|
||||
[kitty_exe(), '--single-instance', f'--instance-group={group}', '--title', 'si-test-title'],
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
try:
|
||||
with closing(server.accept()[0]) as peer:
|
||||
data = b''
|
||||
while True:
|
||||
d = peer.recv(8192)
|
||||
if not d:
|
||||
break
|
||||
data += d
|
||||
output = p.communicate(timeout=30)[0].decode()
|
||||
finally:
|
||||
if p.poll() is None:
|
||||
p.kill()
|
||||
p.wait()
|
||||
self.assertEqual(p.returncode, 0, f'kitty --single-instance failed with output: {output}')
|
||||
msg = json.loads(data.decode('utf-8'))
|
||||
self.assertEqual(msg['cmd'], 'new_instance')
|
||||
self.assertIn('si-test-title', msg['args'])
|
||||
self.assertEqual(msg['cwd'], os.getcwd())
|
||||
self.assertEqual(msg['environ'].get('KITTY_SINGLE_INSTANCE_TEST'), 'xyz')
|
||||
Loading…
Add table
Add a link
Reference in a new issue