diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-03-20 20:57:37 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-03-20 22:31:14 +0100 |
commit | 43dc7aa2ba9e2e943b7bde47ce707fd1c0b778b1 (patch) | |
tree | 1c07bcabde02048d181c5b63d6ba0e136dcf248e | |
parent | coccinelle: make use of DIV_ROUND_UP() wherever appropriate (diff) | |
download | systemd-43dc7aa2ba9e2e943b7bde47ce707fd1c0b778b1.tar.gz systemd-43dc7aa2ba9e2e943b7bde47ce707fd1c0b778b1.tar.bz2 systemd-43dc7aa2ba9e2e943b7bde47ce707fd1c0b778b1.zip |
coccinelle: always use fcntl(fd, FD_DUPFD, 3) instead of dup(fd)
Let's avoid fds 0…2 for safety reasons.
-rw-r--r-- | coccinelle/dup-fcntl.cocci | 5 | ||||
-rw-r--r-- | src/test/test-fd-util.c | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/coccinelle/dup-fcntl.cocci b/coccinelle/dup-fcntl.cocci new file mode 100644 index 000000000..ef1356428 --- /dev/null +++ b/coccinelle/dup-fcntl.cocci @@ -0,0 +1,5 @@ +@@ +expression fd; +@@ +- dup(fd) ++ fcntl(fd, F_DUPFD, 3) diff --git a/src/test/test-fd-util.c b/src/test/test-fd-util.c index 3f94df2ee..a43a28547 100644 --- a/src/test/test-fd-util.c +++ b/src/test/test-fd-util.c @@ -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); |