From d9f9168c7649533d2727d246f9740481f9c63d86 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 5 Jan 2025 17:45:24 -0800 Subject: [PATCH] names: Use hostnamectl instead of socket API get the current hostname - This would mean consistent interfacing with systemd instead of a split approach. Tests: - Edit hostname page shows the current value of hostname correctly. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/names/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index 3a9883fab..5af5b947e 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -242,7 +242,9 @@ def get_domain_name(): def get_hostname(): """Return the hostname.""" - return socket.gethostname() + process = subprocess.run(['hostnamectl', 'hostname', '--static'], + stdout=subprocess.PIPE, check=True) + return process.stdout.decode().strip() def set_hostname(hostname):