summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coccinelle/safe_close.cocci18
-rw-r--r--src/login/logind-button.c6
-rw-r--r--src/udev/udev-event.c12
3 files changed, 24 insertions, 12 deletions
diff --git a/coccinelle/safe_close.cocci b/coccinelle/safe_close.cocci
new file mode 100644
index 0000000000..6fedd804f2
--- /dev/null
+++ b/coccinelle/safe_close.cocci
@@ -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);
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index 210b889c4f..3324c4622c 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -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;
}
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 4761222786..f2b165076d 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -754,12 +754,10 @@ int udev_event_spawn(struct udev_event *event,
/* child closes parent's ends of pipes */
if (outpipe[READ_END] >= 0) {
- close(outpipe[READ_END]);
- outpipe[READ_END] = -1;
+ outpipe[READ_END] = safe_close(outpipe[READ_END]);
}
if (errpipe[READ_END] >= 0) {
- close(errpipe[READ_END]);
- errpipe[READ_END] = -1;
+ errpipe[READ_END] = safe_close(errpipe[READ_END]);
}
strscpy(arg, sizeof(arg), cmd);
@@ -785,12 +783,10 @@ int udev_event_spawn(struct udev_event *event,
default:
/* parent closed child's ends of pipes */
if (outpipe[WRITE_END] >= 0) {
- close(outpipe[WRITE_END]);
- outpipe[WRITE_END] = -1;
+ outpipe[WRITE_END] = safe_close(outpipe[WRITE_END]);
}
if (errpipe[WRITE_END] >= 0) {
- close(errpipe[WRITE_END]);
- errpipe[WRITE_END] = -1;
+ errpipe[WRITE_END] = safe_close(errpipe[WRITE_END]);
}
spawn_read(event,