From 50e59aee4491c03340cab1e2b56ff80fe9a41ed3 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 9 Aug 2017 15:00:05 +0200 Subject: [PATCH 1/2] actually set sticky bit use new_permissions, not old! --- jupyter_client/connect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index afe197688..dd359c907 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -148,7 +148,7 @@ def write_connection_file(fname=None, shell_port=0, iopub_port=0, stdin_port=0, new_permissions = permissions | stat.S_ISVTX if new_permissions != permissions: try: - os.chmod(path, permissions) + os.chmod(path, new_permissions) except OSError as e: # failed to set sticky bit, # probably not a big deal From 02bd87703ca47b291f0f329af3cf8a9e7e0b2124 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 9 Aug 2017 15:04:39 +0200 Subject: [PATCH 2/2] suppress permission error setting sticky bit on runtime_dir may not be permitted when using temporary files on some platforms and soften warning, explaining consequences. --- jupyter_client/connect.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index dd359c907..9f629c143 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -10,6 +10,7 @@ from __future__ import absolute_import +import errno import glob import json import os @@ -150,12 +151,17 @@ def write_connection_file(fname=None, shell_port=0, iopub_port=0, stdin_port=0, try: os.chmod(path, new_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, - ) + if e.errno == errno.EPERM and path == runtime_dir: + # suppress permission errors setting sticky bit on runtime_dir, + # which we may not own. + pass + else: + # failed to set sticky bit, probably not a big deal + warnings.warn( + "Failed to set sticky bit on %r: %s" + "\nProbably not a big deal, but runtime files may be cleaned up periodically." % (path, e), + RuntimeWarning, + ) return fname, cfg