summaryrefslogtreecommitdiffstats
path: root/logwrapper
diff options
context:
space:
mode:
authorRom Lemarchand <romlem@google.com>2013-03-11 14:00:58 -0700
committerRom Lemarchand <romlem@google.com>2013-03-14 21:31:07 -0700
commit74a7b91cbe29d3a9e6500fb90aae6d9a858dc1f7 (patch)
tree1e769ecf8aca84ec43ff913fc9db301ff01ec6a9 /logwrapper
parent39b7fdea315bf60c5d1e9ae1ddd4b81e2cf83b23 (diff)
downloadsystem_core-74a7b91cbe29d3a9e6500fb90aae6d9a858dc1f7.zip
system_core-74a7b91cbe29d3a9e6500fb90aae6d9a858dc1f7.tar.gz
system_core-74a7b91cbe29d3a9e6500fb90aae6d9a858dc1f7.tar.bz2
liblogwrap: lock android_fork_execvp
Add a lock around android_fork_execvp to ensure no two threads can execute it at the same time. This is to help with http://b/8333626 Change-Id: I75d087a74b58f5b8e878675b301200f54d976fb2
Diffstat (limited to 'logwrapper')
-rw-r--r--logwrapper/logwrap.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/logwrapper/logwrap.c b/logwrapper/logwrap.c
index b2abfe2..129ffb1 100644
--- a/logwrapper/logwrap.c
+++ b/logwrapper/logwrap.c
@@ -27,6 +27,7 @@
#include <fcntl.h>
#include <libgen.h>
#include <stdbool.h>
+#include <pthread.h>
#include <logwrap/logwrap.h>
#include "private/android_filesystem_config.h"
@@ -35,6 +36,7 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
static int signal_fd_write;
+static pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER;
#define ERROR(fmt, args...) \
do { \
@@ -204,6 +206,12 @@ int android_fork_execvp(int argc, char* argv[], int *status, bool ignore_int_qui
int sockets[2];
int rc = 0;
+ rc = pthread_mutex_lock(&fd_mutex);
+ if (rc) {
+ ERROR("failed to lock signal_fd mutex\n");
+ goto err_lock;
+ }
+
/* Use ptty instead of socketpair so that STDOUT is not buffered */
parent_ptty = open("/dev/ptmx", O_RDWR);
if (parent_ptty < 0) {
@@ -231,6 +239,7 @@ int android_fork_execvp(int argc, char* argv[], int *status, bool ignore_int_qui
rc = -1;
goto err_fork;
} else if (pid == 0) {
+ pthread_mutex_unlock(&fd_mutex);
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
close(parent_ptty);
@@ -299,5 +308,7 @@ err_fork:
err_ptty:
close(parent_ptty);
err_open:
+ pthread_mutex_unlock(&fd_mutex);
+err_lock:
return rc;
}