summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2017-07-27 16:35:09 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2017-07-27 16:35:09 +0000
commit89207470ed102ae46c7187ab346f8e86c5cb0ed3 (patch)
tree07d1fc56fb1e17343c87a0f12d2a187746a133b2
parent0fc2cd820c1f7bd4b47498f8319783cf0d02d123 (diff)
bad things can (and will) happen if a threaded program calls fork() and
then strays off the path to exec(). one common manifestation of this problem occurs in pthread_join(), so we can add a little check there. first person to hit this in real life gets to change the error message.
-rw-r--r--lib/librthread/rthread.c8
-rw-r--r--lib/librthread/rthread_fork.c4
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c
index b2e5e7ea86b..b9aa60ef77b 100644
--- a/lib/librthread/rthread.c
+++ b/lib/librthread/rthread.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread.c,v 1.94 2016/09/04 10:13:35 akfaew Exp $ */
+/* $OpenBSD: rthread.c,v 1.95 2017/07/27 16:35:08 tedu Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -64,6 +64,7 @@ REDIRECT_SYSCALL(thrkill);
static int concurrency_level; /* not used */
int _threads_ready;
+int _post_threaded;
size_t _thread_pagesize;
struct listhead _thread_list = LIST_HEAD_INITIALIZER(_thread_list);
_atomic_lock_t _thread_lock = _SPINLOCK_UNLOCKED;
@@ -358,6 +359,11 @@ pthread_join(pthread_t thread, void **retval)
pthread_t self;
PREP_CANCEL_POINT(tib);
+ if (_post_threaded) {
+#define GREATSCOTT "great scott! serious repercussions on future events!\n"
+ write(2, GREATSCOTT, sizeof(GREATSCOTT) - 1);
+ abort();
+ }
if (!_threads_ready)
_rthread_init();
self = tib->tib_thread;
diff --git a/lib/librthread/rthread_fork.c b/lib/librthread/rthread_fork.c
index 59d61b53e83..9ceb05d9157 100644
--- a/lib/librthread/rthread_fork.c
+++ b/lib/librthread/rthread_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_fork.c,v 1.19 2016/09/04 10:13:35 akfaew Exp $ */
+/* $OpenBSD: rthread_fork.c,v 1.20 2017/07/27 16:35:08 tedu Exp $ */
/*
* Copyright (c) 2008 Kurt Miller <kurt@openbsd.org>
@@ -58,6 +58,7 @@ _dofork(pid_t (*sys_fork)(void))
pthread_t me;
pid_t newid;
int i;
+ extern int _post_threaded;
if (!_threads_ready)
return sys_fork();
@@ -110,6 +111,7 @@ _dofork(pid_t (*sys_fork)(void))
/* single threaded now */
__isthreaded = 0;
+ _post_threaded = 1;
}
#ifndef NO_PIC
else if (_DYNAMIC)