public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* problem with syslog, libpthread and dlopen
@ 2003-09-19  0:08 Philip Blundell
  2003-09-22 17:53 ` Philip Blundell
  0 siblings, 1 reply; 3+ messages in thread
From: Philip Blundell @ 2003-09-19  0:08 UTC (permalink / raw)
  To: libc-hacker

Some Debian users have been reporting problems with syslog() blocking
forever when an object that's linked against libpthread has been
previously loaded with dlopen.  If the main program is linked with
-lpthread directly, or it's loaded with LD_PRELOAD, the bug does not
occur.

What seems to happen is that the __libc_cleanup_push and
__libc_cleanup_pop calls in openlog() have no effect, because libc's GOT
entries for _pthread_cleanup_push and _pthread_cleanup_pop are set to
NULL.  But the call to __libc_lock_lock goes via
__libc_pthread_functions, which has now been initialized, so openlog()
returns with the lock still held.  Then the next call to a syslog
function attempts to claim the lock a second time, and deadlock ensues.

A testcase is at:
http://lists.debian.org/debian-glibc/2003/debian-glibc-200309/msg00310.html

What's the right way to fix this?  Should _pthread_cleanup_push/pop be
called through __libc_pthread_functions as well?

Thanks

p.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: problem with syslog, libpthread and dlopen
  2003-09-19  0:08 problem with syslog, libpthread and dlopen Philip Blundell
@ 2003-09-22 17:53 ` Philip Blundell
  2003-09-23  5:51   ` Ulrich Drepper
  0 siblings, 1 reply; 3+ messages in thread
From: Philip Blundell @ 2003-09-22 17:53 UTC (permalink / raw)
  To: libc-hacker

[-- Attachment #1: Type: text/plain, Size: 252 bytes --]

On Fri, 2003-09-19 at 01:08, Philip Blundell wrote:
> What's the right way to fix this?  Should _pthread_cleanup_push/pop be
> called through __libc_pthread_functions as well?

Here's the patch I'm currently using for this.  Any comments?

Thanks

p.


[-- Attachment #2: push-pop.diff --]
[-- Type: text/plain, Size: 3852 bytes --]

2003-09-22  Philip Blundell  <philb@gnu.org>

	* forward.c: Add _pthread_cleanup_push, _pthread_cleanup_pop.
	* sysdeps/pthread/pthread-functions.h (struct pthread_functions):
	Likewise.
	* pthread.c (__pthread_elements): Initialise these new elements.	
	* sysdeps/pthread/bits/libc-lock.h (__libc_cleanup_push): Use
	__libc_maybe_call.
	(__libc_cleanup_pop): Likewise.

Index: linuxthreads/forward.c
===================================================================
RCS file: /cvs/glibc/libc/linuxthreads/forward.c,v
retrieving revision 1.5
diff -u -r1.5 forward.c
--- linuxthreads/forward.c	2 Sep 2003 00:37:04 -0000	1.5
+++ linuxthreads/forward.c	18 Sep 2003 23:36:32 -0000
@@ -173,3 +173,7 @@
 	 0)
 
 FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
+
+FORWARD2 (_pthread_cleanup_push, void, (struct _pthread_cleanup_buffer * buffer, void (*routine)(void *), void * arg), (buffer, routine, arg), return)
+
+FORWARD2 (_pthread_cleanup_pop, void, (struct _pthread_cleanup_buffer * buffer, int execute), (buffer, execute), return)
Index: linuxthreads/pthread.c
===================================================================
RCS file: /cvs/glibc/libc/linuxthreads/pthread.c,v
retrieving revision 1.130
diff -u -r1.130 pthread.c
--- linuxthreads/pthread.c	17 Sep 2003 09:39:16 -0000	1.130
+++ linuxthreads/pthread.c	18 Sep 2003 23:36:32 -0000
@@ -279,7 +279,9 @@
     .ptr_pthread_cleanup_upto = __pthread_cleanup_upto,
     .ptr_pthread_sigaction = __pthread_sigaction,
     .ptr_pthread_sigwait = __pthread_sigwait,
-    .ptr_pthread_raise = __pthread_raise
+    .ptr_pthread_raise = __pthread_raise,
+    .ptr__pthread_cleanup_push = _pthread_cleanup_push,
+    .ptr__pthread_cleanup_pop = _pthread_cleanup_pop
   };
 #ifdef SHARED
 # define ptr_pthread_functions &__pthread_functions
Index: linuxthreads/sysdeps/pthread/pthread-functions.h
===================================================================
RCS file: /cvs/glibc/libc/linuxthreads/sysdeps/pthread/pthread-functions.h,v
retrieving revision 1.3
diff -u -r1.3 pthread-functions.h
--- linuxthreads/sysdeps/pthread/pthread-functions.h	10 Sep 2003 22:27:19 -0000	1.3
+++ linuxthreads/sysdeps/pthread/pthread-functions.h	18 Sep 2003 23:36:33 -0000
@@ -83,6 +83,11 @@
   int (*ptr_pthread_raise) (int sig);
   int (*ptr___pthread_cond_timedwait) (pthread_cond_t *, pthread_mutex_t *,
 				       const struct timespec *);
+  void (*ptr__pthread_cleanup_push) (struct _pthread_cleanup_buffer * buffer,
+				     void (*routine)(void *), void * arg);
+
+  void (*ptr__pthread_cleanup_pop) (struct _pthread_cleanup_buffer * buffer,
+				    int execute);
 };
 
 /* Variable in libc.so.  */
Index: linuxthreads/sysdeps/pthread/bits/libc-lock.h
===================================================================
RCS file: /cvs/glibc/libc/linuxthreads/sysdeps/pthread/bits/libc-lock.h,v
retrieving revision 1.31
diff -u -r1.31 libc-lock.h
--- linuxthreads/sysdeps/pthread/bits/libc-lock.h	8 Aug 2003 07:40:17 -0000	1.31
+++ linuxthreads/sysdeps/pthread/bits/libc-lock.h	18 Sep 2003 23:36:33 -0000
@@ -265,18 +265,12 @@
     }
 
 #define __libc_cleanup_push(fct, arg) \
-  { struct _pthread_cleanup_buffer _buffer;				      \
-    int _avail = _pthread_cleanup_push != NULL;				      \
-    if (_avail) {							      \
-      _pthread_cleanup_push (&_buffer, (fct), (arg));			      \
-    }
+    { struct _pthread_cleanup_buffer _buffer; 				      \
+    __libc_maybe_call (_pthread_cleanup_push, (&_buffer, (fct), (arg)), 0)
 
 #define __libc_cleanup_pop(execute) \
-    if (_avail) {							      \
-      _pthread_cleanup_pop (&_buffer, execute);				      \
-    }									      \
-  }
-
+    __libc_maybe_call (_pthread_cleanup_pop, (&_buffer, execute), 0);	      \
+    }
 
 /* Create thread-specific key.  */
 #define __libc_key_create(KEY, DESTRUCTOR) \

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: problem with syslog, libpthread and dlopen
  2003-09-22 17:53 ` Philip Blundell
@ 2003-09-23  5:51   ` Ulrich Drepper
  0 siblings, 0 replies; 3+ messages in thread
From: Ulrich Drepper @ 2003-09-23  5:51 UTC (permalink / raw)
  To: Philip Blundell; +Cc: libc-hacker

Philip Blundell wrote:

> Here's the patch I'm currently using for this.  Any comments?

Looks OK, I've applied it.

-- 
--------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-09-23  5:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-19  0:08 problem with syslog, libpthread and dlopen Philip Blundell
2003-09-22 17:53 ` Philip Blundell
2003-09-23  5:51   ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).