Commit 565c832d authored by Martin Flöser's avatar Martin Flöser
Browse files

[server] Expose executable path in ClientConnection

Summary: Convenient API to get the absolute executable path for the pid.

Reviewers: sebas, mart

Subscribers: plasma-devel

Differential Revision: https://phabricator.kde.org/D858
parent f51038c2
########################################################
# Test WaylandServerDisplay
########################################################
add_definitions(-DAUTOTEST_CURRENT_BIN_DIR="${CMAKE_CURRENT_BINARY_DIR}")
set( testWaylandServerDisplay_SRCS
test_display.cpp
)
......
......@@ -137,6 +137,7 @@ void TestWaylandServerDisplay::testClientConnection()
QVERIFY(connection->groupId() != 0);
QVERIFY(connection->processId() != 0);
QCOMPARE(connection->display(), &display);
QCOMPARE(connection->executablePath(), QStringLiteral("%1/testWaylandServerDisplay").arg(AUTOTEST_CURRENT_BIN_DIR));
QCOMPARE((wl_client*)*connection, client);
const ClientConnection &constRef = *connection;
QCOMPARE((wl_client*)constRef, client);
......
......@@ -20,6 +20,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include "clientconnection.h"
#include "display.h"
// Qt
#include <QFileInfo>
#include <QVector>
// Wayland
#include <wayland-server.h>
......@@ -40,6 +41,7 @@ public:
pid_t pid = 0;
uid_t user = 0;
gid_t group = 0;
QString executablePath;
private:
static void destroyListenerCallback(wl_listener *listener, void *data);
......@@ -59,6 +61,7 @@ ClientConnection::Private::Private(wl_client *c, Display *display, ClientConnect
listener.notify = destroyListenerCallback;
wl_client_add_destroy_listener(c, &listener);
wl_client_get_credentials(client, &pid, &user, &group);
executablePath = QFileInfo(QStringLiteral("/proc/%1/exe").arg(pid)).symLinkTarget();
}
ClientConnection::Private::~Private()
......@@ -145,5 +148,10 @@ uid_t ClientConnection::userId() const
return d->user;
}
QString ClientConnection::executablePath() const
{
return d->executablePath;
}
}
}
......@@ -108,6 +108,19 @@ public:
**/
gid_t groupId() const;
/**
* The absolute path to the executable.
*
* Please note: if the ClientConnection got created with @link Display::createClient @endlink
* the executablePath will be identical to the process running the KWayland::Server::Display.
*
* If the executable path cannot be resolved an empty QString is returned.
*
* @see processId
* @since 5.6
**/
QString executablePath() const;
/**
* Cast operator the native wl_client this ClientConnection represents.
**/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment