Skip to content

Commit

Permalink
Merge pull request #44 from hartwork/improve-pty-handling
Browse files Browse the repository at this point in the history
Improve PTY handling
  • Loading branch information
hartwork authored Dec 22, 2023
2 parents 0f08288 + afc8f3c commit 31e1017
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 82 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "sandwine"
version = "3.0.0"
version = "4.0.0"
license = {text = "GPLv3+"}
description = "Command-line tool to run Windows apps with Wine and bwrap/bubblewrap isolation"
readme = {file = "README.md", content-type = "text/markdown"}
Expand All @@ -31,7 +31,6 @@ authors = [
requires-python = ">=3.9"
dependencies = [
"coloredlogs>=15.0.1",
"pexpect>=4.9.0",
]
keywords = ["Wine", "sandbox", "sandboxing", "bubblewrap", "bwrap"]
classifiers = [
Expand Down
28 changes: 16 additions & 12 deletions sandwine/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import coloredlogs

from sandwine._pty import pty_spawn_argv
from sandwine._x11 import X11Display, X11Mode, create_x11_context, detect_and_require_nested_x11

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -411,12 +410,24 @@ def create_bwrap_argv(config):
if config.second_try:
argv.add('sh', '-c', '"$0" "$@" || exec "$0" "$@"')

# Add Wine
# Add Wine and PTY
if config.argv_0 is not None:
# Add Wine
inner_argv = []
if config.with_wine:
argv.add('wine', config.argv_0, *config.argv_1_plus)
inner_argv.append('wine')
inner_argv.append(config.argv_0)
inner_argv.extend(config.argv_1_plus)

# Add PTY
if config.with_pty:
# NOTE: This implementation is known to not support Ctrl+Z (SIGTSTP).
# Implementing something with Ctrl+Z support is complex and planned for later.
# The current approach is inspired by ptysolate by Jakub Wilk:
# https://github.com/jwilk/ptysolate
argv.add('script', '-e', '-q', '-c', f'exec {shlex.join(inner_argv)}', '/dev/null')
else:
argv.add(config.argv_0, *config.argv_1_plus)
argv.add(*inner_argv)
else:
argv.add('true')

Expand All @@ -431,13 +442,6 @@ def require_recent_bubblewrap():
sys.exit(1)


def spawn_argv(argv: list[str], with_pty: bool) -> int:
if not with_pty:
return subprocess.call(argv)

return pty_spawn_argv(argv)


def main():
exit_code = 0
try:
Expand Down Expand Up @@ -472,7 +476,7 @@ def main():

with x11context:
try:
exit_code = spawn_argv(argv, with_pty=config.with_pty)
exit_code = subprocess.call(argv)
except FileNotFoundError:
_logger.error(f'Command {argv[0]!r} is not available, aborting.')
exit_code = 127
Expand Down
68 changes: 0 additions & 68 deletions sandwine/_pty.py

This file was deleted.

0 comments on commit 31e1017

Please sign in to comment.