diff options
author | Dan Williams <dan.j.williams@intel.com> | 2010-07-06 21:48:56 +0200 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2010-07-06 21:48:56 +0200 |
commit | f4190c2f12527e37304f7c185afa0449fa9dee1c (patch) | |
tree | 356a2ab1431d08d161df80f03d7a45c088bccee6 /mdmon.c | |
parent | Merge branch 'master' of git://github.com/djbw/mdadm (diff) | |
download | mdadm-f4190c2f12527e37304f7c185afa0449fa9dee1c.tar.xz mdadm-f4190c2f12527e37304f7c185afa0449fa9dee1c.zip |
mdmon: satisfy glibc tls abi requirements with pthreads
Setting up a proper tls descriptor is required to conform to the abi
[1]. Until it can be implemented in mdmon use pthreads instead of
clone(2) to let glibc handle the details. The old behaviour can be had
by un-defining USE_PTHREADS.
Note, the "O2" builds need LDFLAGS now to pick up the '-pthread' option.
[1]: http://people.redhat.com/drepper/tls.pdf
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'mdmon.c')
-rw-r--r-- | mdmon.c | 42 |
1 files changed, 39 insertions, 3 deletions
@@ -58,8 +58,11 @@ #include <fcntl.h> #include <signal.h> #include <dirent.h> - +#ifdef USE_PTHREADS +#include <pthread.h> +#else #include <sched.h> +#endif #include "mdadm.h" #include "mdmon.h" @@ -71,7 +74,39 @@ int mon_tid, mgr_tid; int sigterm; -int run_child(void *v) +#ifdef USE_PTHREADS +static void *run_child(void *v) +{ + struct supertype *c = v; + + mon_tid = syscall(SYS_gettid); + do_monitor(c); + return 0; +} + +static int clone_monitor(struct supertype *container) +{ + pthread_attr_t attr; + pthread_t thread; + int rc; + + mon_tid = -1; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 4096); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + rc = pthread_create(&thread, &attr, run_child, container); + if (rc) + return rc; + while (mon_tid == -1) + usleep(10); + pthread_attr_destroy(&attr); + + mgr_tid = syscall(SYS_gettid); + + return mon_tid; +} +#else /* USE_PTHREADS */ +static int run_child(void *v) { struct supertype *c = v; @@ -85,7 +120,7 @@ int __clone2(int (*fn)(void *), int flags, void *arg, ... /* pid_t *pid, struct user_desc *tls, pid_t *ctid */ ); #endif - int clone_monitor(struct supertype *container) +static int clone_monitor(struct supertype *container) { static char stack[4096]; @@ -103,6 +138,7 @@ int __clone2(int (*fn)(void *), return mon_tid; } +#endif /* USE_PTHREADS */ static int make_pidfile(char *devname) { |