a52f674
From 66a28b3bec25e0456771db7ac356ad58793c337e Mon Sep 17 00:00:00 2001
a52f674
From: David Herrmann <dh.herrmann@gmail.com>
a52f674
Date: Thu, 28 Nov 2013 14:51:40 +0100
a52f674
Subject: [PATCH] logind: ignore failing close() on session-devices
a52f674
a52f674
Unfortunately, close() on a revoked/removed character-device fails with
a52f674
ENODEV. I tried tracking this down in the kernel, but couldn't figure out
a52f674
were exactly it comes from. However, can be easily reproduced with:
a52f674
  fd = open("/dev/input/event0", O_RDWR);
a52f674
  ioctl(fd, EVIOCREVOKE, 0);
a52f674
  r = close(fd);
a52f674
A second close on @fd would return EBADF so the close is actually valid.
a52f674
a52f674
We simply ignore close() errors for all session-devices as their access
a52f674
may be revoked asynchronously, or the device might get unplugged.
a52f674
We use close_nointr() in case anyone ever looks at the return value (or
a52f674
anyone runs "grep 'close(' -r src/" to find broken close() calls).
a52f674
a52f674
Fixes:
a52f674
  systemd-logind[31992]: Assertion 'close_nointr(fd) == 0' failed at src/shared/util.c:185, function close_nointr_nofail(). Aborting.
a52f674
a52f674
(cherry picked from commit d1107170f9e0fa2cb6e8d18586a003f0d96abfc3)
a52f674
---
a52f674
 src/login/logind-session-device.c | 6 +++---
a52f674
 1 file changed, 3 insertions(+), 3 deletions(-)
a52f674
a52f674
diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c
a52f674
index 6605935..fd02b43 100644
a52f674
--- a/src/login/logind-session-device.c
a52f674
+++ b/src/login/logind-session-device.c
a52f674
@@ -162,7 +162,7 @@ static int session_device_open(SessionDevice *sd, bool active) {
a52f674
                          * state. */
a52f674
                         r = sd_drmsetmaster(fd);
a52f674
                         if (r < 0) {
a52f674
-                                close(fd);
a52f674
+                                close_nointr(fd);
a52f674
                                 return r;
a52f674
                         }
a52f674
                 } else {
a52f674
@@ -209,7 +209,7 @@ static int session_device_start(SessionDevice *sd) {
a52f674
                 r = session_device_open(sd, true);
a52f674
                 if (r < 0)
a52f674
                         return r;
a52f674
-                close_nointr_nofail(sd->fd);
a52f674
+                close_nointr(sd->fd);
a52f674
                 sd->fd = r;
a52f674
                 break;
a52f674
         case DEVICE_TYPE_UNKNOWN:
a52f674
@@ -407,7 +407,7 @@ void session_device_free(SessionDevice *sd) {
a52f674
 
a52f674
         session_device_stop(sd);
a52f674
         session_device_notify(sd, SESSION_DEVICE_RELEASE);
a52f674
-        close_nointr_nofail(sd->fd);
a52f674
+        close_nointr(sd->fd);
a52f674
 
a52f674
         LIST_REMOVE(SessionDevice, sd_by_device, sd->device->session_devices, sd);
a52f674