richardphibel / rpms / systemd

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