Work-around a stupid gcov-breaking bug in OSX 10.6

This only affects the unit tests.

Fix found at http://rachelbythebay.com/w/2011/07/12/forkcrash/
This commit is contained in:
Nick Mathewson 2012-04-11 21:33:27 -04:00
parent 53a07fe2f9
commit b62b31f1f1
5 changed files with 36 additions and 2 deletions

View File

@ -829,7 +829,7 @@ test_fork(void)
event_base_assert_ok_(current_base);
TT_BLATHER(("Before fork"));
if ((pid = fork()) == 0) {
if ((pid = regress_fork()) == 0) {
/* in the child */
TT_BLATHER(("In child, before reinit"));
event_base_assert_ok_(current_base);

View File

@ -118,6 +118,8 @@ int test_ai_eq_(const struct evutil_addrinfo *ai, const char *sockaddr_port,
long timeval_msec_diff(const struct timeval *start, const struct timeval *end);
pid_t regress_fork(void);
#ifdef __cplusplus
}
#endif

View File

@ -33,6 +33,14 @@
#include <fcntl.h>
#endif
#if defined(__APPLE__) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
#if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 && \
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070)
#define FORK_BREAKS_GCOV
#include <vproc.h>
#endif
#endif
#include "event2/event-config.h"
#ifdef EVENT____func__
@ -157,6 +165,18 @@ regress_make_tmpfile(const void *data, size_t datalen, char **filename_out)
#endif
}
#ifndef _WIN32
pid_t
regress_fork(void)
{
pid_t pid = fork();
#ifdef FORK_BREAKS_GCOV
vproc_transaction_begin(0);
#endif
return pid;
}
#endif
static void
ignore_log_cb(int s, const char *msg)
{

View File

@ -471,7 +471,7 @@ check_error_logging(void (*fn)(void), int wantexitcode,
int status = 0, exitcode;
fatal_want_severity = wantseverity;
fatal_want_message = wantmsg;
if ((pid = fork()) == 0) {
if ((pid = regress_fork()) == 0) {
/* child process */
fn();
exit(0); /* should be unreachable. */

View File

@ -39,6 +39,15 @@
#include <unistd.h>
#endif
#if defined(__APPLE__) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
#if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 && \
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070)
/* Workaround for a stupid bug in OSX 10.6 */
#define FORK_BREAKS_GCOV
#include <vproc.h>
#endif
#endif
#ifndef __GNUC__
#define __attribute__(x)
#endif
@ -160,6 +169,9 @@ testcase_run_forked_(const struct testgroup_t *group,
if (opt_verbosity>0)
printf("[forking] ");
pid = fork();
#ifdef FORK_BREAKS_GCOV
vproc_transaction_begin(0);
#endif
if (!pid) {
/* child. */
int test_r, write_r;