logind-session-device: use _cleanup_close_
authorMike Yuan <me@yhndnzj.com>
Thu, 28 Dec 2023 12:43:12 +0000 (20:43 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 28 Dec 2023 12:43:42 +0000 (20:43 +0800)
src/login/logind-session-device.c

index 44d8d525ee01c240ac4033dc0dae78374c129f76..fc0b2fb86e7b3a8570f5acfba01b2812f584980d 100644 (file)
@@ -114,7 +114,8 @@ static int sd_drmdropmaster(int fd) {
 }
 
 static int session_device_open(SessionDevice *sd, bool active) {
-        int fd, r;
+        _cleanup_close_ int fd = -EBADF;
+        int r;
 
         assert(sd);
         assert(sd->type != DEVICE_TYPE_UNKNOWN);
@@ -132,10 +133,8 @@ static int session_device_open(SessionDevice *sd, bool 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) {
-                                (void) close_nointr(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. */
@@ -153,7 +152,7 @@ static int session_device_open(SessionDevice *sd, bool active) {
                 break;
         }
 
-        return fd;
+        return TAKE_FD(fd);
 }
 
 static int session_device_start(SessionDevice *sd) {