]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: always use fcntl(fd, FD_DUPFD, 3) instead of dup(fd) 8508/head
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Mar 2018 19:57:37 +0000 (20:57 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Mar 2018 21:31:14 +0000 (22:31 +0100)
Let's avoid fds 0…2 for safety reasons.

coccinelle/dup-fcntl.cocci [new file with mode: 0644]
src/test/test-fd-util.c

diff --git a/coccinelle/dup-fcntl.cocci b/coccinelle/dup-fcntl.cocci
new file mode 100644 (file)
index 0000000..ef13564
--- /dev/null
@@ -0,0 +1,5 @@
+@@
+expression fd;
+@@
+- dup(fd)
++ fcntl(fd, F_DUPFD, 3)
index 3f94df2eee399c0f215b4f46315e1e3832fa8b24..a43a2854773f4bf16523093e067697b8568c29f8 100644 (file)
@@ -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);