All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH pseudo 1/2] test-umask: clear state before test
@ 2016-10-01 15:03 Rabin Vincent
  2016-10-01 15:03 ` [PATCH pseudo 2/2] Reset the pseudo mutex on fork Rabin Vincent
  0 siblings, 1 reply; 2+ messages in thread
From: Rabin Vincent @ 2016-10-01 15:03 UTC (permalink / raw)
  To: seebs; +Cc: yocto, Rabin Vincent

From: Rabin Vincent <rabinv@axis.com>

test-umask fails if run twice.  Make it remove the created temporary
files before the test.

Signed-off-by: Rabin Vincent <rabinv@axis.com>
---
 test/test-umask.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/test-umask.sh b/test/test-umask.sh
index 48cb3b1..8ca4963 100755
--- a/test/test-umask.sh
+++ b/test/test-umask.sh
@@ -4,6 +4,8 @@ mode() {
 	ls -l "$1" | awk '{ print $1 }'
 }
 
+rm -f a b
+
 # Verify normal operation...
 umask 022
 touch a
-- 
2.1.4



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

* [PATCH pseudo 2/2] Reset the pseudo mutex on fork
  2016-10-01 15:03 [PATCH pseudo 1/2] test-umask: clear state before test Rabin Vincent
@ 2016-10-01 15:03 ` Rabin Vincent
  0 siblings, 0 replies; 2+ messages in thread
From: Rabin Vincent @ 2016-10-01 15:03 UTC (permalink / raw)
  To: seebs; +Cc: yocto, Rabin Vincent

From: Rabin Vincent <rabinv@axis.com>

When tclsh forks it can create new threads in the child process, in a
pthread_atfork() handler.  Running this under pseudo results in a
deadlock since the pseudo_lock() call in the new thread in the child
process premanently believes that the mutex is already locked by another
thread (which actually only existed in the parent process).

The provided test cases reproduces this.  Similar hangs can also been
seen in other cases, such as when attempting to use vim's cscope support
under pseudo.

Fix it by reseting the mutex in a pthread_atfork() child function.

Signed-off-by: Rabin Vincent <rabinv@axis.com>
---
 pseudo_wrappers.c       | 10 ++++++++++
 test/test-tclsh-fork.sh |  6 ++++++
 2 files changed, 16 insertions(+)
 create mode 100755 test/test-tclsh-fork.sh

diff --git a/pseudo_wrappers.c b/pseudo_wrappers.c
index 615ac9a..12bc541 100644
--- a/pseudo_wrappers.c
+++ b/pseudo_wrappers.c
@@ -98,8 +98,18 @@ extern int (*pseudo_real_lsetxattr)(const char *, const char *, const void *, si
 extern int (*pseudo_real_fsetxattr)(int, const char *, const void *, size_t, int);
 #endif
 
+static void libpseudo_atfork_child(void)
+{
+	pthread_mutex_init(&pseudo_mutex, NULL);
+	pseudo_mutex_recursion = 0;
+	pseudo_mutex_holder = 0;
+}
+
 static void
 _libpseudo_init(void) {
+	if (!_libpseudo_initted)
+		pthread_atfork(NULL, NULL, libpseudo_atfork_child);
+
 	pseudo_getlock();
 	pseudo_antimagic();
 	_libpseudo_initted = 1;
diff --git a/test/test-tclsh-fork.sh b/test/test-tclsh-fork.sh
new file mode 100755
index 0000000..e9dec66
--- /dev/null
+++ b/test/test-tclsh-fork.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+# Check that tclsh doesn't hang.  Note that the timeout is not needed to
+# reproduce the hang in tclsh, it's only there to ensure that this test script
+# doesn't hang in case of a failing test.
+timeout 2s bash -c "echo 'open {|true} r+' | tclsh"
-- 
2.1.4



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

end of thread, other threads:[~2016-10-01 15:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-01 15:03 [PATCH pseudo 1/2] test-umask: clear state before test Rabin Vincent
2016-10-01 15:03 ` [PATCH pseudo 2/2] Reset the pseudo mutex on fork Rabin Vincent

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.