summaryrefslogtreecommitdiff
path: root/coccinelle
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-26 15:41:38 +0100
committerLennart Poettering <lennart@poettering.net>2018-02-28 10:00:50 +0100
commite7685a77b41bbd1b8289aeaf75fccaf4bb68a361 (patch)
tree2a2942015d0168dced4458652d0bd2d79d0f1c99 /coccinelle
parentc7f9a8d2705ad4d18d1ca43f3a8625575f1186e5 (diff)
downloadsystemd-e7685a77b41bbd1b8289aeaf75fccaf4bb68a361.tar.gz
util: add new safe_close_above_stdio() wrapper
At various places we only want to close fds if they are not stdin/stdout/stderr, i.e. fds 0, 1, 2. Let's add a unified helper call for that, and port everything over.
Diffstat (limited to 'coccinelle')
-rw-r--r--coccinelle/close-above-stdio.cocci36
1 files changed, 36 insertions, 0 deletions
diff --git a/coccinelle/close-above-stdio.cocci b/coccinelle/close-above-stdio.cocci
new file mode 100644
index 0000000000..44b3b1c9f1
--- /dev/null
+++ b/coccinelle/close-above-stdio.cocci
@@ -0,0 +1,36 @@
+@@
+expression fd;
+@@
+- if (fd > 2)
+- safe_close(fd);
++ safe_close_above_stdio(fd);
+@@
+expression fd;
+@@
+- if (fd > 2)
+- fd = safe_close(fd);
++ fd = safe_close_above_stdio(fd);
+@@
+expression fd;
+@@
+- if (fd >= 3)
+- safe_close(fd);
++ safe_close_above_stdio(fd);
+@@
+expression fd;
+@@
+- if (fd >= 3)
+- fd = safe_close(fd);
++ fd = safe_close_above_stdio(fd);
+@@
+expression fd;
+@@
+- if (fd > STDERR_FILENO)
+- safe_close(fd);
++ safe_close_above_stdio(fd);
+@@
+expression fd;
+@@
+- if (fd > STDERR_FILENO)
+- fd = safe_close(fd);
++ fd = safe_close_above_stdio(fd);