systemd/coccinelle/close-above-stdio.cocci
Lennart Poettering e7685a77b4 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.
2018-02-28 10:00:50 +01:00

37 lines
554 B
Plaintext

@@
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);