mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-01-03 22:00:14 +01:00
tools: set the default properties in the fake portal
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
6197e5a34e
commit
1e8c184d8e
2 changed files with 51 additions and 1 deletions
|
|
@ -185,7 +185,7 @@ if get_option('portal')
|
|||
executable('eis-fake-portal',
|
||||
'tools/eis-fake-portal.c',
|
||||
include_directories: 'src',
|
||||
dependencies: [dep_libutil, dep_systemd])
|
||||
dependencies: [dep_libutil, dep_systemd, dep_libreis])
|
||||
endif
|
||||
|
||||
# tests
|
||||
|
|
|
|||
|
|
@ -24,16 +24,22 @@
|
|||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util-io.h"
|
||||
#include "util-mem.h"
|
||||
#include "util-logger.h"
|
||||
#include "util-strings.h"
|
||||
|
||||
#include "libreis.h"
|
||||
|
||||
#include <systemd/sd-bus.h>
|
||||
|
||||
DEFINE_UNREF_CLEANUP_FUNC(reis);
|
||||
|
||||
struct portal {
|
||||
struct logger *logger;
|
||||
char *busname;
|
||||
|
|
@ -133,6 +139,39 @@ portal_emulate_input(sd_bus_message *m, void *userdata,
|
|||
return create_request_object(portal, sd_bus_message_get_bus(m), objpath);
|
||||
}
|
||||
|
||||
static void
|
||||
set_prop_cmdline(struct reis *reis)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
xsnprintf(path, sizeof(path), "/proc/%u/cmdline", getpid());
|
||||
_cleanup_close_ int fd = open(path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return;
|
||||
|
||||
int len;
|
||||
if ((len = read(fd, path, sizeof(path) - 1)) < 0)
|
||||
return;
|
||||
path[len] = '\0';
|
||||
|
||||
reis_set_property_with_permissions(reis, "ei.application.cmdline", path, REIS_PROPERTY_PERM_NONE);
|
||||
}
|
||||
|
||||
static void
|
||||
set_prop_pid(struct reis *reis)
|
||||
{
|
||||
char pid[64];
|
||||
|
||||
xsnprintf(pid, sizeof(pid), "%u", getpid());
|
||||
reis_set_property_with_permissions(reis, "ei.application.pid", pid, REIS_PROPERTY_PERM_NONE);
|
||||
}
|
||||
|
||||
static void
|
||||
set_prop_type(struct reis *reis)
|
||||
{
|
||||
reis_set_property_with_permissions(reis, "ei.connection.type", "portal", REIS_PROPERTY_PERM_NONE);
|
||||
}
|
||||
|
||||
static int
|
||||
portal_connect(sd_bus_message *m, void *userdata,
|
||||
sd_bus_error *ret_error)
|
||||
|
|
@ -145,6 +184,17 @@ portal_connect(sd_bus_message *m, void *userdata,
|
|||
|
||||
_cleanup_free_ char *sockpath = xaprintf("%s/eis-0", xdg);
|
||||
int handle = xconnect(sockpath);
|
||||
if (handle < 0) {
|
||||
log_error(portal, "Failed to connect to EIS (%s)\n", strerror(-handle));
|
||||
abort();
|
||||
}
|
||||
|
||||
_unref_(reis) *reis = reis_new(handle);
|
||||
assert(reis);
|
||||
set_prop_pid(reis);
|
||||
set_prop_cmdline(reis);
|
||||
set_prop_type(reis);
|
||||
|
||||
log_debug(portal, "passing Handle %d\n", handle);
|
||||
return sd_bus_reply_method_return(m, "h", handle);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue