>From ba196a08048e52e437e84aa2f230e4f5af9b4e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Sun, 24 Nov 2013 00:06:10 +0000 Subject: [PATCH] sort: fix possible multithreaded races with stdio functions Avoid using the _unlocked variants which are not threadsafe. * src/sort.c: If pthreads are available, then define AVOID_UNLOCKED_IO * src/system.h: Don't include the mapping header when instructed not to. --- src/sort.c | 5 +++++ src/system.h | 5 ++++- 2 files changed, 9 insertions(+), 1 deletions(-) diff --git a/src/sort.c b/src/sort.c index bb4e313..695c71e 100644 --- a/src/sort.c +++ b/src/sort.c @@ -22,6 +22,11 @@ #include +/* Avoid using the unlocked variants in this multithreaded program. */ +#if HAVE_PTHREAD_T +# define AVOID_UNLOCKED_IO 1 +#endif + #include #include #include diff --git a/src/system.h b/src/system.h index db89316..b839a70 100644 --- a/src/system.h +++ b/src/system.h @@ -254,7 +254,10 @@ uid_t getuid (); #define X2REALLOC(P, PN) ((void) verify_true (sizeof *(P) == 1), \ x2realloc (P, PN)) -#include "unlocked-io.h" +#if !AVOID_UNLOCKED_IO +# include "unlocked-io.h" +#endif + #include "same-inode.h" #include "dirname.h" -- 1.7.7.6