mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
coccinelle: always use fcntl(fd, FD_DUPFD, 3) instead of dup(fd)
Let's avoid fds 0…2 for safety reasons.
This commit is contained in:
parent
be6b0c2165
commit
43dc7aa2ba
5
coccinelle/dup-fcntl.cocci
Normal file
5
coccinelle/dup-fcntl.cocci
Normal file
@ -0,0 +1,5 @@
|
||||
@@
|
||||
expression fd;
|
||||
@@
|
||||
- dup(fd)
|
||||
+ fcntl(fd, F_DUPFD, 3)
|
@ -71,9 +71,9 @@ static void test_same_fd(void) {
|
||||
_cleanup_close_ int a = -1, b = -1, c = -1;
|
||||
|
||||
assert_se(pipe2(p, O_CLOEXEC) >= 0);
|
||||
assert_se((a = dup(p[0])) >= 0);
|
||||
assert_se((a = fcntl(p[0], F_DUPFD, 3)) >= 0);
|
||||
assert_se((b = open("/dev/null", O_RDONLY|O_CLOEXEC)) >= 0);
|
||||
assert_se((c = dup(a)) >= 0);
|
||||
assert_se((c = fcntl(a, F_DUPFD, 3)) >= 0);
|
||||
|
||||
assert_se(same_fd(p[0], p[0]) > 0);
|
||||
assert_se(same_fd(p[1], p[1]) > 0);
|
||||
|
Loading…
Reference in New Issue
Block a user