#include "mem_config.h"
+#include "test/lib/env.hpp"
+#include "test/lib/random.hpp"
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <unistd.h>
-#if HAVE_SETENV
-# define SET_ENV(n, k, v) setenv(k, v, 0)
-#else // !HAVE_SETENV
-# define SET_ENV(n, k, v) static char n ## _env[] = k "=" v; putenv(n ## _env)
-#endif
-
static void sigchld(int, siginfo_t *si, void *) {
switch (si->si_code) {
case CLD_EXITED:
}
static inline void setup_signals() {
- struct sigaction sa;
+ cout << " - Setting up signals ... ";
+ struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_NOCLDSTOP | SA_RESTART | SA_SIGINFO | SA_NODEFER;
sa.sa_sigaction = sigchld;
if (0 > sigaction(SIGCHLD, &sa, nullptr)) {
perror("sigaction(CHLD)");
+ } else {
+ cout << "done\n";
}
}
static inline void setup_asan(char **argv) {
const auto set = getenv("ASAN_OPTIONS");
+ cout << " - Setting up ASAN ... ";
+
if (!set || !*set) {
- SET_ENV(asan, "ASAN_OPTIONS", ASAN_OPTIONS);
+ SET_ENV_EX(asan, "ASAN_OPTIONS", ASAN_OPTIONS, 0);
+ cout << "re-exec\n";
execvp(argv[0], argv);
perror("exec()");
}
+ cout << "done\n";
}
#else
-# define setup_asan(a)
+# define setup_asan(a) (void) a
#endif
#if LIBMEMCACHED_WITH_SASL_SUPPORT
static inline void setup_sasl() {
- SET_ENV(sasl_pwdb, "MEMCACHED_SASL_PWDB", LIBMEMCACHED_WITH_SASL_PWDB);
- SET_ENV(sasl_conf, "SASL_CONF_PATH", LIBMEMCACHED_WITH_SASL_CONF);
+ cout << " - Setting up SASL ... ";
+
+ SET_ENV_EX(sasl_pwdb, "MEMCACHED_SASL_PWDB", LIBMEMCACHED_WITH_SASL_PWDB, 0);
+ SET_ENV_EX(sasl_conf, "SASL_CONF_PATH", LIBMEMCACHED_WITH_SASL_CONF, 0);
+
+ cout << "done\n";
}
#else
# define setup_sasl()
#endif
+static inline void setup_random() {
+ cout << " - Setting up RNG ... ";
+
+ random_setup();
+
+ cout << "done\n";
+}
+
int setup(int &, char ***argv) {
+ cout << "Starting " << **argv << " (pid=" << getpid() << ") ... \n";
+
setup_signals();
+ setup_random();
setup_asan(*argv);
setup_sasl();