summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-05-05 21:45:54 +0200
committerLennart Poettering <lennart@poettering.net>2023-05-16 12:08:41 +0200
commit7b674a9ee86dad21ba631b82c5b46938a3a587d8 (patch)
treee6f5813b9c0e9cfd720e1afe993be0c4d4ab5967 /src
parentb587194313cbad2fbd6a7e70cec860f0d0ed798c (diff)
downloadsystemd-7b674a9ee86dad21ba631b82c5b46938a3a587d8.tar.gz
pid1: debug log client comm/description strings if available for incoming connections
Very useful for debugging, to see which clients actually connect.
Diffstat (limited to 'src')
-rw-r--r--src/core/dbus.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/core/dbus.c b/src/core/dbus.c
index c41e1a6c74..7277696196 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -684,7 +684,7 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
return 0;
}
- nfd = -EBADF;
+ TAKE_FD(nfd);
r = bus_check_peercred(bus);
if (r < 0) {
@@ -703,7 +703,8 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
r = sd_bus_negotiate_creds(bus, 1,
SD_BUS_CREDS_PID|SD_BUS_CREDS_UID|
SD_BUS_CREDS_EUID|SD_BUS_CREDS_EFFECTIVE_CAPS|
- SD_BUS_CREDS_SELINUX_CONTEXT);
+ SD_BUS_CREDS_SELINUX_CONTEXT|
+ SD_BUS_CREDS_COMM|SD_BUS_CREDS_DESCRIPTION);
if (r < 0) {
log_warning_errno(r, "Failed to enable credentials for new connection: %m");
return 0;
@@ -721,6 +722,23 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
return 0;
}
+ if (DEBUG_LOGGING) {
+ _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *c = NULL;
+ const char *comm = NULL, *description = NULL;
+ pid_t pid = 0;
+
+ r = sd_bus_get_owner_creds(bus, SD_BUS_CREDS_PID|SD_BUS_CREDS_COMM|SD_BUS_CREDS_DESCRIPTION, &c);
+ if (r < 0)
+ log_warning_errno(r, "Failed to get peer creds, ignoring: %m");
+ else {
+ (void) sd_bus_creds_get_pid(c, &pid);
+ (void) sd_bus_creds_get_comm(c, &comm);
+ (void) sd_bus_creds_get_description(c, &description);
+ }
+
+ log_debug("Accepting direct incoming connection from " PID_FMT " (%s) [%s]", pid, strna(comm), strna(description));
+ }
+
r = sd_bus_attach_event(bus, m->event, SD_EVENT_PRIORITY_NORMAL);
if (r < 0) {
log_warning_errno(r, "Failed to attach new connection bus to event loop: %m");