From fbdf9f2089a2653c8ea8150af22852ebc61ce42d Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sat, 30 Jun 2012 09:30:23 -0700 Subject: [PATCH] Update util and fix a few cppcheck warnings. --- tests/libmemcached-1.0/haldenbrand.cc | 4 ++-- tests/libmemcached-1.0/mem_functions.cc | 4 +--- tests/libmemcached-1.0/pool.cc | 2 ++ util/instance.cc | 2 -- util/logfile.cc | 1 + util/pidfile.cc | 7 ++++++- util/signal.cc | 21 ++++++++++++++++++++- util/signal.hpp | 18 +++++++++++++++++- 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/tests/libmemcached-1.0/haldenbrand.cc b/tests/libmemcached-1.0/haldenbrand.cc index cbbe88dd..a48b346a 100644 --- a/tests/libmemcached-1.0/haldenbrand.cc +++ b/tests/libmemcached-1.0/haldenbrand.cc @@ -92,13 +92,13 @@ test_return_t haldenbrand_TEST2(memcached_st *memc) test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true)); -#ifdef NOT_YET +#if 0 test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, 20 * 1024576)); test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, 20 * 1024576)); getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE); getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE); - for (x= 0, errors= 0; total < 20 * 1024576 ; x++) + for (x= 0, errors= 0; total < 20 * 1024576 ; x++); #endif size_t total_value_length= 0; diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index bfacffea..9750d44d 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -3109,11 +3109,9 @@ test_return_t enable_consistent_hsieh(memcached_st *memc) test_return_t enable_cas(memcached_st *memc) { - unsigned int set= 1; - if (libmemcached_util_version_check(memc, 1, 2, 4)) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true); return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/pool.cc b/tests/libmemcached-1.0/pool.cc index ea6501e8..6156ecad 100644 --- a/tests/libmemcached-1.0/pool.cc +++ b/tests/libmemcached-1.0/pool.cc @@ -495,6 +495,8 @@ test_return_t regression_bug_962815(memcached_st *memc) { Error << "poll() failed with:" << strerror(errno); } + test_zero(active_fd); + set_running(false); } diff --git a/util/instance.cc b/util/instance.cc index e96f414f..8b9f5ee9 100644 --- a/util/instance.cc +++ b/util/instance.cc @@ -211,7 +211,6 @@ bool Instance::run() case READING: if (operation->has_response()) { - size_t total_read; ssize_t read_length; do @@ -240,7 +239,6 @@ bool Instance::run() } operation->push(buffer, static_cast(read_length)); - total_read+= static_cast(read_length); } while (more_to_read()); } // end has_response diff --git a/util/logfile.cc b/util/logfile.cc index c63077c1..29023b6f 100644 --- a/util/logfile.cc +++ b/util/logfile.cc @@ -49,6 +49,7 @@ #include #include #include +#include namespace datadifferential { namespace util { diff --git a/util/pidfile.cc b/util/pidfile.cc index 11f7f398..c6c5b440 100644 --- a/util/pidfile.cc +++ b/util/pidfile.cc @@ -118,8 +118,13 @@ bool Pidfile::create() } } + int oflags= O_CREAT|O_WRONLY|O_TRUNC; +#ifdef HAVE_O_CLOEXEC + oflags= oflags | O_CLOEXEC; +#endif + int file; - if ((file = open(_filename.c_str(), O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU|S_IRGRP|S_IROTH)) < 0) + if ((file = open(_filename.c_str(), oflags, S_IRWXU|S_IRGRP|S_IROTH)) < 0) { std::stringstream error_stream; error_stream << "Could not open pid file for writing: " << _filename << "(" << strerror(errno) << ")"; diff --git a/util/signal.cc b/util/signal.cc index c28a4bc4..6eda5645 100644 --- a/util/signal.cc +++ b/util/signal.cc @@ -101,6 +101,19 @@ void SignalThread::test() assert(sigismember(&set, SIGUSR2)); } +void SignalThread::sighup(signal_callback_fn* arg) +{ + _sighup= arg; +} + +void SignalThread::sighup() +{ + if (_sighup) + { + _sighup(); + } +} + SignalThread::~SignalThread() { if (not is_shutdown()) @@ -142,6 +155,10 @@ static void *sig_thread(void *arg) case SIGUSR2: break; + case SIGHUP: + context->sighup(); + break; + case SIGABRT: case SIGINT: case SIGQUIT: @@ -172,7 +189,9 @@ static void *sig_thread(void *arg) SignalThread::SignalThread(bool exit_on_signal_arg) : _exit_on_signal(exit_on_signal_arg), magic_memory(MAGIC_MEMORY), - thread(pthread_self()) + __shutdown(SHUTDOWN_RUNNING), + thread(pthread_self()), + _sighup(NULL) { pthread_mutex_init(&shutdown_mutex, NULL); sigemptyset(&set); diff --git a/util/signal.hpp b/util/signal.hpp index e082d7d2..fab67be6 100644 --- a/util/signal.hpp +++ b/util/signal.hpp @@ -43,6 +43,16 @@ #include #endif +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (signal_callback_fn)(); + +#ifdef __cplusplus +} +#endif + namespace datadifferential { namespace util { @@ -59,7 +69,6 @@ class SignalThread { uint64_t magic_memory; volatile shutdown_t __shutdown; pthread_mutex_t shutdown_mutex; - pthread_t thread; public: @@ -84,6 +93,13 @@ public: void set_shutdown(shutdown_t arg); bool is_shutdown(); shutdown_t get_shutdown(); + + void sighup(); + void sighup(signal_callback_fn* arg); + +private: + pthread_t thread; + signal_callback_fn* _sighup; }; } /* namespace util */ -- 2.30.2