From 309711025bdb9864511a9e724d6c8b4034a2243c Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 11 Feb 2012 16:17:13 +0900 Subject: [PATCH 1/7] Cleaned up some code. --- src/command_ip.cc | 9 ++++++--- src/command_network.cc | 2 -- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/command_ip.cc b/src/command_ip.cc index b92547df..55d065fc 100644 --- a/src/command_ip.cc +++ b/src/command_ip.cc @@ -234,9 +234,12 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) { void initialize_command_ip() { - CMD2_ANY_STRING ("ip_tables.insert_table", std::bind(&apply_ip_tables_insert_table, std::placeholders::_2)); - CMD2_ANY_LIST ("ip_tables.get", std::bind(&apply_ip_tables_get, std::placeholders::_2)); - CMD2_ANY_LIST ("ip_tables.add_address", std::bind(&apply_ip_tables_add_address, std::placeholders::_2)); + CMD2_ANY ("strings.ip_filter", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_FILTER)); + CMD2_ANY ("strings.ip_tos", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_TOS)); + + CMD2_ANY_STRING ("ip_tables.insert_table", std::bind(&apply_ip_tables_insert_table, std::placeholders::_2)); + CMD2_ANY_LIST ("ip_tables.get", std::bind(&apply_ip_tables_get, std::placeholders::_2)); + CMD2_ANY_LIST ("ip_tables.add_address", std::bind(&apply_ip_tables_add_address, std::placeholders::_2)); CMD2_ANY ("ipv4_filter.size_data", std::bind(&apply_ipv4_filter_size_data)); CMD2_ANY_STRING ("ipv4_filter.get", std::bind(&apply_ipv4_filter_get, std::placeholders::_2)); diff --git a/src/command_network.cc b/src/command_network.cc index b513b068..ca2911b9 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -238,8 +238,6 @@ initialize_command_network() { CMD2_ANY ("strings.connection_type", std::bind(&torrent::option_list_strings, torrent::OPTION_CONNECTION_TYPE)); CMD2_ANY ("strings.encryption", std::bind(&torrent::option_list_strings, torrent::OPTION_ENCRYPTION)); - CMD2_ANY ("strings.ip_filter", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_FILTER)); - CMD2_ANY ("strings.ip_tos", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_TOS)); CMD2_VAR_BOOL ("log.handshake", false); From 46320533012f6db6ec03555702d798a0d737c44b Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 11 Feb 2012 18:52:46 +0900 Subject: [PATCH 2/7] Added 'ip_tables.size_data'. --- doc/manual/ip_filtering.tex | 85 +++++++++++++++++++++++++++++++++++++ src/command_ip.cc | 11 +++++ 2 files changed, 96 insertions(+) create mode 100644 doc/manual/ip_filtering.tex diff --git a/doc/manual/ip_filtering.tex b/doc/manual/ip_filtering.tex new file mode 100644 index 00000000..976b31d2 --- /dev/null +++ b/doc/manual/ip_filtering.tex @@ -0,0 +1,85 @@ +\section(IP filtering} + +\subsection{Introduction} + +\subsection{Make a new ip table} + +\begin{verbatim} +ip_tables.insert_table = +\end{verbatim} + +Create a new empty table with the name 'table\_name', with the default +value returned being $0$. + +There is currently no use of the generic ip tables commands. + + +\subsection{Add a new address block} + +\begin{verbatim} +ip_tables.add_address = , 10.0.0.0/8, +\end{verbatim} + +Set for all addresses in the address block, overwriting prior +values. + + +\subsection{Add a new address block} + +\begin{verbatim} +ip_tables.load = , ~/foo.txt, +\end{verbatim} + +Set for all addresses in the file 'foo.txt' separated by +newline, similar to 'add\_address'. + + +\subsection{Get value for address} + +\begin{verbatim} +ip_tables.get = , 10.10.10.10 +\end{verbatim} + +Returns the value set for an address, or the address block it belongs +to. The default is $0$. + + +\subsection{Size of data structures} + +\begin{verbatim} +ip_tables.size_data = +\end{verbatim} + +Returns the size in bytes of all data structures for this table, +excluding the root class object itself. Note that the in-memory table +is dynamically consolidated, as such memory use will always be based +on actual fragmentation. + +The table is a b-tree with 1024 nodes per branch. + + +\subsection{IPv4 filtering table} + +\begin{verbatim} +ipv4_filter.add_address = 10.0.0.0/8, unwanted +ipv4_filter.add_address = 11.0.0.0/8, preferred +ipv4_filter.load = ~/filters.txt, unwanted +ipv4_filter.get = 10.10.10.10 +ipv4_filter.size_data = +\end{verbatim} + +The main ip filter, currently supporting 'unwanted' (do not allow +connections) and 'preferred' (currently used only in private code). + + + +\subsection{Constants} + +\begin{verbatim} +strings.ip_filter = +=> +{ "unwanted", PeerInfo::flag_unwanted }, +{ "preferred", PeerInfo::flag_preferred }, +\end{verbatim} + +Constants used by ipv4_filter values. diff --git a/src/command_ip.cc b/src/command_ip.cc index 55d065fc..3b066e08 100644 --- a/src/command_ip.cc +++ b/src/command_ip.cc @@ -88,6 +88,16 @@ apply_ip_tables_insert_table(const std::string& args) { return torrent::Object(); } +torrent::Object +apply_ip_tables_size_data(const std::string& args) { + rpc::ip_table_list::const_iterator itr = ip_tables.find(args); + + if (itr != ip_tables.end()) + throw torrent::input_error("IP table does not exist."); + + return itr->table.sizeof_data(); +} + torrent::Object apply_ip_tables_get(const torrent::Object::list_type& args) { if (args.size() != 2) @@ -238,6 +248,7 @@ initialize_command_ip() { CMD2_ANY ("strings.ip_tos", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_TOS)); CMD2_ANY_STRING ("ip_tables.insert_table", std::bind(&apply_ip_tables_insert_table, std::placeholders::_2)); + CMD2_ANY_STRING ("ip_tables.size_data", std::bind(&apply_ip_tables_size_data, std::placeholders::_2)); CMD2_ANY_LIST ("ip_tables.get", std::bind(&apply_ip_tables_get, std::placeholders::_2)); CMD2_ANY_LIST ("ip_tables.add_address", std::bind(&apply_ip_tables_add_address, std::placeholders::_2)); From ba30dcd7cf9002d1e743d513219c3510aa97ea47 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 11 Feb 2012 19:14:22 +0900 Subject: [PATCH 3/7] Added names to threads. --- src/thread_main.h | 2 ++ src/thread_worker.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/thread_main.h b/src/thread_main.h index 41b7306d..39a7112e 100644 --- a/src/thread_main.h +++ b/src/thread_main.h @@ -47,6 +47,8 @@ public: ThreadMain() {} ~ThreadMain(); + const char* name() const { return "main_rtorrent"; } + virtual void init_thread(); private: diff --git a/src/thread_worker.h b/src/thread_worker.h index eba97ac4..e3a9f06a 100644 --- a/src/thread_worker.h +++ b/src/thread_worker.h @@ -53,6 +53,8 @@ public: ThreadWorker(); ~ThreadWorker(); + const char* name() const { return "worker_rtorrent"; } + virtual void init_thread(); rpc::SCgi* scgi() { return m_safe.scgi; } From 9ad22ab8ff177ebdc6575e1c756ec1a157b8bed6 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sun, 12 Feb 2012 15:11:26 +0900 Subject: [PATCH 4/7] Fixed log syntax. --- src/core/download_list.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/download_list.cc b/src/core/download_list.cc index 98b152c5..1f6a2db1 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -429,7 +429,7 @@ void DownloadList::pause(Download* download, int flags) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "->download_list: Pausing download: flags%0x.", flags); + lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "->download_list: Pausing download: flags:%0x.", flags); try { From 47125b9c385e607a413cb8d64ce353f3e52ed380 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sun, 12 Feb 2012 21:58:16 +0900 Subject: [PATCH 5/7] Moved main thread object to libtorrent. --- src/Makefile.am | 2 -- src/control.cc | 4 +-- src/core/curl_socket.cc | 15 ++++++----- src/globals.cc | 2 -- src/globals.h | 3 --- src/main.cc | 45 +++++++++++++++++--------------- src/thread_base.cc | 3 ++- src/thread_main.cc | 58 ----------------------------------------- src/thread_main.h | 57 ---------------------------------------- 9 files changed, 36 insertions(+), 153 deletions(-) delete mode 100644 src/thread_main.cc delete mode 100644 src/thread_main.h diff --git a/src/Makefile.am b/src/Makefile.am index 33ab8891..5be6527a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,8 +34,6 @@ libsub_root_a_SOURCES = \ signal_handler.h \ thread_base.cc \ thread_base.h \ - thread_main.cc \ - thread_main.h \ thread_worker.cc \ thread_worker.h diff --git a/src/control.cc b/src/control.cc index 17aa6e81..29603594 100644 --- a/src/control.cc +++ b/src/control.cc @@ -114,7 +114,7 @@ Control::initialize() { m_ui->init(this); - m_inputStdin->insert(main_thread->poll()); + m_inputStdin->insert(torrent::main_thread()->poll()); } void @@ -124,7 +124,7 @@ Control::cleanup() { priority_queue_erase(&taskScheduler, &m_taskShutdown); - m_inputStdin->remove(main_thread->poll()); + m_inputStdin->remove(torrent::main_thread()->poll()); m_core->download_store()->disable(); diff --git a/src/core/curl_socket.cc b/src/core/curl_socket.cc index b8587edc..03b04e5f 100644 --- a/src/core/curl_socket.cc +++ b/src/core/curl_socket.cc @@ -41,6 +41,7 @@ #include #include +#include #include "control.h" @@ -69,22 +70,22 @@ CurlSocket::receive_socket(void* easy_handle, curl_socket_t fd, int what, void* if (socket == NULL) { socket = stack->new_socket(fd); - main_thread->poll()->open(socket); + torrent::main_thread()->poll()->open(socket); // No interface for libcurl to signal when it's interested in error events. // Assume that hence it must always be interested in them. - main_thread->poll()->insert_error(socket); + torrent::main_thread()->poll()->insert_error(socket); } if (what == CURL_POLL_NONE || what == CURL_POLL_OUT) - main_thread->poll()->remove_read(socket); + torrent::main_thread()->poll()->remove_read(socket); else - main_thread->poll()->insert_read(socket); + torrent::main_thread()->poll()->insert_read(socket); if (what == CURL_POLL_NONE || what == CURL_POLL_IN) - main_thread->poll()->remove_write(socket); + torrent::main_thread()->poll()->remove_write(socket); else - main_thread->poll()->insert_write(socket); + torrent::main_thread()->poll()->insert_write(socket); return 0; } @@ -99,7 +100,7 @@ CurlSocket::close() { if (m_fileDesc == -1) throw torrent::internal_error("CurlSocket::close() m_fileDesc == -1."); - main_thread->poll()->closed(this); + torrent::main_thread()->poll()->closed(this); m_fileDesc = -1; } diff --git a/src/globals.cc b/src/globals.cc index b0cb293a..a73230ef 100644 --- a/src/globals.cc +++ b/src/globals.cc @@ -43,6 +43,4 @@ rak::timer cachedTime; rpc::ip_table_list ip_tables; Control* control = NULL; -//__thread ThreadBase* main_thread = NULL; -ThreadMain* main_thread = NULL; ThreadWorker* worker_thread = NULL; diff --git a/src/globals.h b/src/globals.h index 2faea757..69d01f3f 100644 --- a/src/globals.h +++ b/src/globals.h @@ -41,7 +41,6 @@ #include #include "thread_base.h" -#include "thread_main.h" #include "thread_worker.h" #include "rpc/ip_table_list.h" @@ -57,8 +56,6 @@ extern rak::timer cachedTime; extern rpc::ip_table_list ip_tables; extern Control* control; -// extern __thread ThreadBase* main_thread; // Only use for worker threads for now. -extern ThreadMain* main_thread; extern ThreadWorker* worker_thread; #endif diff --git a/src/main.cc b/src/main.cc index 435c70e1..4cb89286 100644 --- a/src/main.cc +++ b/src/main.cc @@ -77,7 +77,6 @@ #include "signal_handler.h" #include "option_parser.h" -#include "thread_main.h" #include "thread_worker.h" void handle_sigbus(int signum, siginfo_t* sa, void* ptr); @@ -150,14 +149,29 @@ load_arg_torrents(Control* c, char** first, char** last) { } } -static inline rak::timer +static uint64_t client_next_timeout(Control* c) { if (taskScheduler.empty()) - return c->is_shutdown_started() ? rak::timer::from_milliseconds(100) : rak::timer::from_seconds(60); + return (c->is_shutdown_started() ? rak::timer::from_milliseconds(100) : rak::timer::from_seconds(60)).usec(); else if (taskScheduler.top()->time() <= cachedTime) return 0; else - return taskScheduler.top()->time() - cachedTime; + return (taskScheduler.top()->time() - cachedTime).usec(); +} + +static void +client_perform() { + // Use throw exclusively. + if (control->is_shutdown_completed()) + throw torrent::shutdown_exception(); + + if (control->is_shutdown_received()) + control->handle_shutdown(); + + control->inc_tick(); + + cachedTime = rak::timer::current(); + rak::priority_queue_perform(&taskScheduler, cachedTime); } int @@ -171,9 +185,6 @@ main(int argc, char** argv) { control = new Control; - main_thread = new ThreadMain(); - main_thread->init_thread(); - worker_thread = new ThreadWorker(); worker_thread->init_thread(); @@ -195,7 +206,11 @@ main(int argc, char** argv) { SignalHandler::set_handler(SIGUSR1, sigc::ptr_fun(&do_nothing)); torrent::Poll::slot_create_poll() = std::tr1::bind(&core::create_poll); - torrent::initialize(main_thread->poll()); + torrent::initialize(); + + torrent::main_thread()->init_thread(); + torrent::main_thread()->slot_do_work() = tr1::bind(&client_perform); + torrent::main_thread()->slot_next_timeout() = tr1::bind(&client_next_timeout, control); // Initialize option handlers after libtorrent to ensure // torrent::ConnectionManager* are valid etc. @@ -856,18 +871,7 @@ main(int argc, char** argv) { worker_thread->start_thread(); - while (!control->is_shutdown_completed()) { - if (control->is_shutdown_received()) - control->handle_shutdown(); - - control->inc_tick(); - - cachedTime = rak::timer::current(); - rak::priority_queue_perform(&taskScheduler, cachedTime); - - // Do shutdown check before poll, not after. - main_thread->poll()->do_poll(client_next_timeout(control).usec()); - } + torrent::thread_base::event_loop(torrent::main_thread()); control->core()->download_list()->session_save(); control->cleanup(); @@ -883,7 +887,6 @@ main(int argc, char** argv) { delete control; delete worker_thread; - delete main_thread; return 0; } diff --git a/src/thread_base.cc b/src/thread_base.cc index 0640cac6..19dab3b0 100644 --- a/src/thread_base.cc +++ b/src/thread_base.cc @@ -46,6 +46,7 @@ #include #include #include +#include #include #include "globals.h" @@ -167,7 +168,7 @@ ThreadBase::interrupt_main_polling() { int sleep_length = 0; while (ThreadBase::is_main_polling()) { - pthread_kill(main_thread->m_thread, SIGUSR1); + pthread_kill(torrent::main_thread()->pthread(), SIGUSR1); if (!ThreadBase::is_main_polling()) return; diff --git a/src/thread_main.cc b/src/thread_main.cc deleted file mode 100644 index 09c78989..00000000 --- a/src/thread_main.cc +++ /dev/null @@ -1,58 +0,0 @@ -// rTorrent - BitTorrent library -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include "thread_main.h" -#include "globals.h" - -#include -#include - -ThreadMain::~ThreadMain() { -} - -void -ThreadMain::init_thread() { - // The main thread always holds the lock while running. - acquire_global_lock(); - - m_poll = core::create_poll(); - m_poll->set_flags(torrent::Poll::flag_waive_global_lock); - - m_state = STATE_INITIALIZED; - m_thread = pthread_self(); -} diff --git a/src/thread_main.h b/src/thread_main.h deleted file mode 100644 index 39a7112e..00000000 --- a/src/thread_main.h +++ /dev/null @@ -1,57 +0,0 @@ -// rTorrent - BitTorrent library -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#ifndef RTORRENT_THREAD_MAIN_H -#define RTORRENT_THREAD_MAIN_H - -#include "thread_base.h" - -// Check if cacheline aligned with inheritance ends up taking two -// cachelines. - -class lt_cacheline_aligned ThreadMain : public ThreadBase { -public: - ThreadMain() {} - ~ThreadMain(); - - const char* name() const { return "main_rtorrent"; } - - virtual void init_thread(); - -private: -}; - -#endif From f1852cd22274d9c6223bb2ba99f1ab27e894bc4b Mon Sep 17 00:00:00 2001 From: Extravagant Date: Sun, 12 Feb 2012 22:23:40 +0000 Subject: [PATCH 6/7] Updated with AC_LANG_SOURCE directives Please see this informative thread on bug-autoconf: http://www.mail-archive.com/bug-autoconf@gnu.org/msg03052.html --- scripts/attributes.m4 | 28 +++++++++++++------------- scripts/checks.m4 | 36 ++++++++++++++++----------------- scripts/common.m4 | 47 +++++++++++++++++++++---------------------- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/scripts/attributes.m4 b/scripts/attributes.m4 index 183d48b9..b121fcdc 100644 --- a/scripts/attributes.m4 +++ b/scripts/attributes.m4 @@ -3,10 +3,10 @@ AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [ AC_CACHE_CHECK([if compiler supports __attribute__((constructor))], [cc_cv_attribute_constructor], - [AC_COMPILE_IFELSE([ + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ void ctor() __attribute__((constructor)); void ctor() { }; - ], + ])], [cc_cv_attribute_constructor=yes], [cc_cv_attribute_constructor=no]) ]) @@ -23,9 +23,9 @@ AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [ AC_DEFUN([CC_ATTRIBUTE_FORMAT], [ AC_CACHE_CHECK([if compiler supports __attribute__((format(printf, n, n)))], [cc_cv_attribute_format], - [AC_COMPILE_IFELSE([ + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { } - ], + ])], [cc_cv_attribute_format=yes], [cc_cv_attribute_format=no]) ]) @@ -42,9 +42,9 @@ AC_DEFUN([CC_ATTRIBUTE_FORMAT], [ AC_DEFUN([CC_ATTRIBUTE_INTERNAL], [ AC_CACHE_CHECK([if compiler supports __attribute__((visibility("internal")))], [cc_cv_attribute_internal], - [AC_COMPILE_IFELSE([ + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ void __attribute__((visibility("internal"))) internal_function() { } - ], + ])], [cc_cv_attribute_internal=yes], [cc_cv_attribute_internal=no]) ]) @@ -66,9 +66,9 @@ AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [ AC_CACHE_CHECK([if compiler supports __attribute__((visibility("default")))], [cc_cv_attribute_visibility], - [AC_COMPILE_IFELSE([ + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ void __attribute__((visibility("default"))) visibility_function() { } - ], + ])], [cc_cv_attribute_visibility=yes], [cc_cv_attribute_visibility=no]) ]) @@ -90,10 +90,10 @@ AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [ AC_DEFUN([CC_ATTRIBUTE_NONNULL], [ AC_CACHE_CHECK([if compiler supports __attribute__((nonnull()))], [cc_cv_attribute_nonnull], - [AC_COMPILE_IFELSE([ + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ void some_function(void *foo, void *bar) __attribute__((nonnull())); void some_function(void *foo, void *bar) { } - ], + ])], [cc_cv_attribute_nonnull=yes], [cc_cv_attribute_nonnull=no]) ]) @@ -110,9 +110,9 @@ AC_DEFUN([CC_ATTRIBUTE_NONNULL], [ AC_DEFUN([CC_ATTRIBUTE_UNUSED], [ AC_CACHE_CHECK([if compiler supports __attribute__((unused))], [cc_cv_attribute_unused], - [AC_COMPILE_IFELSE([ + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ void some_function(void *foo, __attribute__((unused)) void *bar); - ], + ])], [cc_cv_attribute_unused=yes], [cc_cv_attribute_unused=no]) ]) @@ -129,13 +129,13 @@ AC_DEFUN([CC_ATTRIBUTE_UNUSED], [ AC_DEFUN([CC_FUNC_EXPECT], [ AC_CACHE_CHECK([if compiler has __builtin_expect function], [cc_cv_func_expect], - [AC_COMPILE_IFELSE([ + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ int some_function() { int a = 3; return (int)__builtin_expect(a, 3); } - ], + ])], [cc_cv_func_expect=yes], [cc_cv_func_expect=no]) ]) diff --git a/scripts/checks.m4 b/scripts/checks.m4 index f32bd3b0..9bc7a85d 100644 --- a/scripts/checks.m4 +++ b/scripts/checks.m4 @@ -1,15 +1,15 @@ AC_DEFUN([TORRENT_CHECK_XFS], [ AC_MSG_CHECKING(for XFS support) - AC_COMPILE_IFELSE( - [[#include + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include #include int main() { struct xfs_flock64 l; ioctl(0, XFS_IOC_RESVSP64, &l); return 0; } - ]], + ])], [ AC_DEFINE(USE_XFS, 1, Use XFS filesystem stuff.) AC_MSG_RESULT(yes) @@ -46,13 +46,13 @@ AC_DEFUN([TORRENT_WITH_XFS], [ AC_DEFUN([TORRENT_CHECK_EPOLL], [ AC_MSG_CHECKING(for epoll support) - AC_COMPILE_IFELSE( - [[#include + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include int main() { int fd = epoll_create(100); return 0; } - ]], + ])], [ AC_DEFINE(USE_EPOLL, 1, Use epoll.) AC_MSG_RESULT(yes) @@ -77,14 +77,14 @@ AC_DEFUN([TORRENT_WITHOUT_EPOLL], [ AC_DEFUN([TORRENT_CHECK_KQUEUE], [ AC_MSG_CHECKING(for kqueue support) - AC_LINK_IFELSE( - [[#include /* Because OpenBSD's sys/event.h fails to compile otherwise. Yeah... */ + AC_LINK_IFELSE([AC_LANG_SOURCE([ + #include /* Because OpenBSD's sys/event.h fails to compile otherwise. Yeah... */ #include int main() { int fd = kqueue(); return 0; } - ]], + ])], [ AC_DEFINE(USE_KQUEUE, 1, Use kqueue.) AC_MSG_RESULT(yes) @@ -96,8 +96,8 @@ AC_DEFUN([TORRENT_CHECK_KQUEUE], [ AC_DEFUN([TORRENT_CHECK_KQUEUE_SOCKET_ONLY], [ AC_MSG_CHECKING(whether kqueue supports pipes and ptys) - AC_RUN_IFELSE( - [[#include + AC_RUN_IFELSE([AC_LANG_SOURCE([ + #include #include #include #include @@ -122,7 +122,7 @@ AC_DEFUN([TORRENT_CHECK_KQUEUE_SOCKET_ONLY], [ if ((n = kevent(kfd, NULL, 0, ev_out, 2, &ts)) < 1) return 9; return 0; } - ]], + ])], [ AC_MSG_RESULT(yes) ], [ @@ -364,11 +364,11 @@ AC_DEFUN([TORRENT_CHECK_TR1], [ AC_LANG_PUSH(C++) AC_MSG_CHECKING(for TR1 support) - AC_COMPILE_IFELSE( - [[#include + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include class Foo; typedef std::tr1::unordered_map Bar; - ]], + ])], [ AC_MSG_RESULT(yes) AC_DEFINE(HAVE_TR1, 1, Define to 1 if your C++ library supports the extensions from Technical Report 1) @@ -385,14 +385,14 @@ AC_DEFUN([TORRENT_CHECK_CXX11], [ AC_LANG_PUSH(C++) AC_MSG_CHECKING(for C++11 support) - AC_COMPILE_IFELSE( - [[#include + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include #include class Foo; typedef std::unordered_map Bar; union test { Bar b1; }; - ]], + ])], [ AC_MSG_RESULT(yes) AC_DEFINE(HAVE_CXX11, 1, Define to 1 if your C++ compiler has support for C++11.) diff --git a/scripts/common.m4 b/scripts/common.m4 index f875c71a..ad4edad4 100644 --- a/scripts/common.m4 +++ b/scripts/common.m4 @@ -99,11 +99,11 @@ AC_DEFUN([TORRENT_OTFD], [ AC_LANG_PUSH(C++) AC_MSG_CHECKING(for proper overloaded template function disambiguation) - AC_COMPILE_IFELSE( - [[template void f(T&) {} + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + template void f(T&) {} template void f(T*) {} int main() { int *i = 0; f(*i); f(i); } - ]], + ])], [ AC_MSG_RESULT(yes) ], [ @@ -119,24 +119,24 @@ AC_DEFUN([TORRENT_MINCORE_SIGNEDNESS], [ AC_LANG_PUSH(C++) AC_MSG_CHECKING(signedness of mincore parameter) - AC_COMPILE_IFELSE( - [[#include + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include #include #include void f() { mincore((char*)0, 0, (unsigned char*)0); } - ]], + ])], [ AC_DEFINE(USE_MINCORE, 1, Use mincore) AC_DEFINE(USE_MINCORE_UNSIGNED, 1, use unsigned char* in mincore) AC_MSG_RESULT(unsigned) ], [ - AC_COMPILE_IFELSE( - [[#include + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include #include #include void f() { mincore((char*)0, 0, (char*)0); } - ]], + ])], [ AC_DEFINE(USE_MINCORE, 1, Use mincore) AC_DEFINE(USE_MINCORE_UNSIGNED, 0, use char* in mincore) @@ -168,11 +168,11 @@ AC_DEFUN([TORRENT_MINCORE], [ AC_DEFUN([TORRENT_CHECK_MADVISE], [ AC_MSG_CHECKING(for madvise) - AC_COMPILE_IFELSE( - [[#include + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include #include void f() { static char test[1024]; madvise((void *)test, sizeof(test), MADV_NORMAL); } - ]], + ])], [ AC_MSG_RESULT(yes) AC_DEFINE(USE_MADVISE, 1, Use madvise) @@ -184,10 +184,9 @@ AC_DEFUN([TORRENT_CHECK_MADVISE], [ AC_DEFUN([TORRENT_CHECK_POPCOUNT], [ AC_MSG_CHECKING(for __builtin_popcount) - AC_COMPILE_IFELSE( - [[ + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ void f() { __builtin_popcount(0); } - ]], + ])], [ AC_MSG_RESULT(yes) AC_DEFINE(USE_BUILTIN_POPCOUNT, 1, Use __builtin_popcount.) @@ -199,12 +198,12 @@ AC_DEFUN([TORRENT_CHECK_POPCOUNT], [ AC_DEFUN([TORRENT_CHECK_CACHELINE], [ AC_MSG_CHECKING(for cacheline) - AC_COMPILE_IFELSE( - [[#include + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include #include void* vptr __cacheline_aligned; void f() { posix_memalign(&vptr, SMP_CACHE_BYTES, 42); } - ]], + ])], [ AC_MSG_RESULT(found builtin) dnl AC_DEFINE(LT_SMP_CACHE_BYTES, SMP_CACHE_BYTES, Largest L1 cache size we know of, should work on all archs.) @@ -224,10 +223,10 @@ dnl Need to fix this so that it uses the stuff defined by the system. AC_DEFUN([TORRENT_CHECK_EXECINFO], [ AC_MSG_CHECKING(for execinfo.h) - AC_RUN_IFELSE( - [[#include + AC_RUN_IFELSE([AC_LANG_SOURCE([ + #include int main() { backtrace((void**)0, 0); backtrace_symbols((char**)0, 0); return 0;} - ]], + ])], [ AC_MSG_RESULT(yes) AC_DEFINE(USE_EXECINFO, 1, Use execinfo.h) @@ -239,8 +238,8 @@ AC_DEFUN([TORRENT_CHECK_EXECINFO], [ AC_DEFUN([TORRENT_CHECK_ALIGNED], [ AC_MSG_CHECKING(the byte alignment) - AC_RUN_IFELSE( - [[#include + AC_RUN_IFELSE([AC_LANG_SOURCE([ + #include int main() { char buf[8] = { 0, 0, 0, 0, 1, 0, 0, 0 }; int i; @@ -248,7 +247,7 @@ AC_DEFUN([TORRENT_CHECK_ALIGNED], [ if (*(uint32_t*)(buf + i) == 0) return -1; return 0; } - ]], + ])], [ AC_MSG_RESULT(none needed) ], [ From 4f601fda79559485db5f707e4fa3f85a7db98fe3 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Mon, 13 Feb 2012 17:15:54 +0900 Subject: [PATCH 7/7] Use intermediate std::string to store the arguments to work around a possible bug. --- src/command_ip.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/command_ip.cc b/src/command_ip.cc index 3b066e08..0dc590b4 100644 --- a/src/command_ip.cc +++ b/src/command_ip.cc @@ -197,12 +197,14 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) { if (args.size() != 2) throw torrent::input_error("Incorrect number of arguments."); - std::fstream file(rak::path_expand(args.front().as_string()).c_str(), std::ios::in); + std::string filename = args.front().as_string(); + std::string value_name = args.back().as_string(); + int value = torrent::option_find_string(torrent::OPTION_IP_FILTER, value_name.c_str()); + + std::fstream file(rak::path_expand(filename).c_str(), std::ios::in); if (!file.is_open()) - throw torrent::input_error("Could not open ip filter file: " + args.front().as_string()); - - int value = torrent::option_find_string(torrent::OPTION_IP_FILTER, args.back().as_string().c_str()); + throw torrent::input_error("Could not open ip filter file: " + filename); char buffer[4096]; unsigned int lineNumber = 0; @@ -228,16 +230,16 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) { } } catch (torrent::input_error& e) { - snprintf(buffer, 2048, "Error in ip filter file: %s:%u: %s", args.front().as_string().c_str(), lineNumber, e.what()); + snprintf(buffer, 2048, "Error in ip filter file: %s:%u: %s", filename.c_str(), lineNumber, e.what()); throw torrent::input_error(buffer); } lt_log_print(torrent::LOG_CONNECTION_INFO, "Loaded %u %s address blocks (%u kb in-memory) from '%s'.", lineNumber, - args.back().as_string().c_str(), + value_name.c_str(), torrent::PeerList::ipv4_filter()->sizeof_data() / 1024, - args.front().as_string().c_str()); + filename.c_str()); return torrent::Object(); }