2013-08-19 08:57:16 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2014-04-22 17:06:36 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/native/meta-launcher.h"
|
2013-08-19 08:57:16 -04:00
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
#include <gio/gunixfdlist.h>
|
2013-08-19 08:57:16 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2013-12-31 17:44:45 -05:00
|
|
|
#include <malloc.h>
|
2013-08-19 08:57:16 -04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
2014-04-22 17:06:36 -04:00
|
|
|
#include <string.h>
|
2013-12-31 17:44:45 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <systemd/sd-login.h>
|
2015-08-31 12:03:53 -04:00
|
|
|
#include <gudev/gudev.h>
|
2013-12-31 17:44:45 -05:00
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
#include "backends/meta-backend-private.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/native/dbus-utils.h"
|
2017-03-10 00:55:33 -05:00
|
|
|
#include "backends/native/meta-backend-native.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/native/meta-cursor-renderer-native.h"
|
|
|
|
#include "backends/native/meta-renderer-native.h"
|
|
|
|
#include "clutter/clutter.h"
|
|
|
|
#include "clutter/evdev/clutter-evdev.h"
|
|
|
|
|
|
|
|
#include "meta-dbus-login1.h"
|
2013-08-19 08:57:16 -04:00
|
|
|
|
|
|
|
struct _MetaLauncher
|
|
|
|
{
|
2013-12-31 17:44:45 -05:00
|
|
|
Login1Session *session_proxy;
|
|
|
|
Login1Seat *seat_proxy;
|
2017-07-06 04:00:56 -04:00
|
|
|
char *seat_id;
|
2013-08-19 08:57:16 -04:00
|
|
|
|
2017-02-10 18:00:59 -05:00
|
|
|
GHashTable *sysfs_fds;
|
2013-12-31 17:44:45 -05:00
|
|
|
gboolean session_active;
|
2013-08-19 08:57:16 -04:00
|
|
|
};
|
|
|
|
|
2017-07-06 04:00:56 -04:00
|
|
|
const char *
|
|
|
|
meta_launcher_get_seat_id (MetaLauncher *launcher)
|
|
|
|
{
|
|
|
|
return launcher->seat_id;
|
|
|
|
}
|
|
|
|
|
2018-06-12 10:45:35 -04:00
|
|
|
static gboolean
|
|
|
|
find_systemd_session (gchar **session_id,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
const gchar * const graphical_session_types[] = { "wayland", "x11", "mir", NULL };
|
|
|
|
const gchar * const active_states[] = { "active", "online", NULL };
|
|
|
|
g_autofree gchar *class = NULL;
|
|
|
|
g_autofree gchar *local_session_id = NULL;
|
|
|
|
g_autofree gchar *type = NULL;
|
|
|
|
g_autofree gchar *state = NULL;
|
|
|
|
g_auto (GStrv) sessions = NULL;
|
|
|
|
int n_sessions;
|
|
|
|
int saved_errno;
|
|
|
|
|
|
|
|
g_assert (session_id != NULL);
|
|
|
|
g_assert (error == NULL || *error == NULL);
|
|
|
|
|
2018-07-09 05:20:47 -04:00
|
|
|
/* if we are in a logind session, we can trust that value, so use it. This
|
|
|
|
* happens for example when you run mutter directly from a VT but when
|
|
|
|
* systemd starts us we will not be in a logind session. */
|
|
|
|
saved_errno = sd_pid_get_session (0, &local_session_id);
|
|
|
|
if (saved_errno < 0)
|
|
|
|
{
|
|
|
|
if (saved_errno != -ENODATA)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Failed to get session by pid for user %d (%s)",
|
|
|
|
getuid (),
|
|
|
|
g_strerror (-saved_errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*session_id = g_steal_pointer (&local_session_id);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-06-12 10:45:35 -04:00
|
|
|
saved_errno = sd_uid_get_display (getuid (), &local_session_id);
|
|
|
|
if (saved_errno < 0)
|
|
|
|
{
|
|
|
|
/* no session, maybe there's a greeter session */
|
|
|
|
if (saved_errno == -ENODATA)
|
|
|
|
{
|
|
|
|
n_sessions = sd_uid_get_sessions (getuid (), 1, &sessions);
|
|
|
|
if (n_sessions < 0)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Failed to get all sessions for user %d (%m)",
|
|
|
|
getuid ());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_sessions == 0)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"User %d has no sessions",
|
|
|
|
getuid ());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < n_sessions; ++i)
|
|
|
|
{
|
|
|
|
saved_errno = sd_session_get_class (sessions[i], &class);
|
|
|
|
if (saved_errno < 0)
|
|
|
|
{
|
|
|
|
g_warning ("Couldn't get class for session '%d': %s",
|
|
|
|
i,
|
|
|
|
g_strerror (-saved_errno));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0 (class, "greeter") == 0)
|
|
|
|
{
|
|
|
|
local_session_id = g_strdup (sessions[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!local_session_id)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Couldn't find a session or a greeter session for user %d",
|
|
|
|
getuid ());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Couldn't get display for user %d: %s",
|
|
|
|
getuid (),
|
|
|
|
g_strerror (-saved_errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sd_uid_get_display will return any session if there is no graphical
|
|
|
|
* one, so let's check it really is graphical. */
|
|
|
|
saved_errno = sd_session_get_type (local_session_id, &type);
|
|
|
|
if (saved_errno < 0)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Couldn't get type for session '%s': %s",
|
|
|
|
local_session_id,
|
|
|
|
g_strerror (-saved_errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_strv_contains (graphical_session_types, type))
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Session '%s' is not a graphical session (type: '%s')",
|
|
|
|
local_session_id,
|
|
|
|
type);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and display sessions can be 'closing' if they are logged out but
|
|
|
|
* some processes are lingering; we shouldn't consider these */
|
|
|
|
saved_errno = sd_session_get_state (local_session_id, &state);
|
|
|
|
if (saved_errno < 0)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Couldn't get state for session '%s': %s",
|
|
|
|
local_session_id,
|
|
|
|
g_strerror (-saved_errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_strv_contains (active_states, state))
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Session '%s' is not active",
|
|
|
|
local_session_id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*session_id = g_steal_pointer (&local_session_id);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
static Login1Session *
|
2015-10-28 10:45:20 -04:00
|
|
|
get_session_proxy (GCancellable *cancellable,
|
|
|
|
GError **error)
|
2013-08-19 08:57:16 -04:00
|
|
|
{
|
2016-01-21 10:58:57 -05:00
|
|
|
g_autofree char *proxy_path = NULL;
|
|
|
|
g_autofree char *session_id = NULL;
|
2018-06-12 10:45:35 -04:00
|
|
|
g_autoptr (GError) local_error = NULL;
|
2013-12-31 17:44:45 -05:00
|
|
|
Login1Session *session_proxy;
|
2015-09-03 10:03:41 -04:00
|
|
|
|
2018-06-12 10:45:35 -04:00
|
|
|
if (!find_systemd_session (&session_id, &local_error))
|
2015-10-28 10:45:20 -04:00
|
|
|
{
|
2019-02-12 03:34:06 -05:00
|
|
|
g_propagate_prefixed_error (error,
|
|
|
|
g_steal_pointer (&local_error),
|
|
|
|
"Could not get session ID: ");
|
2015-10-28 10:45:20 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-16 23:40:59 -04:00
|
|
|
|
|
|
|
proxy_path = get_escaped_dbus_path ("/org/freedesktop/login1/session", session_id);
|
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
session_proxy = login1_session_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
|
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
|
|
|
"org.freedesktop.login1",
|
2015-09-16 23:40:59 -04:00
|
|
|
proxy_path,
|
2015-10-28 10:45:20 -04:00
|
|
|
cancellable, error);
|
2015-09-03 10:03:41 -04:00
|
|
|
if (!session_proxy)
|
2015-10-28 10:45:20 -04:00
|
|
|
g_prefix_error(error, "Could not get session proxy: ");
|
2015-09-03 10:03:41 -04:00
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
return session_proxy;
|
2013-08-19 08:57:16 -04:00
|
|
|
}
|
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
static Login1Seat *
|
2019-05-10 13:29:47 -04:00
|
|
|
get_seat_proxy (gchar *seat_id,
|
|
|
|
GCancellable *cancellable,
|
2015-10-28 10:45:20 -04:00
|
|
|
GError **error)
|
2013-08-19 08:57:16 -04:00
|
|
|
{
|
2019-05-10 13:29:47 -04:00
|
|
|
g_autofree char *seat_proxy_path = get_escaped_dbus_path ("/org/freedesktop/login1/seat", seat_id);
|
2015-09-03 10:03:41 -04:00
|
|
|
Login1Seat *seat = login1_seat_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
|
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
|
|
|
"org.freedesktop.login1",
|
2019-05-10 13:29:47 -04:00
|
|
|
seat_proxy_path,
|
2015-10-28 10:45:20 -04:00
|
|
|
cancellable, error);
|
2015-09-03 10:03:41 -04:00
|
|
|
if (!seat)
|
2015-10-28 10:45:20 -04:00
|
|
|
g_prefix_error(error, "Could not get seat proxy: ");
|
2015-09-03 10:03:41 -04:00
|
|
|
|
|
|
|
return seat;
|
2013-08-19 08:57:16 -04:00
|
|
|
}
|
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
static gboolean
|
|
|
|
take_device (Login1Session *session_proxy,
|
|
|
|
int dev_major,
|
|
|
|
int dev_minor,
|
|
|
|
int *out_fd,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
2015-05-29 20:17:34 -04:00
|
|
|
g_autoptr (GVariant) fd_variant = NULL;
|
|
|
|
g_autoptr (GUnixFDList) fd_list = NULL;
|
2013-12-31 17:44:45 -05:00
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
if (!login1_session_call_take_device_sync (session_proxy,
|
|
|
|
dev_major,
|
|
|
|
dev_minor,
|
|
|
|
NULL,
|
|
|
|
&fd_variant,
|
|
|
|
NULL, /* paused */
|
|
|
|
&fd_list,
|
|
|
|
cancellable,
|
|
|
|
error))
|
2015-05-29 20:17:34 -04:00
|
|
|
return FALSE;
|
2013-12-31 17:44:45 -05:00
|
|
|
|
|
|
|
fd = g_unix_fd_list_get (fd_list, g_variant_get_handle (fd_variant), error);
|
|
|
|
if (fd == -1)
|
2015-05-29 20:17:34 -04:00
|
|
|
return FALSE;
|
2013-12-31 17:44:45 -05:00
|
|
|
|
|
|
|
*out_fd = fd;
|
2015-05-29 20:17:34 -04:00
|
|
|
return TRUE;
|
2013-12-31 17:44:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
get_device_info_from_path (const char *path,
|
|
|
|
int *out_major,
|
|
|
|
int *out_minor)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
r = stat (path, &st);
|
2015-05-29 20:17:34 -04:00
|
|
|
if (r < 0 || !S_ISCHR (st.st_mode))
|
|
|
|
return FALSE;
|
2013-12-31 17:44:45 -05:00
|
|
|
|
|
|
|
*out_major = major (st.st_rdev);
|
|
|
|
*out_minor = minor (st.st_rdev);
|
2015-05-29 20:17:34 -04:00
|
|
|
return TRUE;
|
2013-12-31 17:44:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
get_device_info_from_fd (int fd,
|
|
|
|
int *out_major,
|
|
|
|
int *out_minor)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
r = fstat (fd, &st);
|
2015-05-29 20:17:34 -04:00
|
|
|
if (r < 0 || !S_ISCHR (st.st_mode))
|
|
|
|
return FALSE;
|
2013-12-31 17:44:45 -05:00
|
|
|
|
|
|
|
*out_major = major (st.st_rdev);
|
|
|
|
*out_minor = minor (st.st_rdev);
|
2015-05-29 20:17:34 -04:00
|
|
|
return TRUE;
|
2013-12-31 17:44:45 -05:00
|
|
|
}
|
|
|
|
|
2017-07-06 04:00:56 -04:00
|
|
|
int
|
|
|
|
meta_launcher_open_restricted (MetaLauncher *launcher,
|
|
|
|
const char *path,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int major, minor;
|
|
|
|
|
|
|
|
if (!get_device_info_from_path (path, &major, &minor))
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Could not get device info for path %s: %m", path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!take_device (launcher->session_proxy, major, minor, &fd, NULL, error))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_launcher_close_restricted (MetaLauncher *launcher,
|
|
|
|
int fd)
|
|
|
|
{
|
|
|
|
int major, minor;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (!get_device_info_from_fd (fd, &major, &minor))
|
|
|
|
{
|
|
|
|
g_warning ("Could not get device info for fd %d: %m", fd);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!login1_session_call_release_device_sync (launcher->session_proxy,
|
|
|
|
major, minor,
|
|
|
|
NULL, &error))
|
|
|
|
{
|
|
|
|
g_warning ("Could not release device (%d,%d): %s",
|
|
|
|
major, minor, error->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
close (fd);
|
|
|
|
}
|
|
|
|
|
2013-08-19 08:57:16 -04:00
|
|
|
static int
|
|
|
|
on_evdev_device_open (const char *path,
|
2014-04-22 17:13:04 -04:00
|
|
|
int flags,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2013-08-19 08:57:16 -04:00
|
|
|
{
|
2013-12-31 17:44:45 -05:00
|
|
|
MetaLauncher *self = user_data;
|
|
|
|
|
2017-02-10 18:00:59 -05:00
|
|
|
/* Allow readonly access to sysfs */
|
|
|
|
if (g_str_has_prefix (path, "/sys/"))
|
|
|
|
{
|
2017-07-06 04:00:56 -04:00
|
|
|
int fd;
|
|
|
|
|
2017-07-12 16:36:42 -04:00
|
|
|
do
|
|
|
|
{
|
|
|
|
fd = open (path, flags);
|
|
|
|
}
|
|
|
|
while (fd < 0 && errno == EINTR);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_FILE_ERROR,
|
|
|
|
g_file_error_from_errno (errno),
|
|
|
|
"Could not open /sys file: %s: %m", path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_add (self->sysfs_fds, GINT_TO_POINTER (fd));
|
2017-02-10 18:00:59 -05:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2017-07-06 04:00:56 -04:00
|
|
|
return meta_launcher_open_restricted (self, path, error);
|
2013-08-19 08:57:16 -04:00
|
|
|
}
|
|
|
|
|
2014-03-11 17:18:47 -04:00
|
|
|
static void
|
2014-04-22 17:13:04 -04:00
|
|
|
on_evdev_device_close (int fd,
|
|
|
|
gpointer user_data)
|
2014-03-11 17:18:47 -04:00
|
|
|
{
|
2013-12-31 17:44:45 -05:00
|
|
|
MetaLauncher *self = user_data;
|
|
|
|
|
2017-02-10 18:00:59 -05:00
|
|
|
if (g_hash_table_lookup (self->sysfs_fds, GINT_TO_POINTER (fd)))
|
|
|
|
{
|
|
|
|
/* /sys/ paths just need close() here */
|
|
|
|
g_hash_table_remove (self->sysfs_fds, GINT_TO_POINTER (fd));
|
|
|
|
close (fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-06 04:00:56 -04:00
|
|
|
meta_launcher_close_restricted (self, fd);
|
2014-03-11 17:18:47 -04:00
|
|
|
}
|
|
|
|
|
2013-08-19 08:57:16 -04:00
|
|
|
static void
|
2013-12-31 17:44:45 -05:00
|
|
|
sync_active (MetaLauncher *self)
|
2013-08-19 08:57:16 -04:00
|
|
|
{
|
2017-03-10 00:55:33 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
|
2013-12-31 17:44:45 -05:00
|
|
|
gboolean active = login1_session_get_active (LOGIN1_SESSION (self->session_proxy));
|
|
|
|
|
|
|
|
if (active == self->session_active)
|
|
|
|
return;
|
2014-04-22 17:21:12 -04:00
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
self->session_active = active;
|
|
|
|
|
|
|
|
if (active)
|
2017-03-10 00:55:33 -05:00
|
|
|
meta_backend_native_resume (backend_native);
|
2013-12-31 17:44:45 -05:00
|
|
|
else
|
2017-03-10 00:55:33 -05:00
|
|
|
meta_backend_native_pause (backend_native);
|
2013-08-19 08:57:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-12-31 17:44:45 -05:00
|
|
|
on_active_changed (Login1Session *session,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
2013-08-19 08:57:16 -04:00
|
|
|
{
|
2013-12-31 17:44:45 -05:00
|
|
|
MetaLauncher *self = user_data;
|
|
|
|
sync_active (self);
|
2013-08-19 08:57:16 -04:00
|
|
|
}
|
|
|
|
|
2015-08-31 12:03:53 -04:00
|
|
|
static gchar *
|
2015-10-28 10:45:20 -04:00
|
|
|
get_seat_id (GError **error)
|
2015-08-31 12:03:53 -04:00
|
|
|
{
|
2018-06-12 10:45:35 -04:00
|
|
|
g_autoptr (GError) local_error = NULL;
|
2016-01-21 10:58:57 -05:00
|
|
|
g_autofree char *session_id = NULL;
|
|
|
|
char *seat_id = NULL;
|
2015-10-28 10:45:20 -04:00
|
|
|
int r;
|
2015-08-31 12:03:53 -04:00
|
|
|
|
2018-06-12 10:45:35 -04:00
|
|
|
if (!find_systemd_session (&session_id, &local_error))
|
2015-10-28 10:45:20 -04:00
|
|
|
{
|
2019-02-12 03:34:06 -05:00
|
|
|
g_propagate_prefixed_error (error,
|
|
|
|
g_steal_pointer (&local_error),
|
|
|
|
"Could not get session ID: ");
|
2015-10-28 10:45:20 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-31 12:03:53 -04:00
|
|
|
|
2015-10-28 10:45:20 -04:00
|
|
|
r = sd_session_get_seat (session_id, &seat_id);
|
|
|
|
if (r < 0)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
|
|
|
"Could not get seat for session: %s", g_strerror (-r));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-31 12:03:53 -04:00
|
|
|
return seat_id;
|
|
|
|
}
|
|
|
|
|
2013-12-31 18:03:31 -05:00
|
|
|
MetaLauncher *
|
2015-10-28 10:45:20 -04:00
|
|
|
meta_launcher_new (GError **error)
|
2013-08-19 08:57:16 -04:00
|
|
|
{
|
2015-02-26 03:13:16 -05:00
|
|
|
MetaLauncher *self = NULL;
|
2016-01-21 10:58:57 -05:00
|
|
|
g_autoptr (Login1Session) session_proxy = NULL;
|
|
|
|
g_autoptr (Login1Seat) seat_proxy = NULL;
|
|
|
|
g_autofree char *seat_id = NULL;
|
2015-10-28 10:45:20 -04:00
|
|
|
gboolean have_control = FALSE;
|
2013-08-19 08:57:16 -04:00
|
|
|
|
2015-10-28 10:45:20 -04:00
|
|
|
session_proxy = get_session_proxy (NULL, error);
|
|
|
|
if (!session_proxy)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!login1_session_call_take_control_sync (session_proxy, FALSE, NULL, error))
|
|
|
|
{
|
|
|
|
g_prefix_error (error, "Could not take control: ");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
have_control = TRUE;
|
2013-08-19 08:57:16 -04:00
|
|
|
|
2015-10-28 10:45:20 -04:00
|
|
|
seat_id = get_seat_id (error);
|
2015-08-31 12:03:53 -04:00
|
|
|
if (!seat_id)
|
2015-10-28 10:45:20 -04:00
|
|
|
goto fail;
|
|
|
|
|
2019-05-10 13:29:47 -04:00
|
|
|
seat_proxy = get_seat_proxy (seat_id, NULL, error);
|
2015-10-28 10:45:20 -04:00
|
|
|
if (!seat_proxy)
|
|
|
|
goto fail;
|
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
self = g_slice_new0 (MetaLauncher);
|
2016-01-21 10:58:57 -05:00
|
|
|
self->session_proxy = g_object_ref (session_proxy);
|
|
|
|
self->seat_proxy = g_object_ref (seat_proxy);
|
2017-07-06 04:00:56 -04:00
|
|
|
self->seat_id = g_steal_pointer (&seat_id);
|
2017-02-10 18:00:59 -05:00
|
|
|
self->sysfs_fds = g_hash_table_new (NULL, NULL);
|
2013-12-31 17:44:45 -05:00
|
|
|
self->session_active = TRUE;
|
2014-04-22 17:15:31 -04:00
|
|
|
|
2017-07-06 04:00:56 -04:00
|
|
|
clutter_evdev_set_seat_id (self->seat_id);
|
2017-02-02 13:01:25 -05:00
|
|
|
|
2014-03-11 17:18:47 -04:00
|
|
|
clutter_evdev_set_device_callbacks (on_evdev_device_open,
|
|
|
|
on_evdev_device_close,
|
|
|
|
self);
|
2014-03-11 16:48:52 -04:00
|
|
|
|
2013-12-31 17:44:45 -05:00
|
|
|
g_signal_connect (self->session_proxy, "notify::active", G_CALLBACK (on_active_changed), self);
|
2017-07-06 04:00:56 -04:00
|
|
|
|
2013-12-31 18:03:31 -05:00
|
|
|
return self;
|
2015-10-28 10:45:20 -04:00
|
|
|
|
|
|
|
fail:
|
|
|
|
if (have_control)
|
|
|
|
login1_session_call_release_control_sync (session_proxy, NULL, NULL);
|
|
|
|
return NULL;
|
2013-08-19 08:57:16 -04:00
|
|
|
}
|
|
|
|
|
2013-12-31 18:03:31 -05:00
|
|
|
void
|
2013-12-31 17:44:45 -05:00
|
|
|
meta_launcher_free (MetaLauncher *self)
|
2013-08-19 08:57:16 -04:00
|
|
|
{
|
2017-07-06 04:00:56 -04:00
|
|
|
g_free (self->seat_id);
|
2013-12-31 17:44:45 -05:00
|
|
|
g_object_unref (self->seat_proxy);
|
|
|
|
g_object_unref (self->session_proxy);
|
2017-02-10 18:00:59 -05:00
|
|
|
g_hash_table_destroy (self->sysfs_fds);
|
2013-12-31 17:44:45 -05:00
|
|
|
g_slice_free (MetaLauncher, self);
|
2013-08-19 08:57:16 -04:00
|
|
|
}
|
2014-01-16 13:40:41 -05:00
|
|
|
|
2014-04-22 17:08:57 -04:00
|
|
|
gboolean
|
|
|
|
meta_launcher_activate_session (MetaLauncher *launcher,
|
|
|
|
GError **error)
|
|
|
|
{
|
2013-12-31 17:44:45 -05:00
|
|
|
if (!login1_session_call_activate_sync (launcher->session_proxy, NULL, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
sync_active (launcher);
|
|
|
|
return TRUE;
|
2014-04-22 17:08:57 -04:00
|
|
|
}
|
|
|
|
|
2014-01-16 13:40:41 -05:00
|
|
|
gboolean
|
|
|
|
meta_launcher_activate_vt (MetaLauncher *launcher,
|
2014-04-22 17:13:04 -04:00
|
|
|
signed char vt,
|
|
|
|
GError **error)
|
2014-01-16 13:40:41 -05:00
|
|
|
{
|
2013-12-31 17:44:45 -05:00
|
|
|
return login1_seat_call_switch_to_sync (launcher->seat_proxy, vt, NULL, error);
|
2014-01-16 13:40:41 -05:00
|
|
|
}
|