From 6137bcf5737300606b7adee6530903bf815e8103 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Thu, 28 May 2015 15:01:51 +0200 Subject: [PATCH] changed paths of DNS cache (now in /var/cache) and dumped packets; dump only if /datastore/pingcheck.broken exists --- src/config/option/dnscachefileoption.cpp | 2 +- src/icmp/icmppacketfactory.cpp | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/config/option/dnscachefileoption.cpp b/src/config/option/dnscachefileoption.cpp index 3dd97d3..d4c910c 100644 --- a/src/config/option/dnscachefileoption.cpp +++ b/src/config/option/dnscachefileoption.cpp @@ -39,7 +39,7 @@ using I2n::Logger::GlobalLogger; DnsCacheFileOption::DnsCacheFileOption() : ConfigurationOption( "dns-cache-file", - value()->default_value( "/etc/pingcheck_dns_cache.xml" ), + value()->default_value( "/var/cache/pingcheck_dns_cache.xml" ), "Name of the DNS cache file." ) { diff --git a/src/icmp/icmppacketfactory.cpp b/src/icmp/icmppacketfactory.cpp index 5024789..ae972fa 100644 --- a/src/icmp/icmppacketfactory.cpp +++ b/src/icmp/icmppacketfactory.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include "boost_assert_handler.h" @@ -51,8 +52,9 @@ using I2n::Logger::GlobalLogger; //----------------------------------------------------------------------------- // set default value -DumpMode IcmpPacketFactory::PacketDumpMode = DUMP_IF_ERROR; -std::string IcmpPacketFactory::DumpFilePrefix = "/tmp/icmp_"; +DumpMode IcmpPacketFactory::PacketDumpMode = DUMP_ALWAYS; //DUMP_IF_ERROR; +std::string IcmpPacketFactory::DumpFilePrefix = + "/datastore/pingcheck.broken/icmp_"; /** * @brief Creates an ICMP packet from the input stream @c std::istream. @@ -202,6 +204,14 @@ void IcmpPacketFactory::dump_packet(const std::string &data) std::stringstream temp_name; temp_name << DumpFilePrefix << capture_time << ".pcap.XXXXXX"; + // check if directory exists + if ( !I2n::path_exists( I2n::dirname(temp_name.str()) ) ) + { + GlobalLogger.debug() << "Not saving packet data because directory " + << I2n::dirname(temp_name.str()) << " does not exist"; + return; + } + // open file I2n::tmpfstream temp_stream; if ( !temp_stream.open(temp_name.str()) ) @@ -227,6 +237,14 @@ void IcmpPacketFactory::dump_packet(const IcmpPacket &packet) std::stringstream temp_name; temp_name << DumpFilePrefix << capture_time << ".pcap.XXXXXX"; + // check if directory exists + if ( !I2n::path_exists( I2n::dirname(temp_name.str()) ) ) + { + GlobalLogger.debug() << "Not saving packet data because directory " + << I2n::dirname(temp_name.str()) << " does not exist"; + return; + } + // open file I2n::tmpfstream temp_stream; if ( !temp_stream.open(temp_name.str()) ) -- 1.7.1