From: Nick Mathewson Date: Tue, 29 Dec 2009 21:38:03 +0000 (-0500) Subject: Detect setenv/unsetenv; skip main/base_environ test if we can't fake them. X-Git-Tag: release-2.0.4-alpha~69 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7296971b105ffc2bc9d20b0a24a3055c2ecf5e69;p=libevent Detect setenv/unsetenv; skip main/base_environ test if we can't fake them. Previously, we assumed that we would have setenv/unsetenv everywhere but WIN32, where we could fake them with putenv. This isn't so: some other non-windows systems lack setenv/unsetenv, and some of them lack putenv too. The first part of the solution, then, is to detect setenv/unsetenv/ putenv from configure.in, and to fake setenv/unsetenv with putenv whenever we have the latter but not one of the former. But what should we do when we don't even have putenv? We could do elaborate tricks to manipulate the environ pointer, but since we're only doing this for the unit tests, let's just skip the one test in question that uses setenv/unsetenv. --- diff --git a/configure.in b/configure.in index 8d590ffb..87c625c0 100644 --- a/configure.in +++ b/configure.in @@ -180,8 +180,7 @@ AC_C_INLINE AC_HEADER_TIME dnl Checks for library functions. -AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random issetugid geteuid getegid getservbyname getprotobynumber) - +AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random issetugid geteuid getegid getservbyname getprotobynumber setenv unsetenv putenv) # Check for gethostbyname_r in all its glorious incompatible versions. # (This is cut-and-pasted from Tor, which based its logic on diff --git a/test/regress.c b/test/regress.c index 4e4e11bf..f34890a1 100644 --- a/test/regress.c +++ b/test/regress.c @@ -1683,39 +1683,52 @@ end: event_config_free(cfg); } -static void -methodname_to_envvar(const char *mname, char *buf, size_t buflen) -{ - char *cp; - evutil_snprintf(buf, buflen, "EVENT_NO%s", mname); - for (cp = buf; *cp; ++cp) { - *cp = toupper(*cp); - } -} - -#ifdef WIN32 +#ifdef _EVENT_HAVE_SETENV +#define SETENV_OK +#elif !defined(_EVENT_HAVE_SETENV) && defined(_EVENT_HAVE_PUTENV) static void setenv(const char *k, const char *v, int _o) { char b[256]; evutil_snprintf(b, sizeof(b), "%s=%s",k,v); putenv(b); } +#define SETENV_OK +#endif + +#ifdef _EVENT_HAVE_UNSETENV +#define UNSETENV_OK +#elif !defined(_EVENT_HAVE_UNSETENV) && defined(_EVENT_HAVE_PUTENV) static void unsetenv(const char *k) { char b[256]; evutil_snprintf(b, sizeof(b), "%s=",k); putenv(b); } +#define UNSETENV_OK +#endif + +#if defined(SETENV_OK) && defined(UNSETENV_OK) +static void +methodname_to_envvar(const char *mname, char *buf, size_t buflen) +{ + char *cp; + evutil_snprintf(buf, buflen, "EVENT_NO%s", mname); + for (cp = buf; *cp; ++cp) { + *cp = toupper(*cp); + } +} #endif static void test_base_environ(void *arg) { + struct event_base *base = NULL; + struct event_config *cfg = NULL; + +#if defined(SETENV_OK) && defined(UNSETENV_OK) const char **basenames; char varbuf[128]; int i, n_methods=0; - struct event_base *base = NULL; - struct event_config *cfg = NULL; const char *defaultname; basenames = event_get_supported_methods(); @@ -1757,6 +1770,9 @@ test_base_environ(void *arg) base = event_base_new_with_config(cfg); tt_assert(base); tt_str_op(defaultname, ==, event_base_get_method(base)); +#else + tt_skip(); +#endif end: if (base)