mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-06 18:58:09 -04:00
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.
This commit is contained in:
parent
97a8c79006
commit
7296971b10
@ -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
|
||||
|
@ -1683,6 +1683,31 @@ end:
|
||||
event_config_free(cfg);
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
@ -1692,30 +1717,18 @@ methodname_to_envvar(const char *mname, char *buf, size_t buflen)
|
||||
*cp = toupper(*cp);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
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);
|
||||
}
|
||||
static void unsetenv(const char *k)
|
||||
{
|
||||
char b[256];
|
||||
evutil_snprintf(b, sizeof(b), "%s=",k);
|
||||
putenv(b);
|
||||
}
|
||||
#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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user