diff --git a/src/cockpit/channels/dbus.py b/src/cockpit/channels/dbus.py index 664f181b3c3b..779a5216083a 100644 --- a/src/cockpit/channels/dbus.py +++ b/src/cockpit/channels/dbus.py @@ -45,6 +45,7 @@ from cockpit._vendor.systemd_ctypes import Bus, BusError, introspection from ..channel import Channel, ChannelError +from ..config import IS_LITTLE_ENDIAN_MACHINE logger = logging.getLogger(__name__) @@ -174,6 +175,7 @@ class DBusChannel(Channel): name = None bus = None owner = None + endianness = "<" if IS_LITTLE_ENDIAN_MACHINE else ">" async def setup_name_owner_tracking(self): def send_owner(owner): @@ -346,10 +348,9 @@ async def do_call(self, message): # If the method call has kicked off any signals related to # watch processing, wait for that to be done. async with self.watch_processing_lock: - # TODO: stop hard-coding the endian flag here. self.send_json( reply=[reply.get_body()], id=cookie, - flags="<" if flags is not None else None, + flags=self.endianness if flags is not None else None, type=reply.get_signature(True)) # noqa: FBT003 except BusError as error: # actually, should send the fields from the message body diff --git a/src/cockpit/config.py b/src/cockpit/config.py index 04d017e37e83..2647eaeceef8 100644 --- a/src/cockpit/config.py +++ b/src/cockpit/config.py @@ -18,6 +18,7 @@ import configparser import logging import os +import sys from pathlib import Path from cockpit._vendor.systemd_ctypes import bus @@ -27,6 +28,7 @@ XDG_CONFIG_HOME = Path(os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config')) DOT_CONFIG_COCKPIT = XDG_CONFIG_HOME / 'cockpit' +IS_LITTLE_ENDIAN_MACHINE = sys.byteorder == 'little' def lookup_config(filename: str) -> Path: config_dirs = os.environ.get('XDG_CONFIG_DIRS', '/etc').split(':')