Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set sticky bit on connection files #201

Merged
merged 3 commits into from
Feb 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions jupyter_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import json
import os
import socket
import stat
import tempfile
import warnings
from getpass import getpass
Expand Down Expand Up @@ -135,6 +136,27 @@ def write_connection_file(fname=None, shell_port=0, iopub_port=0, stdin_port=0,
with open(fname, 'w') as f:
f.write(json.dumps(cfg, indent=2))

if hasattr(stat, 'S_ISVTX'):
# set the sticky bit on the file and its parent directory
# to avoid periodic cleanup
paths = [fname]
runtime_dir = os.path.dirname(fname)
if runtime_dir:
paths.append(runtime_dir)
for path in paths:
permissions = os.stat(path).st_mode
new_permissions = permissions | stat.S_ISVTX
if new_permissions != permissions:
try:
os.chmod(path, permissions)
except OSError as e:
# failed to set sticky bit,
# probably not a big deal
warnings.warn(
"Failed to set sticky bit on %r: %s" % (path, e),
RuntimeWarning,
)

return fname, cfg


Expand Down