EAC Linux v2 on Gentoo with OpenRC: ebuilds, host config, tools, docs
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Own org.freedesktop.systemd1 and log every method call as a JSON line.
|
||||
|
||||
Each call gets an org.freedesktop.DBus.Error.NotSupported reply, so the log shows
|
||||
the first call of every attempt. Reply with real values here once the calls are known.
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
|
||||
import dbus
|
||||
import dbus.lowlevel
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
from gi.repository import GLib
|
||||
|
||||
NAME = "org.freedesktop.systemd1"
|
||||
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
bus = dbus.SessionBus() if "--session" in sys.argv[1:] else dbus.SystemBus()
|
||||
commands = {}
|
||||
|
||||
|
||||
def command(sender):
|
||||
if sender not in commands:
|
||||
try:
|
||||
pid = bus.call_blocking("org.freedesktop.DBus", "/org/freedesktop/DBus",
|
||||
"org.freedesktop.DBus", "GetConnectionUnixProcessID",
|
||||
"s", (sender,))
|
||||
with open(f"/proc/{pid}/cmdline", "rb") as f:
|
||||
commands[sender] = f"{pid} " + f.read().replace(b"\0", b" ").decode().strip()
|
||||
except (dbus.DBusException, OSError) as e:
|
||||
commands[sender] = f"? ({e})"
|
||||
return commands[sender]
|
||||
|
||||
|
||||
def on_message(conn, msg):
|
||||
if msg.get_type() != dbus.lowlevel.MESSAGE_TYPE_METHOD_CALL or msg.get_destination() != NAME:
|
||||
return dbus.lowlevel.HANDLER_RESULT_NOT_YET_HANDLED
|
||||
print(json.dumps({
|
||||
"time": time.strftime("%T"),
|
||||
"sender": msg.get_sender(),
|
||||
"command": command(msg.get_sender()),
|
||||
"path": msg.get_path(),
|
||||
"method": f"{msg.get_interface()}.{msg.get_member()}",
|
||||
"signature": msg.get_signature(),
|
||||
"args": msg.get_args_list(),
|
||||
}, default=str), flush=True)
|
||||
if not msg.get_no_reply():
|
||||
conn.send_message(dbus.lowlevel.ErrorMessage(
|
||||
msg, "org.freedesktop.DBus.Error.NotSupported", "systemd1-trace: logged only"))
|
||||
return dbus.lowlevel.HANDLER_RESULT_HANDLED
|
||||
|
||||
|
||||
bus.add_message_filter(on_message)
|
||||
if bus.request_name(NAME, dbus.bus.NAME_FLAG_DO_NOT_QUEUE) != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER:
|
||||
sys.exit(f"{NAME} is already owned")
|
||||
print(f"owning {NAME}", file=sys.stderr, flush=True)
|
||||
GLib.MainLoop().run()
|
||||
Reference in New Issue
Block a user