From e2d746871d0fc05d280e74585289a14c5570dfdd Mon Sep 17 00:00:00 2001 From: James Peach Date: Wed, 10 Aug 2016 14:10:17 -0700 Subject: [PATCH 1/2] TS-4728: Return bool from LogHost boolean functions. (cherry picked from commit 0a12b2682cc718057ee33d0642dfe009c5574004) Conflicts: proxy/logging/LogHost.cc --- proxy/logging/LogConfig.cc | 2 +- proxy/logging/LogHost.cc | 39 +++++++++++++++++++------------------- proxy/logging/LogHost.h | 6 +++--- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/proxy/logging/LogConfig.cc b/proxy/logging/LogConfig.cc index 2bff8329501..0590fc3ef9a 100644 --- a/proxy/logging/LogConfig.cc +++ b/proxy/logging/LogConfig.cc @@ -1471,7 +1471,7 @@ LogConfig::read_xml_log_config() while (failover_str = failover_tok.getNext(), failover_str != 0) { LogHost *lh = new LogHost(obj->get_full_filename(), obj->get_signature()); - if (lh->set_name_or_ipstr(failover_str)) { + if (lh->set_name_or_ipstr(failover_str) == false) { Warning("Could not set \"%s\" as collation host", host); delete lh; } else if (!prev) { diff --git a/proxy/logging/LogHost.cc b/proxy/logging/LogHost.cc index 796419f4eaf..a887721cd1e 100644 --- a/proxy/logging/LogHost.cc +++ b/proxy/logging/LogHost.cc @@ -94,12 +94,12 @@ LogHost::~LogHost() // - by specifying a hostname and a port (as separate arguments). // - by specifying an ip and a port (as separate arguments). // -int -LogHost::set_name_port(char *hostname, unsigned int pt) +bool +LogHost::set_name_port(const char *hostname, unsigned int pt) { if (!hostname || hostname[0] == 0) { Note("Cannot establish LogHost with NULL hostname"); - return 1; + return false; } clear(); // remove all previous state for this LogHost @@ -109,38 +109,38 @@ LogHost::set_name_port(char *hostname, unsigned int pt) Debug("log-host", "LogHost established as %s:%u", this->name(), this->port()); - create_orphan_LogFile_object(); - return 0; + m_orphan_file = make_orphan_logfile(this, m_object_filename); + return true; } -int -LogHost::set_ipstr_port(char *ipstr, unsigned int pt) +bool +LogHost::set_ipstr_port(const char *ipstr, unsigned int pt) { if (!ipstr || ipstr[0] == 0) { Note("Cannot establish LogHost with NULL ipstr"); - return 1; + return false; } clear(); // remove all previous state for this LogHost - if (0 != m_ip.load(ipstr)) + if (0 != m_ip.load(ipstr)) { Note("Log host failed to parse IP address %s", ipstr); + } + m_port = pt; ink_strlcpy(m_ipstr, ipstr, sizeof(m_ipstr)); m_name = ats_strdup(ipstr); Debug("log-host", "LogHost established as %s:%u", name(), pt); - create_orphan_LogFile_object(); - return 0; + m_orphan_file = make_orphan_logfile(this, m_object_filename); + return true; } -int -LogHost::set_name_or_ipstr(char *name_or_ip) +bool +LogHost::set_name_or_ipstr(const char *name_or_ip) { - int retVal = 1; - - if (name_or_ip && name_or_ip[0] != 0) { + if (name_or_ip && name_or_ip[0] != '\0') { ts::ConstBuffer addr, port; if (ats_ip_parse(ts::ConstBuffer(name_or_ip, strlen(name_or_ip)), &addr, &port) == 0) { uint16_t p = port ? atoi(port.data()) : Log::config->collation_port; @@ -149,13 +149,14 @@ LogHost::set_name_or_ipstr(char *name_or_ip) // string is followed by either a nul or a colon. n[addr.size()] = 0; if (AF_UNSPEC == ats_ip_check_characters(addr)) { - retVal = set_name_port(n, p); + return set_name_port(n, p); } else { - retVal = set_ipstr_port(n, p); + return set_ipstr_port(n, p); } } } - return retVal; + + return false; } bool diff --git a/proxy/logging/LogHost.h b/proxy/logging/LogHost.h index 7425d7c804a..5eb0d91a68e 100644 --- a/proxy/logging/LogHost.h +++ b/proxy/logging/LogHost.h @@ -42,9 +42,9 @@ class LogHost LogHost(const LogHost &); ~LogHost(); - int set_name_or_ipstr(char *name_or_ipstr); - int set_ipstr_port(char *ipstr, unsigned int port); - int set_name_port(char *hostname, unsigned int port); + bool set_name_or_ipstr(const char *name_or_ipstr); + bool set_ipstr_port(const char *ipstr, unsigned int port); + bool set_name_port(const char *hostname, unsigned int port); bool connected(bool ping); bool connect(); From 8ec7dcd922493ec41318c989102717b555454a68 Mon Sep 17 00:00:00 2001 From: James Peach Date: Wed, 10 Aug 2016 14:16:16 -0700 Subject: [PATCH 2/2] TS-4728: Remove invalid LogHost assertion. (cherry picked from commit f502718abc09c66830d9dececf596e039daec422) Conflicts: proxy/logging/LogHost.cc --- proxy/logging/LogHost.cc | 41 ++++++++++++++++++++-------------------- proxy/logging/LogHost.h | 13 +++++++++++-- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/proxy/logging/LogHost.cc b/proxy/logging/LogHost.cc index a887721cd1e..8876ef2c99b 100644 --- a/proxy/logging/LogHost.cc +++ b/proxy/logging/LogHost.cc @@ -46,6 +46,25 @@ #define PING true #define NOPING false +static Ptr +make_orphan_logfile(LogHost *lh, const char *filename) +{ + const char *ext = "orphan"; + unsigned name_len = (unsigned)(strlen(filename) + strlen(lh->name()) + strlen(ext) + 16); + char *name_buf = (char *)ats_malloc(name_len); + + // NT: replace ':'s with '-'s. This change is necessary because + // NT doesn't like filenames with ':'s in them. ^_^ + snprintf(name_buf, name_len, "%s%s%s-%u.%s", filename, LOGFILE_SEPARATOR_STRING, lh->name(), lh->port(), ext); + + // XXX should check for conflicts with orphan filename + + Ptr orphan(new LogFile(name_buf, NULL, LOG_FILE_ASCII, lh->signature())); + + ats_free(name_buf); + return orphan; +} + /*------------------------------------------------------------------------- LogHost -------------------------------------------------------------------------*/ @@ -78,7 +97,7 @@ LogHost::LogHost(const LogHost &rhs) m_log_collation_client_sm(NULL) { memcpy(m_ipstr, rhs.m_ipstr, sizeof(m_ipstr)); - create_orphan_LogFile_object(); + m_orphan_file = make_orphan_logfile(this, m_object_filename); } LogHost::~LogHost() @@ -226,26 +245,6 @@ LogHost::disconnect() m_connected = false; } -void -LogHost::create_orphan_LogFile_object() -{ - delete m_orphan_file; - - const char *orphan_ext = "orphan"; - unsigned name_len = (unsigned)(strlen(m_object_filename) + strlen(name()) + strlen(orphan_ext) + 16); - char *name_buf = (char *)ats_malloc(name_len); - - // NT: replace ':'s with '-'s. This change is necessary because - // NT doesn't like filenames with ':'s in them. ^_^ - snprintf(name_buf, name_len, "%s%s%s-%u.%s", m_object_filename, LOGFILE_SEPARATOR_STRING, name(), port(), orphan_ext); - - // should check for conflicts with orphan filename - // - m_orphan_file = new LogFile(name_buf, NULL, LOG_FILE_ASCII, m_object_signature); - ink_assert(m_orphan_file != NULL); - ats_free(name_buf); -} - // // preprocess the given buffer data before sent to target host // and try to delete it when its reference become zero. diff --git a/proxy/logging/LogHost.h b/proxy/logging/LogHost.h index 5eb0d91a68e..11842c8a099 100644 --- a/proxy/logging/LogHost.h +++ b/proxy/logging/LogHost.h @@ -61,21 +61,30 @@ class LogHost // void orphan_write_and_try_delete(LogBuffer *lb); - char const * + const char * name() const { return m_name ? m_name : "UNKNOWN"; } + + uint64_t + signature() const + { + return m_object_signature; + } + IpAddr const & ip_addr() const { return m_ip; } + in_port_t port() const { return m_port; } + char const * ipstr() const { @@ -99,7 +108,6 @@ class LogHost private: void clear(); bool authenticated(); - void create_orphan_LogFile_object(); private: char *m_object_filename; @@ -143,6 +151,7 @@ class LogHostList : public LogBufferSink { return m_host_list.head; } + LogHost * next(LogHost *here) {