diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2016-11-24 14:50:21 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2016-11-24 14:50:21 +0000 |
commit | 4e2825545b5ee4db644ad01531044b278b58e4bd (patch) | |
tree | 2f24538ec121a97628ce19e4bfe8c8c364b0f3c8 /lib | |
parent | 9b6cc50d1aab77bdec14d5f6d37a00412da6e8ea (diff) | |
download | src-4e2825545b5ee4db644ad01531044b278b58e4bd.tar.gz src-4e2825545b5ee4db644ad01531044b278b58e4bd.zip |
Add a warning against modifying this code without understanding it, and
an example of how not to make it more portable. I've had this lying
around uncommitted since 2009...
Notes
Notes:
svn path=/head/; revision=309109
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libutil/flopen.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/libutil/flopen.c b/lib/libutil/flopen.c index 754c9c037fa2..bc4119dcb1cc 100644 --- a/lib/libutil/flopen.c +++ b/lib/libutil/flopen.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2007 Dag-Erling Coïdan Smørgrav + * Copyright (c) 2007-2009 Dag-Erling Coïdan Smørgrav * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,6 +37,14 @@ __FBSDID("$FreeBSD$"); #include <libutil.h> +/* + * Reliably open and lock a file. + * + * DO NOT, UNDER PAIN OF DEATH, modify this code without first reading the + * revision history and discussing your changes with <des@freebsd.org>. + * Don't be fooled by the code's apparent simplicity; there would be no + * need for this function if it was as easy to get right as you think. + */ int flopen(const char *path, int flags, ...) { @@ -100,6 +108,14 @@ flopen(const char *path, int flags, ...) errno = serrno; return (-1); } +#ifdef DONT_EVEN_THINK_ABOUT_IT + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + serrno = errno; + (void)close(fd); + errno = serrno; + return (-1); + } +#endif return (fd); } } |