aboutsummaryrefslogtreecommitdiffstats
path: root/configure.in
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2008-09-12 10:15:26 -0400
committerTheodore Ts'o <tytso@mit.edu>2008-09-12 10:15:26 -0400
commitd7f45af802330a0e1450afa05185d3722e77a76c (patch)
tree4eb79fcc0ad80db68625e7412866c7d400e09402 /configure.in
parent3218dc9db8fc2affeae2fb563db0fc07a55a59de (diff)
downloade2fsprogs-d7f45af802330a0e1450afa05185d3722e77a76c.tar.gz
e2fsprogs-d7f45af802330a0e1450afa05185d3722e77a76c.tar.xz
e2fsprogs-d7f45af802330a0e1450afa05185d3722e77a76c.zip
libcom_err: Use sem_post/sem_init to prevent race conditions
SuSE has been carrying a patch for a long time to prevent a largely theoretical race condition if a multi-threaded application adds and removes error tables in multiple threads. Unfortunately SuSE's approach breaks compatibility by forcing applications to link and compile with the -pthread option; using pthread mutexes has historically been problematic. This commit fixes things in a more portable way by using sem_post/sem_wait instead, which is an older interface that doesn't require the pthreads library. Linux happens to implement sem_post/sem_init using futexes, and -lrt ends up pulling in -lpthread, but the advantage of using POSIX semaphores is that applications don't have to be built using -pthread, unlike the use of pthread mutexes. The add_error_table() and remove_error_table() interfaces are the preferred interfaces and locking protection have been added to only these interfaces. I have not added locking protection to the generated initialize_xxx_error_table and initialize_xxx_error_table_r interfaces, to avoid adding symbol dependencies that would cause a library to fail to work when linking against older com_err libraries that do not export et_list_lock() and et_list_unlock(). Threaded applications shouldn't be using these interfaces in any case. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'configure.in')
-rw-r--r--configure.in17
1 files changed, 16 insertions, 1 deletions
diff --git a/configure.in b/configure.in
index 7ec69458..2534df4c 100644
--- a/configure.in
+++ b/configure.in
@@ -584,7 +584,7 @@ if test $cross_compiling = no; then
else
AC_CHECK_PROGS(BUILD_CC, gcc cc)
fi
-AC_CHECK_HEADERS(dirent.h errno.h getopt.h malloc.h mntent.h paths.h setjmp.h signal.h stdarg.h stdint.h stdlib.h termios.h termio.h unistd.h utime.h linux/fd.h linux/major.h net/if_dl.h netinet/in.h sys/disklabel.h sys/file.h sys/ioctl.h sys/mkdev.h sys/mman.h sys/prctl.h sys/queue.h sys/resource.h sys/select.h sys/socket.h sys/sockio.h sys/stat.h sys/syscall.h sys/sysmacros.h sys/time.h sys/types.h sys/un.h sys/wait.h)
+AC_CHECK_HEADERS(dirent.h errno.h getopt.h malloc.h mntent.h paths.h semaphore.h setjmp.h signal.h stdarg.h stdint.h stdlib.h termios.h termio.h unistd.h utime.h linux/fd.h linux/major.h net/if_dl.h netinet/in.h sys/disklabel.h sys/file.h sys/ioctl.h sys/mkdev.h sys/mman.h sys/prctl.h sys/queue.h sys/resource.h sys/select.h sys/socket.h sys/sockio.h sys/stat.h sys/syscall.h sys/sysmacros.h sys/time.h sys/types.h sys/un.h sys/wait.h)
AC_CHECK_HEADERS(sys/disk.h sys/mount.h,,,
[[
#if HAVE_SYS_QUEUE_H
@@ -729,6 +729,21 @@ if test $ac_cv_have_optreset = yes; then
AC_DEFINE(HAVE_OPTRESET)
fi
dnl
+dnl Test for sem_init, and which library it might require:
+dnl
+SEM_INIT_LIB=''
+AC_CHECK_FUNC(sem_init, ,
+ AC_CHECK_LIB(pthread, sem_init,
+ AC_DEFINE(HAVE_SEM_INIT)
+ SEM_INIT_LIB=-lpthread,
+ AC_CHECK_LIB(rt, sem_init,
+ AC_DEFINE(HAVE_SEM_INIT)
+ SEM_INIT_LIB=-lrt,
+ AC_CHECK_LIB(posix4, sem_init,
+ AC_DEFINE(HAVE_SEM_INIT)
+ SEM_INIT_LIB=-lposix4))))dnl
+AC_SUBST(SEM_INIT_LIB)
+dnl
dnl Check for unified diff
dnl
AC_MSG_CHECKING(for unified diff option)