]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libudev-queue: use _cleanup_ attribute and TAKE_FD()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 24 Aug 2018 04:42:18 +0000 (13:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 11 Sep 2018 03:45:21 +0000 (12:45 +0900)
src/libudev/libudev-queue.c

index e7d8ffea4cac4973a3fa7187c1ab37d7f1af1b68..99b35d7e49245f7824759ef3eee7a3385639eb86 100644 (file)
@@ -205,8 +205,9 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu
  * Returns: a file descriptor to watch for a queue to become empty.
  */
 _public_ int udev_queue_get_fd(struct udev_queue *udev_queue) {
-        int fd;
-        int r;
+        _cleanup_close_ int fd = -1;
+
+        assert_return(udev_queue, -EINVAL);
 
         if (udev_queue->fd >= 0)
                 return udev_queue->fd;
@@ -215,15 +216,11 @@ _public_ int udev_queue_get_fd(struct udev_queue *udev_queue) {
         if (fd < 0)
                 return -errno;
 
-        r = inotify_add_watch(fd, "/run/udev" , IN_DELETE);
-        if (r < 0) {
-                r = -errno;
-                close(fd);
-                return r;
-        }
+        if (inotify_add_watch(fd, "/run/udev" , IN_DELETE) < 0)
+                return -errno;
 
-        udev_queue->fd = fd;
-        return fd;
+        udev_queue->fd = TAKE_FD(fd);
+        return udev_queue->fd;
 }
 
 /**