Skip to content

Commit 60725af

Browse files
committed
fix review idea
Signed-off-by: Manjusaka <me@manjusaka.me>
1 parent 8682689 commit 60725af

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

Doc/library/sys.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,15 +1935,19 @@ always available. Unless explicitly noted otherwise, all variables are read-only
19351935

19361936
.. audit-event:: sys.remote_exec pid script_path
19371937

1938-
When the code is executed in the remote process, an :ref:`auditing event <auditing>`
1939-
``sys.remote_exec`` is raised with the *pid* and the path to the script file.
1938+
When the code is executed in the remote process, an
1939+
:ref:`auditing event <auditing>` ``sys.remote_exec`` is raised with
1940+
the *pid* and the path to the script file.
1941+
This event is raised in the process that called :func:`sys.remote_exec`.
19401942

19411943
.. audit-event:: cpython.remote_debugger_script script_path
19421944

19431945
When the script is executed in the remote process, an
19441946
:ref:`auditing event <auditing>`
19451947
``cpython.remote_debugger_script`` is raised
19461948
with the path in the remote process.
1949+
This event is raised in the remote process, not the one
1950+
that called :func:`sys.remote_exec`.
19471951

19481952
.. availability:: Unix, Windows.
19491953
.. versionadded:: 3.14

Lib/test/audit-tests.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,20 +649,28 @@ def test_sys_remote_exec():
649649
pid = os.getpid()
650650
event_pid = -1
651651
event_script_path = ""
652+
remote_event_script_path = ""
652653
def hook(event, args):
653-
if event != "sys.remote_exec": return
654-
nonlocal event_pid
655-
event_pid = args[0]
656-
nonlocal event_script_path
657-
event_script_path = args[1]
654+
if event not in ["sys.remote_exec", "cpython.remote_debugger_script"]:
655+
return
656+
print(event, args)
657+
match event:
658+
case "sys.remote_exec":
659+
nonlocal event_pid, event_script_path
660+
event_pid = args[0]
661+
event_script_path = args[1]
662+
case "cpython.remote_debugger_script":
663+
nonlocal remote_event_script_path
664+
remote_event_script_path = args[0]
658665

659666
sys.addaudithook(hook)
660667
with tempfile.NamedTemporaryFile(mode='w+', delete=True) as tmp_file:
661-
tmp_file.write("print('Hello from remote_exec!')\n")
668+
tmp_file.write("a = 1+1\n")
662669
tmp_file.flush()
663670
sys.remote_exec(pid, tmp_file.name)
664671
assertEqual(event_pid, pid)
665672
assertEqual(event_script_path, tmp_file.name)
673+
assertEqual(remote_event_script_path, tmp_file.name)
666674

667675
if __name__ == "__main__":
668676
from test.support import suppress_msvcrt_asserts

Lib/test/test_audit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ def test_assert_unicode(self):
325325
@support.support_remote_exec_only
326326
@support.cpython_only
327327
def test_sys_remote_exec(self):
328-
returncode, stdout, stderr = self.run_python("test_sys_remote_exec")
328+
returncode, events, stderr = self.run_python("test_sys_remote_exec")
329+
self.assertTrue(any(["sys.remote_exec" in event for event in events]))
330+
self.assertTrue(any(["cpython.remote_debugger_script" in event for event in events]))
329331
if returncode:
330332
self.fail(stderr)
331333

0 commit comments

Comments
 (0)