GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix hardcoded /tmp path for Unix socket in unix_connect by luckyabsoluter · Pull Request #288 · python-xlib/python-xlib

Conversation

@luckyabsoluter

@luckyabsoluter luckyabsoluter commented Apr 20, 2026

Copy link
Copy Markdown

Problem:

  • The unix_connect function previously hardcoded /tmp as the directory for the Unix socket path.
  • This causes compatibility issues on platforms or specific environments that use a different temporary directory, or even lack access to /tmp entirely.

Actions:

  • Imported the tempfile module in unix_connect.
  • Updated the X11 Unix socket path generation to dynamically use tempfile.gettempdir().

Result:

  • The Unix socket path now correctly adapts to the system's runtime configuration (e.g., OS defaults or TMPDIR environment variables), improving cross-platform compatibility.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@luckyabsoluter
Fix hardcoded /tmp path for Unix socket in unix_connect
3a2782c
Problem:
- The unix_connect function previously hardcoded /tmp as the directory for the Unix socket path.
- This causes compatibility issues on platforms or specific environments that use a different temporary directory, or even lack access to /tmp entirely.

Actions:
- Imported the tempfile module in unix_connect.
- Updated the X11 Unix socket path generation to dynamically use tempfile.gettempdir().

Result:
- The Unix socket path now correctly adapts to the system's runtime configuration (e.g., OS defaults or TMPDIR environment variables), improving cross-platform compatibility.
@luckyabsoluter luckyabsoluter mentioned this pull request Apr 20, 2026
Fix hardcoded /tmp path for Unix socket in lock_files mdmintz/sbVirtualDisplay#12
Open
@Avasam

Avasam commented Nov 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Pretty sure the convention IS to use /tmp/.X11-unix/X as the socket path. This PR would just break things.

tempfile.gettempdir() reads TMPDIR, TEMP and TMP. Debian's libpam-tmpdir sets TMPDIR=/tmp/user/<uid> for every login, so this PR would look for /tmp/user/1000/.X11-unix/X0, which doesn't exist. The abstract socket fallback would also break, because this PR builds that name from the same path. The server listens on the abstract name @/tmp/.X11-unix/X0, which is also fixed, so both lookups would miss. Every other X client on that machine would still connect fine.

The one real exception is macOS XQuartz, whose socket lives under /private/tmp/com.apple.launchd.*. Though that path comes through DISPLAY, not TMPDIR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@luckyabsoluter

luckyabsoluter commented Nov 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

That is a very valid point. While the goal here is to support Termux on Android (where X servers must place their sockets under $TMPDIR mainly because standard /tmp is inaccessible), relying unconditionally on tempfile.gettempdir() or TMPDIR across all environments is an overly broad fix.

To solve this without causing regressions on standard Linux, a few alternative approaches were considered:

  • Socket connection fallback (trying /tmp first, then $TMPDIR):

    • Automatically probing fallback directories upon failure carries a security risk of connecting to an unintended socket and exposing X11 authentication data.
  • Checking sys.platform == 'android':

    • Since 'android' was only introduced in Python 3.13, supporting Python < 3.13 would require a redundant fallback to TERMUX_VERSION anyway. Moreover, given how narrow the X11 ecosystem on Android is, rather than casting a wide net with a dual check, it is much cleaner and safer to just target Termux directly with a single check.

This narrows the practical solutions down to two main options:

1. Keep the project strictly platform-agnostic: Introduce a dedicated environment variable

  • For example, allowing users to explicitly override the socket directory via something like PYTHON_XLIB_SOCKET_DIR.
  • This avoids environment-specific checks in the codebase, though it introduces a new configuration variable that users must set manually.

2. Allow a Termux-specific branch: Detect TERMUX_VERSION (Recommended)

  • Narrow the target strictly to Termux by only using TMPDIR when TERMUX_VERSION is present, keeping /tmp as the default everywhere else.
  • This is the most pragmatic and minimal fix—it requires no new imports or user configuration, works out-of-the-box on Termux across all Python versions, and has zero impact on standard Linux environments.
  • However, since TERMUX_VERSION is a fairly common name combination, users who define it for other purposes—unaware that it triggers special behavior in python-xlib—could inadvertently expose themselves to the aforementioned TMPDIR security risks or connection issues. (To mitigate this risk, we could combine the check like if os.getenv('TERMUX_VERSION') and 'com.termux' in os.getenv('PREFIX', ''):.)
tmpdir = '/tmp'
if os.getenv('TERMUX_VERSION'):  # if os.getenv('TERMUX_VERSION') and 'com.termux' in os.getenv('PREFIX', ''):
    tmpdir = os.getenv('TMPDIR') or tmpdir
address = os.path.join(tmpdir, '.X11-unix', 'X%d' % dno)

Addressing this properly will likely require submitting a new PR. Before doing that, I would like to open this up for discussion and hear everyone's thoughts on which direction seems best.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@luckyabsoluter @Avasam
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.