Skip to content
Permalink
Browse files
mysys: Remove freebsd freopen implementation
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=79887
was fixed in 7.4 and 8.2.

Both of these reached end of life in February 2011
https://www.freebsd.org/releases/

Signed-off-by: Daniel Black <daniel@linux.vnet.ibm.com>
  • Loading branch information
grooverdan authored and Sergey Vojtovich committed Nov 15, 2017
1 parent 761e657 commit 3948f4b
Showing 1 changed file with 0 additions and 60 deletions.
@@ -19,10 +19,6 @@
#include <errno.h>
#include "mysys_err.h"

#if defined(__FreeBSD__)
extern int getosreldate(void);
#endif

static void make_ftype(char * to,int flag);

/*
@@ -130,52 +126,6 @@ static FILE *my_win_freopen(const char *path, const char *mode, FILE *stream)
return stream;
}

#elif defined(__FreeBSD__)

/* No close operation hook. */

static int no_close(void *cookie __attribute__((unused)))
{
return 0;
}

/*
A hack around a race condition in the implementation of freopen.
The race condition stems from the fact that the current fd of
the stream is closed before its number is used to duplicate the
new file descriptor. This defeats the desired atomicity of the
close and duplicate of dup2().
See PR number 79887 for reference:
http://www.freebsd.org/cgi/query-pr.cgi?pr=79887
*/

static FILE *my_freebsd_freopen(const char *path, const char *mode, FILE *stream)
{
int old_fd;
FILE *result;

flockfile(stream);

old_fd= fileno(stream);

/* Use a no operation close hook to avoid having the fd closed. */
stream->_close= no_close;

/* Relies on the implicit dup2 to close old_fd. */
result= freopen(path, mode, stream);

/* If successful, the _close hook was replaced. */

if (result == NULL)
close(old_fd);
else
funlockfile(result);

return result;
}

#endif


@@ -199,16 +149,6 @@ FILE *my_freopen(const char *path, const char *mode, FILE *stream)

#if defined(_WIN32)
result= my_win_freopen(path, mode, stream);
#elif defined(__FreeBSD__)
/*
XXX: Once the fix is ported to the stable releases, this should
be dependent upon the specific FreeBSD versions. Check at:
http://www.freebsd.org/cgi/query-pr.cgi?pr=79887
*/
if (getosreldate() > 900027)
result= freopen(path, mode, stream);
else
result= my_freebsd_freopen(path, mode, stream);
#else
result= freopen(path, mode, stream);
#endif

0 comments on commit 3948f4b

Please sign in to comment.