aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Limonciello (AMD) <superm1@kernel.org>2026-01-15 23:27:45 -0600
committerMario Limonciello <superm1@kernel.org>2026-01-15 23:30:36 -0600
commit9df36c9a14fe33e5b51daddf2f995a965958ad5a (patch)
treece0210df759b3ca6eff7eaec4c2969913cc59545
parentc2da77bb849005760045d7106249b04499cbef95 (diff)
downloadamd-debug-tools-master.tar.gz
Switch to systemd-run instead of sudo for showing reportHEAD0.2.12master
This is compatible with sudo-rs as well. Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
-rw-r--r--src/amd_debug/s2idle.py20
-rw-r--r--src/test_s2idle.py12
2 files changed, 20 insertions, 12 deletions
diff --git a/src/amd_debug/s2idle.py b/src/amd_debug/s2idle.py
index 36d6759..8a3f0f2 100644
--- a/src/amd_debug/s2idle.py
+++ b/src/amd_debug/s2idle.py
@@ -10,6 +10,7 @@ from datetime import date, timedelta, datetime
from amd_debug.common import (
convert_string_to_bool,
colorize_choices,
+ fatal_error,
is_root,
relaunch_sudo,
show_log_info,
@@ -60,15 +61,16 @@ def display_report_file(fname, fmt) -> None:
return
user = os.environ.get("SUDO_USER")
if user:
- # ensure that xdg tools will know how to display the file
- # (user may need to call tool with sudo -E)
- if os.environ.get("XDG_SESSION_TYPE"):
- subprocess.call(["sudo", "-E", "-u", user, "xdg-open", fname])
- else:
- print(
- "To display report automatically in browser launch tool "
- f"with '-E' argument (Example: sudo -E {sys.argv[0]})"
- )
+ cmd = [
+ "systemd-run",
+ "--user",
+ f"--machine={user}@.host",
+ "xdg-open",
+ os.path.abspath(fname),
+ ]
+ ret = subprocess.call(cmd)
+ if ret:
+ fatal_error(f"Failed to open report: {ret}")
def get_report_file(report_file, extension) -> str:
diff --git a/src/test_s2idle.py b/src/test_s2idle.py
index 995a714..0c806fc 100644
--- a/src/test_s2idle.py
+++ b/src/test_s2idle.py
@@ -611,12 +611,18 @@ class TestDisplayReportFile(unittest.TestCase):
self, mock_subprocess_call, mock_env_get, mock_is_root
):
"""Test display_report_file when format is html, user is root, and SUDO_USER is set"""
- display_report_file("report.html", "html")
+ with self.assertRaises(SystemExit):
+ display_report_file("/tmp/report.html", "html")
mock_is_root.assert_called_once()
mock_env_get.assert_any_call("SUDO_USER")
- mock_env_get.assert_any_call("XDG_SESSION_TYPE")
mock_subprocess_call.assert_called_once_with(
- ["sudo", "-E", "-u", "testuser", "xdg-open", "report.html"]
+ [
+ "systemd-run",
+ "--user",
+ "--machine=testuser@.host",
+ "xdg-open",
+ "/tmp/report.html",
+ ]
)
@patch("amd_debug.s2idle.is_root", return_value=True)