summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-03 14:26:22 +0200
committerLennart Poettering <lennart@poettering.net>2015-04-03 14:26:22 +0200
commit9ff3e22aa93fe461f8971f2468c65dc928fadc9e (patch)
treecf1054d1aec75dd8566056c916b7939463b684b8
parentd95a74ed1191bb09f5be57b0619d3d77708e019d (diff)
CODING_STYLE: mention that dup() should not be used
-rw-r--r--CODING_STYLE7
1 files changed, 7 insertions, 0 deletions
diff --git a/CODING_STYLE b/CODING_STYLE
index 1748dc4bc4..feb1a9dd67 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -232,3 +232,10 @@
"return" to exit from the main function of a process. If you
fork()ed off a child process, please use _exit() instead of exit(),
so that the exit handlers are not run.
+
+- Please never use dup(). Use fcntl(fd, F_DUPFD_CLOEXEC, 3)
+ instead. For two reason: first, you want O_CLOEXEC set on the new fd
+ (see above). Second, dup() will happily duplicate your fd as 0, 1,
+ 2, i.e. stdin, stdout, stderr, should those fds be closed. Given the
+ special semantics of those fds, it's probably a good idea to avoid
+ them. F_DUPFD_CLOEXEC with "3" as parameter avoids them.