logind-session-device.c revision b4bbcaa9c44260e88402cb8f9a5fb8ac7f35e123
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 David Herrmann
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <string.h>
#include "libudev.h"
#include "alloc-util.h"
#include "bus-util.h"
#include "fd-util.h"
#include "logind-session-device.h"
#include "missing.h"
#include "util.h"
enum SessionDeviceNotifications {
};
const char *t = NULL;
int r;
return 0;
if (!path)
return -ENOMEM;
&m, path,
"org.freedesktop.login1.Session",
if (!m)
return r;
if (r < 0)
return r;
switch (type) {
case SESSION_DEVICE_RESUME:
if (r < 0)
return r;
break;
case SESSION_DEVICE_TRY_PAUSE:
t = "pause";
break;
case SESSION_DEVICE_PAUSE:
t = "force";
break;
case SESSION_DEVICE_RELEASE:
t = "gone";
break;
default:
return -EINVAL;
}
if (t) {
if (r < 0)
return r;
}
}
static int sd_eviocrevoke(int fd) {
static bool warned;
int r;
if (r < 0) {
r = -errno;
warned = true;
log_warning("kernel does not support evdev-revocation");
}
}
return 0;
}
static int sd_drmsetmaster(int fd) {
int r;
if (r < 0)
return -errno;
return 0;
}
static int sd_drmdropmaster(int fd) {
int r;
if (r < 0)
return -errno;
return 0;
}
int fd, r;
/* open device and try to get an udev_device from it */
if (fd < 0)
return -errno;
case DEVICE_TYPE_DRM:
if (active) {
/* Weird legacy DRM semantics might return an error
* even though we're master. No way to detect that so
* fail at all times and let caller retry in inactive
* state. */
r = sd_drmsetmaster(fd);
if (r < 0) {
return r;
}
} else {
/* DRM-Master is granted to the first user who opens a
* device automatically (ughh, racy!). Hence, we just
* drop DRM-Master in case we were the first. */
}
break;
case DEVICE_TYPE_EVDEV:
if (!active)
break;
case DEVICE_TYPE_UNKNOWN:
default:
/* fallback for devices wihout synchronizations */
break;
}
return fd;
}
int r;
return 0;
case DEVICE_TYPE_DRM:
/* Device is kept open. Simply call drmSetMaster() and hope
* there is no-one else. In case it fails, we keep the device
* paused. Maybe at some point we have a drmStealMaster(). */
if (r < 0)
return r;
break;
case DEVICE_TYPE_EVDEV:
/* Evdev devices are revoked while inactive. Reopen it and we
* are fine. */
r = session_device_open(sd, true);
if (r < 0)
return r;
break;
case DEVICE_TYPE_UNKNOWN:
default:
/* fallback for devices wihout synchronizations */
break;
}
return 0;
}
return;
case DEVICE_TYPE_DRM:
/* On DRM devices we simply drop DRM-Master but keep it open.
* This allows the user to keep resources allocated. The
* CAP_SYS_ADMIN restriction to DRM-Master prevents users from
* circumventing this. */
break;
case DEVICE_TYPE_EVDEV:
/* Revoke access on evdev file-descriptors during deactivation.
* This will basically prevent any operations on the fd and
* cannot be undone. Good side is: it needs no CAP_SYS_ADMIN
* protection this way. */
break;
case DEVICE_TYPE_UNKNOWN:
default:
/* fallback for devices without synchronization */
break;
}
}
}
return type;
}
int r;
if (!dev)
return -ENODEV;
if (!node) {
r = -EINVAL;
goto err_dev;
}
/* detect device type so we can find the correct sysfs parent */
r = -ENODEV;
goto err_dev;
/* for evdev devices we need the parent node as device */
p = dev;
if (!dev) {
r = -ENODEV;
goto err_dev;
}
/* Prevent opening unsupported devices. Especially devices of
* subsystem "input" must be opened via the evdev node as
* we require EVIOCREVOKE. */
r = -ENODEV;
goto err_dev;
}
/* search for an existing seat device and return it if available */
/* The caller might have gotten the udev event before we were
* able to process it. Hence, fake the "add" event and let the
* logind-manager handle the new device. */
if (r < 0)
goto err_dev;
/* if it's still not available, then the device is invalid */
r = -ENODEV;
goto err_dev;
}
}
r = -EPERM;
goto err_dev;
}
r = -ENOMEM;
goto err_dev;
}
r = 0;
udev_device_unref(p ? : dev);
return r;
}
int r;
assert(s);
if (!s->seat)
return -EPERM;
if (!sd)
return -ENOMEM;
r = session_device_verify(sd);
if (r < 0)
goto error;
if (r < 0) {
r = -ENOMEM;
goto error;
}
/* Open the device for the first time. We need a valid fd to pass back
* to the caller. If the session is not active, this _might_ immediately
* revoke access and thus invalidate the fd. But this is still needed
* to pass a valid fd back. */
if (r < 0) {
/* EINVAL _may_ mean a master is active; retry inactive */
r = session_device_open(sd, false);
}
if (r < 0)
goto error;
}
return 0;
return r;
}
}
Iterator i;
return;
/* if not all devices are paused, wait for further completion events */
return;
/* complete any pending session switch */
}
void session_device_resume_all(Session *s) {
Iterator i;
int r;
assert(s);
r = session_device_start(sd);
if (!r)
}
}
}
void session_device_pause_all(Session *s) {
Iterator i;
assert(s);
}
}
}
unsigned int session_device_try_pause_all(Session *s) {
Iterator i;
unsigned int num_pending = 0;
assert(s);
++num_pending;
}
}
return num_pending;
}