Skip to content

🐛 fix(unix): fall back to tempdir when runtime dir is not writable#369

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
lengau:runtime-dir
Feb 12, 2026
Merged

🐛 fix(unix): fall back to tempdir when runtime dir is not writable#369
gaborbernat merged 1 commit intotox-dev:mainfrom
lengau:runtime-dir

Conversation

@lengau
Copy link
Copy Markdown
Contributor

@lengau lengau commented Aug 22, 2025

When XDG_RUNTIME_DIR is unset and the platform default runtime directory (e.g. /run/user/<uid> on Linux, /var/run/user/<uid> on BSD) does not exist or is not writable, user_runtime_dir previously returned the unusable path anyway. This caused failures for users in environments where the runtime directory hasn't been provisioned — containers, minimal installs, or systems where logind isn't managing the session. 🐛 See #368 for details.

The fix checks writability via os.access instead of mere existence, and falls back to tempfile.gettempdir() when the default path isn't usable. This mirrors the existing BSD fallback pattern (which previously fell back to /tmp/runtime-<uid>) but now applies it uniformly across all Unix platforms and uses Python's tempfile module to respect platform-specific temp directory conventions.

⚠️ Behavioral change: when XDG_RUNTIME_DIR is unset, user_runtime_dir may now return a different path than before on Linux systems where /run/user/<uid> doesn't exist. Previously it would return the non-existent /run/user/<uid> path; now it falls back to <tempdir>/runtime-<uid>. The $XDG_RUNTIME_DIR environment variable continues to take precedence when set.

Closes #368

Co-authored-by: Alex Lowe alex.lowe@canonical.com

Copy link
Copy Markdown
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good once you fix the CI.

@lengau lengau force-pushed the runtime-dir branch 2 times, most recently from 6c4f908 to 569d313 Compare August 22, 2025 16:59
@gaborbernat gaborbernat marked this pull request as draft August 22, 2025 17:01
@gaborbernat gaborbernat changed the title fix(Unix.user_runtime_dir): nonexistent runtime dir 🐛 fix(unix): fall back to tempdir when runtime dir is not writable Feb 12, 2026
@gaborbernat gaborbernat marked this pull request as ready for review February 12, 2026 19:34
When XDG_RUNTIME_DIR is unset and the platform default runtime directory
(e.g. /run/user/<uid>) does not exist or is not writable, fall back to
a temporary directory via tempfile.gettempdir() instead of returning an
unusable path.

Closes tox-dev#368

Co-authored-by: Alex Lowe <alex.lowe@canonical.com>
@gaborbernat gaborbernat merged commit 8c282eb into tox-dev:main Feb 12, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

user_runtime_dir does not follow the XDG standard, potentially leading to crashes.

2 participants