From 24ac12fa9cebb786966f5907d594c9506d19c29f Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 26 Mar 2012 11:15:13 -0700 Subject: [PATCH] Osx fixes. --- libtest/cmdline.cc | 6 ++++-- libtest/memcached.cc | 22 ++++++++++++++-------- libtest/server.h | 2 +- libtest/signal.cc | 4 ++++ libtest/unittest.cc | 1 - libtest/wait.h | 25 +++++++++++++++++++++++++ memcached/memcached.c | 2 ++ tests/include.am | 2 +- 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 1a13342b..b93d8aba 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -300,7 +300,7 @@ bool Application::slurp() return false; } - if (fds[0].revents == POLLIN) + if (fds[0].revents & POLLIN) { ssize_t read_length; char buffer[1024]= { 0 }; @@ -329,8 +329,10 @@ bool Application::slurp() } } - if (fds[1].revents == POLLIN) + if (fds[1].revents & POLLIN) { + stderr_fd.nonblock(); + ssize_t read_length; char buffer[1024]= { 0 }; while ((read_length= ::read(stderr_fd.fd()[0], buffer, sizeof(buffer)))) diff --git a/libtest/memcached.cc b/libtest/memcached.cc index e7c16395..9c237fdd 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -101,17 +101,21 @@ public: return _username; } + bool wait_for_pidfile() const + { + Wait wait(pid(), 4); + + return wait.successful(); + } + pid_t get_pid(bool error_is_ok) { // Memcached is slow to start, so we need to do this - if (pid_file().empty() == false) + if (error_is_ok and + wait_for_pidfile() == false) { - if (error_is_ok and - wait_for_pidfile() == false) - { - Error << "Pidfile was not found:" << pid_file(); - return -1; - } + Error << "Pidfile was not found:" << pid_file(); + return -1; } pid_t local_pid; @@ -140,15 +144,17 @@ public: bool ping() { +#if 0 // Memcached is slow to start, so we need to do this if (pid_file().empty() == false) { if (wait_for_pidfile() == false) { - Error << "Pidfile was not found:" << pid_file(); + Error << "Pidfile was not found:" << pid_file() << " :" << running(); return -1; } } +#endif memcached_return_t rc; bool ret; diff --git a/libtest/server.h b/libtest/server.h index c9700e95..68d5e226 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -207,7 +207,7 @@ public: return (_pid > 1); } - bool wait_for_pidfile() const; + virtual bool wait_for_pidfile() const; bool check_pid(pid_t pid_arg) const { diff --git a/libtest/signal.cc b/libtest/signal.cc index 266a7c4a..2fd99e07 100644 --- a/libtest/signal.cc +++ b/libtest/signal.cc @@ -143,6 +143,10 @@ static void *sig_thread(void *arg) } break; + case 0: + Error << "Inside of gdb?"; + break; + default: Error << "Signal handling thread got unexpected signal " << strsignal(sig); break; diff --git a/libtest/unittest.cc b/libtest/unittest.cc index a5860bdd..10d6c062 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -388,7 +388,6 @@ static test_return_t application_doesnotexist_BINARY(void *) const char *args[]= { "--fubar", 0 }; #if defined(TARGET_OS_OSX) && TARGET_OS_OSX test_compare(Application::INVALID, true_app.run(args)); - test_compare(Application::FAILURE, true_app.wait()); #else test_compare(Application::SUCCESS, true_app.run(args)); test_compare(Application::INVALID, true_app.wait()); diff --git a/libtest/wait.h b/libtest/wait.h index c6c3f966..f81a29ad 100644 --- a/libtest/wait.h +++ b/libtest/wait.h @@ -24,6 +24,7 @@ #include #include +#include #include @@ -63,6 +64,30 @@ public: } } + Wait(const pid_t &_pid_arg, uint32_t timeout= 6) : + _successful(false) + { + uint32_t waited; + uint32_t this_wait; + uint32_t retry; + + for (waited= 0, retry= 1; ; retry++, waited+= this_wait) + { + if (kill(_pid_arg, 0) == 0) + { + _successful= true; + break; + } + else if (waited >= timeout) + { + break; + } + + this_wait= retry * retry / 3 + 1; + libtest::dream(this_wait, 0); + } + } + bool successful() const { return _successful; diff --git a/memcached/memcached.c b/memcached/memcached.c index 7d053cce..10e89f80 100644 --- a/memcached/memcached.c +++ b/memcached/memcached.c @@ -5278,8 +5278,10 @@ int main (int argc, char **argv) { stop_assoc_maintenance_thread(); /* remove the PID file if we're a daemon */ +#if 0 if (do_daemonize) remove_pidfile(pid_file); +#endif /* Clean up strdup() call for bind() address */ if (settings.inter) free(settings.inter); diff --git a/tests/include.am b/tests/include.am index 7bc9e60b..56e71816 100644 --- a/tests/include.am +++ b/tests/include.am @@ -94,7 +94,7 @@ test-memcapable: tests/var tests/memcapable pahole-mem: tests/testapp @$(PAHOLE_COMMAND) tests/testapp -gdb-mem: tests/var tests/libmemcached-1.0/testapp +gdb-mem: tests/libmemcached-1.0/testapp @$(DEBUG_COMMAND) tests/libmemcached-1.0/testapp gdb-sasl: tests/sasl -- 2.30.2