aboutsummaryrefslogtreecommitdiff
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
parentnspawn: propagate original error. No need to make up -EIO (diff)
downloadsystemd-e7685a77b41bbd1b8289aeaf75fccaf4bb68a361.tar.gz
systemd-e7685a77b41bbd1b8289aeaf75fccaf4bb68a361.tar.bz2
systemd-e7685a77b41bbd1b8289aeaf75fccaf4bb68a361.zip
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 000000000..44b3b1c9f
--- /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);