return instance().clock_m(time);
}
+prefix_ senf::ClockService::clock_type senf::ClockService::from_time_t(time_t const & time)
+{
+ return clock( boost::posix_time::from_time_t(time) );
+}
+
+prefix_ senf::ClockService::clock_type senf::ClockService::from_timeval(timeval const & time)
+{
+ return from_time_t(time.tv_sec) + ClockService::microseconds(time.tv_usec);
+}
+
prefix_ senf::ClockService::clock_type senf::ClockService::nanoseconds(clock_type v)
{
return v;
#define HH_ClockService_ 1
// Custom includes
+#include <sys/time.h>
#include <boost/utility.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/scoped_ptr.hpp>
corresponding clock value.
\see abstime */
+ static clock_type from_time_t(time_t const & time);
+ ///< Convert legacy time_t to clock value
+ /**< This member converts an absolute time value
+ represented as a time_t value into a clock value */
+
+ static clock_type from_timeval(timeval const & time);
+ ///< Convert legacy timeval to clock value
+ /**< This member converts an absolute time value
+ represented as a timeval value into a clock value */
+
static clock_type nanoseconds(clock_type v);
static clock_type microseconds(clock_type v);
static clock_type milliseconds(clock_type v);
return detail::dumpState(map);
}
+template <class SPolicy>
+template <class Facet>
+prefix_ Facet const & senf::SocketHandle<SPolicy>::facet()
+
+{
+ try {
+ return dynamic_cast<Facet const &>(protocol());
+ }
+ SENF_WRAP_EXC(std::bad_cast)
+}
+
///////////////////////////////////////////////////////////////////////////
// senf::ProtocolSocketBody<SProtocol>
every derived class. See the state()
documentation. */
+ template <class Facet>
+ Facet const & facet(); ///< Access a protocol facet
+ /**< This member will try to access the given protocol facet
+ of the socket. If \a Facet is a valid facet of the
+ protocol, it is returned, otherwise \c std::bad_cast
+ will be thrown.
+ \throws std::bad_cast if \a Facet is not a protocol
+ facet of this socket
+ \returns the \a Facet protocol facet of this socket */
+
protected:
explicit SocketHandle(std::auto_ptr<SocketBody> body);
///< Initialize SocketHandle providing the protocol
"socket.protocol: senf::test::SomeSocketProtocol\n"
"socket.protocol.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy>\n"
"socket.server: false\n" );
+
+ BOOST_CHECK_NO_THROW( myh.facet<senf::test::SomeSocketProtocol>() );
}
// Ensure, the destructor is called and calls the correct close() implementation
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2008
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
+//
+// 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.
+
+/** \file
+ \brief Backtrace non-inline non-template implementation */
+
+#include "Backtrace.hh"
+//#include "Backtrace.ih"
+
+// Custom includes
+#include <execinfo.h>
+#include <cxxabi.h>
+#include <boost/regex.hpp>
+
+//#include "Backtrace.mpp"
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+prefix_ void senf::formatBacktrace(std::ostream & os, void ** backtrace, unsigned numEntries)
+{
+ char ** symbols (::backtrace_symbols(backtrace, numEntries));
+
+ static boost::regex const backtraceRx
+ ("(.*)\\((.*)\\+(0x[0-9a-f]+)\\) \\[(0x[0-9a-f]+)\\]");
+ enum { File = 1,
+ Symbol = 2,
+ Offset = 3,
+ Address = 4 };
+
+ for (unsigned i=0; i<numEntries; ++i) {
+ std::string sym (symbols[i]);
+ boost::smatch match;
+ if (regex_match(sym, match, backtraceRx)) {
+ std::string symbol (match[Symbol]);
+ int status (0);
+ char * demangled ( abi::__cxa_demangle(symbol.c_str(), 0, 0, &status) );
+ if (demangled) {
+ symbol = std::string(demangled);
+ free(demangled);
+ }
+ os << " " << symbol << " + " << match[Offset]
+ << "\n in " << match[File] << " [" << match[Address] << "]\n";
+ }
+ else if (sym == "[0xffffe410]")
+ os << " __kernel_vsyscall [0xffffe410]\n";
+ else if (sym == "[0xffffe420]")
+ os << " __kernel_sigreturn [0xffffe410]\n";
+ else if (sym == "[0xffffe440]")
+ os << " __kernel_rt_sigreturn [0xffffe440]\n";
+ else
+ os << " " << sym << "\n";
+ }
+ free(symbols);
+}
+
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+//#include "Backtrace.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2008
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
+//
+// 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.
+
+/** \file
+ \brief Backtrace public header */
+
+#ifndef HH_Backtrace_
+#define HH_Backtrace_ 1
+
+// Custom includes
+#include <iostream>
+
+//#include "Backtrace.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+ void formatBacktrace(std::ostream & os, void ** backtrace, unsigned numEntries);
+
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "Backtrace.cci"
+//#include "Backtrace.ct"
+//#include "Backtrace.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
+#include <execinfo.h>
#include <sstream>
#include <algorithm>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/format.hpp>
#include "../Exception.hh"
#include "../membind.hh"
+#include "../Backtrace.hh"
+
+// #define __USE_GNU
+#include <ucontext.h>
//#include "Daemon.mpp"
#define prefix_
openLog();
fork();
}
+ installSighandlers();
if (! pidfile_.empty()) {
if (pidfileCreate())
pidfileCreated_ = true;
return true;
}
+
+#ifdef SENF_DEBUG
+
+namespace {
+ void fatalSignalsHandler(int sig, ::siginfo_t * info, void * arg)
+ {
+ static char const * const signames[] = {
+ "",
+ "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP", "SIGABRT", "SIGBUS", "SIGFPE",
+ "SIGKILL", "SIGUSR1", "SIGSEGV", "SIGUSR2", "SIGPIPE", "SIGALRM", "SIGTERM",
+ "SIGSTKFLT", "SIGCHLD", "SIGCONT", "SIGSTOP", "SIGTSTP", "SIGTTIN", "SIGTTOU",
+ "SIGURG", "SIGXCPU", "SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH", "SIGIO",
+ "SIGPWR", "SIGSYS" };
+
+ // ::ucontext_t * ucontext = static_cast<ucontext_t*>(arg);
+ std::cerr << "\n" << "Signal " << sig;
+ if (unsigned(sig) < sizeof(signames) / sizeof(signames[0]))
+ std::cerr << " (" << signames[unsigned(sig)] << ")";
+ std::cerr << " received\n";
+
+ if (sig == SIGSEGV)
+ std::cerr << "Invalid memory access at " << info->si_addr << "\n";
+
+ static void * entries[SENF_DEBUG_BACKTRACE_NUMCALLERS];
+ unsigned nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) );
+
+ // Hack the callers address into the backtrace
+ // entries[1] = reinterpret_cast<void *>(ucontext->uc_mcontext.gregs[REG_EIP]);
+
+ std::cerr << "Backtrace:\n";
+ senf::formatBacktrace(std::cerr, entries, nEntries);
+ std::cerr << "-- \n";
+
+ if (sig != SIGUSR2) {
+ ::signal(sig, SIG_DFL);
+ ::kill(::getpid(), sig);
+ }
+ }
+
+}
+
+#endif
+
+prefix_ void senf::Daemon::installSighandlers()
+{
+#ifdef SENF_DEBUG
+ struct ::sigaction sa;
+ sa.sa_sigaction = &fatalSignalsHandler;
+ ::sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESTART | SA_SIGINFO;
+
+ ::sigaction(SIGILL, &sa, NULL);
+ ::sigaction(SIGTRAP, &sa, NULL);
+ ::sigaction(SIGABRT, &sa, NULL);
+ ::sigaction(SIGFPE, &sa, NULL);
+ ::sigaction(SIGBUS, &sa, NULL);
+ ::sigaction(SIGSEGV, &sa, NULL);
+ ::sigaction(SIGSTKFLT, &sa, NULL);
+ ::sigaction(SIGSYS, &sa, NULL);
+ ::sigaction(SIGUSR2, &sa, NULL);
+#endif
+}
+
///////////////////////////////////////////////////////////////////////////
// senf::detail::DaemonWatcher
successful startup. */
int argc(); ///< Access command line parameter count
- char ** argv(); ///< Access command line parameters
+ char ** argv(); ///< Access command line parameters
- static void exit(unsigned code=0); ///< Terminate daemon with failure
+ static void exit(unsigned code=0); ///< Terminate daemon with failure
///\}
This member is only called, if the default main()
implementation is not overridden. */
private:
-
void openLog();
void fork();
bool pidfileCreate();
+ void installSighandlers();
int argc_;
char ** argv_;
#include <execinfo.h>
#include <sstream>
#include "../config.hh"
-
-// Copied from the binutils sources
-#define HAVE_DECL_BASENAME 1
-#define HAVE_DECL_ASPRINTF 1
-#define HAVE_DECL_VASPRINTF 1
-#include "impl/demangle.h"
+#include "Backtrace.hh"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
{
void * entries[SENF_DEBUG_BACKTRACE_NUMCALLERS];
unsigned nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) );
- char ** symbols = ::backtrace_symbols(entries, nEntries);
-
+
std::stringstream ss;
ss << "\nException at\n";
- for (unsigned i=0; i<nEntries; ++i) {
- std::string sym (symbols[i]);
- std::string::size_type fnStart (sym.find("("));
- if (fnStart != std::string::npos) {
- std::string::size_type fnEnd (sym.find(")",fnStart+1));
- if (fnEnd != std::string::npos) {
- std::string fn (sym,fnStart+1, fnEnd-fnStart-1);
- char * demangled ( ::cplus_demangle(fn.c_str(),
- DMGL_TYPES|DMGL_AUTO) );
- if (demangled) {
- ss << " " << demangled << "( ... )" << std::string(sym,fnEnd+1) << "\n";
- continue;
- }
- }
- }
- ss << " " << sym << "\n";
- }
+ formatBacktrace(ss, entries, nEntries);
ss << "-- \n" << message_;
message_ = ss.str();
- free(symbols);
}
#endif
setfill
setFromPosition
setw
+SIGABRT
+SIGALRM
+SIGBUS
+SIGCHLD
+SIGCONT
+SIGFPE
+SIGHUP
+SIGILL
+SIGINT
+SIGIO
+SIGIOT
+SIGKILL
+SIGPIPE
+SIGPROF
+SIGPWR
+SIGQUIT
+SIGSEGV
+SIGSTKFLT
+SIGSTOP
+SIGSYS
+SIGTERM
+SIGTRAP
+SIGTSTP
+SIGTTIN
+SIGTTOU
+SIGURG
SIGUSR
+SIGVTALRM
+SIGWINCH
+SIGXCPU
+SIGXFSZ
SimpleCommandNode
SimpleCommandOverload
SimplePacketType