diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-11-29 16:27:41 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-11-29 16:27:41 +0000 |
commit | 32b4cc06b820e70b40cb6c9d9b528f9832a5ea18 (patch) | |
tree | 0b9c01a2e776843e803fa5b2249d0c80073db180 /lib | |
parent | db24c1c957e1675a1adf3d2b7a0fb24ab643e614 (diff) |
Don't try to reuse _initial_thread in the fork() wrapper, as the
thread's existing handle must continue to be valid and it didn't
fully 'change' the thread handle anyway. For pthread_main_np(),
use a new flag, THREAD_ORIGINAL, to indicate that the flagged thread
is the original thread for *this* process.
Fixes some ConsoleKit failures according to aja@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/librthread/rthread.c | 7 | ||||
-rw-r--r-- | lib/librthread/rthread.h | 13 | ||||
-rw-r--r-- | lib/librthread/rthread_fork.c | 6 | ||||
-rw-r--r-- | lib/librthread/rthread_np.c | 5 |
4 files changed, 17 insertions, 14 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index 76c02a68a4f..710a3a97448 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.74 2013/10/23 05:59:46 guenther Exp $ */ +/* $OpenBSD: rthread.c,v 1.75 2013/11/29 16:27:40 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -171,7 +171,8 @@ _rthread_init(void) thread->tid = getthrid(); thread->donesem.lock = _SPINLOCK_UNLOCKED_ASSIGN; - thread->flags |= THREAD_CANCEL_ENABLE|THREAD_CANCEL_DEFERRED; + thread->flags |= THREAD_CANCEL_ENABLE | THREAD_CANCEL_DEFERRED | + THREAD_ORIGINAL; thread->flags_lock = _SPINLOCK_UNLOCKED_ASSIGN; strlcpy(thread->name, "Main process", sizeof(thread->name)); LIST_INSERT_HEAD(&_thread_list, thread, threads); @@ -219,7 +220,7 @@ _rthread_init(void) static void _rthread_free(pthread_t thread) { - /* initial_thread.tid must remain valid */ + /* _initial_thread is static, so don't free it */ if (thread != &_initial_thread) { /* * thread->tid is written to by __threxit in the thread diff --git a/lib/librthread/rthread.h b/lib/librthread/rthread.h index 903628490ce..cb0c80a8538 100644 --- a/lib/librthread/rthread.h +++ b/lib/librthread/rthread.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.h,v 1.47 2013/11/20 23:18:17 tedu Exp $ */ +/* $OpenBSD: rthread.h,v 1.48 2013/11/29 16:27:40 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -185,11 +185,12 @@ struct pthread { }; #define THREAD_DONE 0x001 #define THREAD_DETACHED 0x002 -#define THREAD_CANCELED 0x004 -#define THREAD_CANCEL_ENABLE 0x008 -#define THREAD_CANCEL_DEFERRED 0x010 -#define THREAD_CANCEL_DELAY 0x020 -#define THREAD_DYING 0x040 +#define THREAD_CANCELED 0x004 +#define THREAD_CANCEL_ENABLE 0x008 +#define THREAD_CANCEL_DEFERRED 0x010 +#define THREAD_CANCEL_DELAY 0x020 +#define THREAD_DYING 0x040 +#define THREAD_ORIGINAL 0x080 /* first thread in process */ #define IS_CANCELED(thread) \ (((thread)->flags & (THREAD_CANCELED|THREAD_DYING)) == THREAD_CANCELED) diff --git a/lib/librthread/rthread_fork.c b/lib/librthread/rthread_fork.c index 38118ca22f6..cb76421d2a1 100644 --- a/lib/librthread/rthread_fork.c +++ b/lib/librthread/rthread_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_fork.c,v 1.9 2013/06/25 22:51:46 guenther Exp $ */ +/* $OpenBSD: rthread_fork.c,v 1.10 2013/11/29 16:27:40 guenther Exp $ */ /* * Copyright (c) 2008 Kurt Miller <kurt@openbsd.org> @@ -130,11 +130,11 @@ _dofork(int is_vfork) me->flags_lock = _SPINLOCK_UNLOCKED_ASSIGN; /* this thread is the initial thread for the new process */ - _initial_thread = *me; + me->flags |= THREAD_ORIGINAL; /* reinit the thread list */ LIST_INIT(&_thread_list); - LIST_INSERT_HEAD(&_thread_list, &_initial_thread, threads); + LIST_INSERT_HEAD(&_thread_list, me, threads); _thread_lock = _SPINLOCK_UNLOCKED_ASSIGN; /* single threaded now */ diff --git a/lib/librthread/rthread_np.c b/lib/librthread/rthread_np.c index 75366b8adb1..0cbb24e74e7 100644 --- a/lib/librthread/rthread_np.c +++ b/lib/librthread/rthread_np.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_np.c,v 1.9 2013/11/13 16:56:17 deraadt Exp $ */ +/* $OpenBSD: rthread_np.c,v 1.10 2013/11/29 16:27:40 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2005 Otto Moerbeek <otto@openbsd.org> @@ -45,7 +45,8 @@ pthread_set_name_np(pthread_t thread, const char *name) int pthread_main_np(void) { - return (!_threads_ready || pthread_self() == &_initial_thread ? 1 : 0); + return (!_threads_ready || (pthread_self()->flags & THREAD_ORIGINAL) + ? 1 : 0); } |