Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions Lib/test/test_syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ def test_openlog_noargs(self):
syslog.openlog()
syslog.syslog('test message from python test_syslog')

@threading_helper.requires_working_threading()
def test_racing_openlog_argv(self):
# gh-159864: openlog() without an ident reads sys.argv[0] while
# another thread replaces it.
argv = ["prog"]
nthreads = 32

def opener():
for _ in range(1000):
syslog.openlog()

def writer():
for i in range(1000):
argv[0] = f"prog-{i}"

with support.swap_attr(sys, "argv", argv):
try:
threading_helper.run_concurrently(
worker_func=[opener] * (nthreads - 1) + [writer],
)
finally:
syslog.closelog()

@threading_helper.requires_working_threading()
def test_syslog_threaded(self):
start = threading.Event()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in :func:`syslog.openlog` under the free-threaded build when
:data:`sys.argv` is modified concurrently.
3 changes: 1 addition & 2 deletions Modules/syslogmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ syslog_get_argv(void)
return NULL;
}

scriptobj = PyList_GetItem(argv, 0);
Py_XINCREF(scriptobj);
scriptobj = PyList_GetItemRef(argv, 0);
Py_DECREF(argv);
if (scriptobj == NULL) {
PyErr_Clear();
Expand Down
Loading