From 6b48cd4b57211fbb75e91cb80771c6e0aa4b8e9f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 21 Oct 2019 15:05:53 +0200 Subject: Guess proper dbus socket --- src/warn.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/warn.c b/src/warn.c index c02829e..b3f6460 100644 --- a/src/warn.c +++ b/src/warn.c @@ -2,6 +2,10 @@ #include "util.h" #include #include +#include +#include +#include +#include struct action { const char *message; @@ -66,7 +70,20 @@ void warn_showCustomWarning( const struct user *usr, const char *title, const ch if ( *usr->display ) { // notify-send if ( doublefork() ) { + char buf[300]; + uid_t uid; + struct passwd *u = getpwnam( usr->user ); + struct stat tmp; + if ( u == NULL ) { + uid = geteuid(); + } else { + uid = u->pw_uid; + } switchUserSafe( usr->user ); + snprintf( buf, sizeof(buf), "unix:path=/run/user/%u/bus", (unsigned int)uid ); + if ( stat( buf + 10, &tmp ) == 0 ) { + setenv( "DBUS_SESSION_BUS_ADDRESS", buf, 1 ); + } setenv( "DISPLAY", usr->display, 1 ); if ( usr->xauth[0] != '\0' && usr->xauth[0] != '-' ) { setenv( "XAUTHORITY", usr->xauth, 1 ); -- cgit v1.2.3-55-g7522