Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,11 @@ always available. Unless explicitly noted otherwise, all variables are read-only
interpreter is pre-release (alpha, beta, or release candidate) then the
local and remote interpreters must be the same exact version.

.. audit-event:: remove_exec pid script_path

When the code is executed in the remote process, an :ref:`auditing event <auditing>`
``remove_exec`` is raised with the *pid* and the path to the script file.

.. audit-event:: remote_debugger_script script_path

When the script is executed in the remote process, an
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2114,11 +2114,18 @@ def audit_hook(event, arg):
script = '''
print("Remote script executed successfully!")
'''
remote_exec_event_triggered = False
def audit_hook(event, arg):
if event == "remote_exec":
nonlocal remote_exec_event_triggered
remote_exec_event_triggered = True
sys.addaudithook(audit_hook)
returncode, stdout, stderr = self._run_remote_exec_test(script, prologue=prologue)
self.assertEqual(returncode, 0)
self.assertIn(b"Remote script executed successfully!", stdout)
self.assertIn(b"Audit event: remote_debugger_script, arg: ", stdout)
self.assertEqual(stderr, b"")
self.assertTrue(remote_exec_event_triggered)

def test_remote_exec_with_exception(self):
"""Test remote exec with an exception raised in the target process
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
emit ``sys.remote_exec`` audit event when ``sys.remote_exec`` has been
called
4 changes: 4 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,10 @@ sys_remote_exec_impl(PyObject *module, int pid, PyObject *script)
PyObject *path;
const char *debugger_script_path;

if (PySys_Audit("remote_exec", "iO", pid, script) < 0) {
return NULL;
}

if (PyUnicode_FSConverter(script, &path) == 0) {
return NULL;
}
Expand Down
Loading