Commit 15460eae authored by Peter Hutterer's avatar Peter Hutterer

systemd-logind: let the logind code decided whether to close an fd

We can only request one fd per device from systemd-logind. If a fd is re-used
by the same device, releasing the fd from one device doesn't mean we can close
it. The systemd code knows when it's really released, so let it close the fd.

Test case: xorg.conf section for an input device with hotplugging enabled.
evdev detects the duplicate and closes the hotplugged device, which closes the
fd. The other instance of evdev thinks the fd is still valid so now you're
playing a double lottery. First, which client(s) will get the evdev fd?
Second, which requests will be picked up by evdev and which ones will be
picked up by the client? You'll never know, but the fun is in finding out.
Signed-off-by: default avatarPeter Hutterer <>
Reviewed-by: default avatarHans de Goede <>
parent a6f5ffd5
......@@ -250,8 +250,6 @@ config_odev_free_attributes(struct OdevAttributes *attribs)
if (fd != -1) {
systemd_logind_release_fd(major, minor);
if (fd != -1)
systemd_logind_release_fd(major, minor, fd);
......@@ -770,10 +770,8 @@ xf86DeleteInput(InputInfoPtr pInp, int flags)
if (pInp->flags & XI86_SERVER_FD) {
systemd_logind_release_fd(pInp->major, pInp->minor);
if (pInp->flags & XI86_SERVER_FD)
systemd_logind_release_fd(pInp->major, pInp->minor, pInp->fd);
/* Remove the entry from the list. */
if (pInp == xf86InputDevs)
......@@ -873,8 +871,7 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable)
sizeof(pInfo) * (new_input_devices_count + 1));
new_input_devices[new_input_devices_count] = pInfo;
systemd_logind_release_fd(pInfo->major, pInfo->minor);
systemd_logind_release_fd(pInfo->major, pInfo->minor, fd);
return BadMatch;
pInfo->fd = fd;
......@@ -340,8 +340,7 @@ static Bool doPlatformProbe(struct xf86_platform_device *dev, DriverPtr drvp,
fd = xf86_get_platform_device_int_attrib(dev, ODEV_ATTRIB_FD, -1);
major = xf86_get_platform_device_int_attrib(dev, ODEV_ATTRIB_MAJOR, 0);
minor = xf86_get_platform_device_int_attrib(dev, ODEV_ATTRIB_MINOR, 0);
systemd_logind_release_fd(major, minor);
systemd_logind_release_fd(major, minor, fd);
config_odev_add_int_attribute(dev->attribs, ODEV_ATTRIB_FD, -1);
dev->flags &= ~XF86_PDEV_SERVER_FD;
......@@ -37,7 +37,7 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
if (paused) {
"Error systemd-logind returned paused fd for drm node\n");
systemd_logind_release_fd(major, minor);
systemd_logind_release_fd(major, minor, -1);
return FALSE;
config_odev_add_int_attribute(attribs, ODEV_ATTRIB_FD, fd);
......@@ -162,7 +162,7 @@ cleanup:
systemd_logind_release_fd(int _major, int _minor)
systemd_logind_release_fd(int _major, int _minor, int fd)
struct systemd_logind_info *info = &logind_info;
InputInfoPtr pInfo;
......@@ -174,7 +174,7 @@ systemd_logind_release_fd(int _major, int _minor)
int matches = 0;
if (!info->session || major == 0)
goto close;
/* Only release the fd if there is only 1 InputInfo left for this major
* and minor, otherwise other InputInfo's are still referencing the fd. */
......@@ -218,6 +218,9 @@ cleanup:
if (reply)
if (fd != -1)
......@@ -30,14 +30,14 @@
int systemd_logind_init(void);
void systemd_logind_fini(void);
int systemd_logind_take_fd(int major, int minor, const char *path, Bool *paus);
void systemd_logind_release_fd(int major, int minor);
void systemd_logind_release_fd(int major, int minor, int fd);
int systemd_logind_controls_session(void);
void systemd_logind_vtenter(void);
#define systemd_logind_init()
#define systemd_logind_fini()
#define systemd_logind_take_fd(major, minor, path, paus) -1
#define systemd_logind_release_fd(major, minor)
#define systemd_logind_release_fd(major, minor, fd) close(fd)
#define systemd_logind_controls_session() 0
#define systemd_logind_vtenter()
Markdown is supported
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