chiark / gitweb /
tree-wide: make more code use safe_close()
authorLennart Poettering <lennart@poettering.net>
Tue, 8 Sep 2015 16:53:19 +0000 (18:53 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 29 Mar 2017 08:45:09 +0000 (10:45 +0200)
Replace this:

        close(fd);
        fd = -1;

write this:

        fd = safe_close(fd);

coccinelle/safe_close.cocci [new file with mode: 0644]
src/login/logind-button.c

diff --git a/coccinelle/safe_close.cocci b/coccinelle/safe_close.cocci
new file mode 100644 (file)
index 0000000..6fedd80
--- /dev/null
@@ -0,0 +1,18 @@
+@@
+expression fd;
+@@
+- close(fd);
+- fd = -1;
++ fd = safe_close(fd);
+@@
+expression fd;
+@@
+- close_nointr(fd);
+- fd = -1;
++ fd = safe_close(fd);
+@@
+expression fd;
+@@
+- safe_close(fd);
+- fd = -1;
++ fd = safe_close(fd);
index 210b889..3324c46 100644 (file)
@@ -240,8 +240,7 @@ int button_open(Button *b) {
         assert(b);
 
         if (b->fd >= 0) {
-                close(b->fd);
-                b->fd = -1;
+                b->fd = safe_close(b->fd);
         }
 
         p = strjoina("/dev/input/", b->name);
@@ -267,8 +266,7 @@ int button_open(Button *b) {
         return 0;
 
 fail:
-        close(b->fd);
-        b->fd = -1;
+        b->fd = safe_close(b->fd);
         return r;
 }