From badc0da3b74d99c90b7b28180d08cd6d08830254 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 19 May 2009 09:13:35 +0200 Subject: Make-Prozess auf CMake umgestellt --- src/modules/FileLogger.cpp | 73 --- src/modules/FileLogger.h | 77 --- src/modules/FileLogger/FileLogger.cpp | 73 +++ src/modules/FileLogger/FileLogger.h | 78 +++ src/modules/Makefile.am | 37 -- src/modules/Makefile.in | 580 --------------------- src/modules/SystemBackendPosix.cpp | 296 ----------- src/modules/SystemBackendPosix.h | 98 ---- .../SystemBackendPosix/SystemBackendPosix.cpp | 296 +++++++++++ .../SystemBackendPosix/SystemBackendPosix.h | 98 ++++ src/modules/SystemBackendProc.cpp | 134 ----- src/modules/SystemBackendProc.h | 67 --- .../SystemBackendProc/SystemBackendProc.cpp | 134 +++++ src/modules/SystemBackendProc/SystemBackendProc.h | 67 +++ src/modules/UserBackendMysql.cpp | 233 --------- src/modules/UserBackendMysql.h | 71 --- src/modules/UserBackendMysql/UserBackendMysql.cpp | 233 +++++++++ src/modules/UserBackendMysql/UserBackendMysql.h | 71 +++ 18 files changed, 1050 insertions(+), 1666 deletions(-) delete mode 100644 src/modules/FileLogger.cpp delete mode 100644 src/modules/FileLogger.h create mode 100644 src/modules/FileLogger/FileLogger.cpp create mode 100644 src/modules/FileLogger/FileLogger.h delete mode 100644 src/modules/Makefile.am delete mode 100644 src/modules/Makefile.in delete mode 100644 src/modules/SystemBackendPosix.cpp delete mode 100644 src/modules/SystemBackendPosix.h create mode 100644 src/modules/SystemBackendPosix/SystemBackendPosix.cpp create mode 100644 src/modules/SystemBackendPosix/SystemBackendPosix.h delete mode 100644 src/modules/SystemBackendProc.cpp delete mode 100644 src/modules/SystemBackendProc.h create mode 100644 src/modules/SystemBackendProc/SystemBackendProc.cpp create mode 100644 src/modules/SystemBackendProc/SystemBackendProc.h delete mode 100644 src/modules/UserBackendMysql.cpp delete mode 100644 src/modules/UserBackendMysql.h create mode 100644 src/modules/UserBackendMysql/UserBackendMysql.cpp create mode 100644 src/modules/UserBackendMysql/UserBackendMysql.h (limited to 'src/modules') diff --git a/src/modules/FileLogger.cpp b/src/modules/FileLogger.cpp deleted file mode 100644 index 5e0c021..0000000 --- a/src/modules/FileLogger.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * FileLogger.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 3 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, see . - */ - -#include "FileLogger.h" - -#include - -#define init FileLogger_LTX_init -#define deinit FileLogger_LTX_deinit - - -namespace Mad { -namespace Modules { - -FileLogger::ConfigHelper FileLogger::configHelper; -std::set FileLogger::loggers; - - -bool FileLogger::ConfigHelper::handleConfigEntry(const Common::ConfigEntry &entry, bool handled) { - if(handled) - return false; - - if(entry[0].getKey().matches("Logger")) { - if(entry[0][0].matches("File")) { - if(entry[1].empty()) { - if(!entry[0][1].empty()) { - FileLogger *logger = new FileLogger(entry[0][1]); - - loggers.insert(logger); - Common::LogManager::get()->registerLogger(static_cast(logger)); - } - else { - Logger::logf(Logger::WARNING, "FileLogger: no filename given."); - } - - return true; - } - } - } - - return false; -} - -} -} - -extern "C" { - -void init() { - Mad::Modules::FileLogger::registerConfigHelper(); -} - -void deinit() { - Mad::Modules::FileLogger::unregisterConfigHelper(); -} - -} diff --git a/src/modules/FileLogger.h b/src/modules/FileLogger.h deleted file mode 100644 index 2def986..0000000 --- a/src/modules/FileLogger.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * FileLogger.h - * - * Copyright (C) 2008 Johannes Thorn - * - * 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 3 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, see . - */ - -#ifndef MAD_MODULES_FILELOGGER_H_ -#define MAD_MODULES_FILELOGGER_H_ - -#include -#include -#include - -#include - -namespace Mad { -namespace Modules { - -class FileLogger : private Common::Logger, private Common::RemoteLogger { - private: - class ConfigHelper : public Common::Configurable { - protected: - virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool handled); - - public: - virtual int getPriority() const {return 1;} - }; - - static ConfigHelper configHelper; - static std::set loggers; - - std::ofstream file; - - protected: - virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message) { - file << message << std::endl; - } - virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message, const std::string &messageSource) { - file << message << " from "<< messageSource << std::endl; - } - - public: - FileLogger(const std::string &filename) - : file(filename.c_str(), std::ios::out|std::ios::app) {} - - static void registerConfigHelper() { - Common::ConfigManager::get()->registerConfigurable(&configHelper); - } - - static void unregisterConfigHelper() { - Common::ConfigManager::get()->unregisterConfigurable(&configHelper); - - for(std::set::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { - delete *logger; - } - - loggers.clear(); - } -}; - -} -} - -#endif /* MAD_MODULES_FILELOGGER_H_ */ diff --git a/src/modules/FileLogger/FileLogger.cpp b/src/modules/FileLogger/FileLogger.cpp new file mode 100644 index 0000000..5e0c021 --- /dev/null +++ b/src/modules/FileLogger/FileLogger.cpp @@ -0,0 +1,73 @@ +/* + * FileLogger.cpp + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 3 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, see . + */ + +#include "FileLogger.h" + +#include + +#define init FileLogger_LTX_init +#define deinit FileLogger_LTX_deinit + + +namespace Mad { +namespace Modules { + +FileLogger::ConfigHelper FileLogger::configHelper; +std::set FileLogger::loggers; + + +bool FileLogger::ConfigHelper::handleConfigEntry(const Common::ConfigEntry &entry, bool handled) { + if(handled) + return false; + + if(entry[0].getKey().matches("Logger")) { + if(entry[0][0].matches("File")) { + if(entry[1].empty()) { + if(!entry[0][1].empty()) { + FileLogger *logger = new FileLogger(entry[0][1]); + + loggers.insert(logger); + Common::LogManager::get()->registerLogger(static_cast(logger)); + } + else { + Logger::logf(Logger::WARNING, "FileLogger: no filename given."); + } + + return true; + } + } + } + + return false; +} + +} +} + +extern "C" { + +void init() { + Mad::Modules::FileLogger::registerConfigHelper(); +} + +void deinit() { + Mad::Modules::FileLogger::unregisterConfigHelper(); +} + +} diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h new file mode 100644 index 0000000..404299b --- /dev/null +++ b/src/modules/FileLogger/FileLogger.h @@ -0,0 +1,78 @@ +/* + * FileLogger.h + * + * Copyright (C) 2008 Johannes Thorn + * + * 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 3 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, see . + */ + +#ifndef MAD_MODULES_FILELOGGER_H_ +#define MAD_MODULES_FILELOGGER_H_ + +#include +#include +#include + +#include + +namespace Mad { +namespace Modules { + +class FileLogger : private Common::Logger, private Common::RemoteLogger { + private: + class ConfigHelper : public Common::Configurable { + protected: + virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool handled); + + public: + virtual int getPriority() const {return 1;} + }; + + static ConfigHelper configHelper; + static std::set loggers; + + std::ofstream file; + + protected: + virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message) { + file << message << std::endl; + } + virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message, const std::string &messageSource) { + file << message << " from "<< messageSource << std::endl; + } + + public: + FileLogger(const std::string &filename) + : file(filename.c_str(), std::ios::out|std::ios::app) {} + + static void registerConfigHelper() { + Common::ConfigManager::get()->registerConfigurable(&configHelper); + Logger::log("Registered!"); + } + + static void unregisterConfigHelper() { + Common::ConfigManager::get()->unregisterConfigurable(&configHelper); + + for(std::set::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { + delete *logger; + } + + loggers.clear(); + } +}; + +} +} + +#endif /* MAD_MODULES_FILELOGGER_H_ */ diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am deleted file mode 100644 index eb95034..0000000 --- a/src/modules/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -moddir = ${pkglibdir}/modules - -default_ldflags = -module -avoid-version -export-dynamic -static_ldflags = $(default_ldflags) -static -rpath $(moddir) - -EXTRA_LTLIBTRARIES = SystemBackendPosix.la SystemBackendProc.la UserBackendMysql.la - -mod_LTLIBRARIES = -noinst_LTLIBRARIES = FileLogger.la - -if SYSTEMBACKEND_POSIX -noinst_LTLIBRARIES += SystemBackendPosix.la -endif - -if SYSTEMBACKEND_PROC -noinst_LTLIBRARIES += SystemBackendProc.la -endif - -if USERBACKEND_MYSQL -mod_LTLIBRARIES += UserBackendMysql.la -endif - -FileLogger_la_SOURCES = FileLogger.cpp -FileLogger_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^FileLogger_LTX_' - -SystemBackendPosix_la_SOURCES = SystemBackendPosix.cpp -SystemBackendPosix_la_LIBADD = $(sigc_LIBS) -SystemBackendPosix_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemBackendPosix_LTX_' - -SystemBackendProc_la_SOURCES = SystemBackendProc.cpp -SystemBackendProc_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemBackendProc_LTX_' - -UserBackendMysql_la_SOURCES = UserBackendMysql.cpp -UserBackendMysql_la_LIBADD = $(MYSQL_LDFLAGS) $(BOOST_REGEX_LIB) -UserBackendMysql_la_LDFLAGS = $(default_ldflags) -export-symbols-regex '^UserBackendMysql_LTX_' - -noinst_HEADERS = FileLogger.h SystemBackendPosix.h SystemBackendProc.h UserBackendMysql.h diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in deleted file mode 100644 index 174cfc0..0000000 --- a/src/modules/Makefile.in +++ /dev/null @@ -1,580 +0,0 @@ -# Makefile.in generated by automake 1.10.2 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - - -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -@SYSTEMBACKEND_POSIX_TRUE@am__append_1 = SystemBackendPosix.la -@SYSTEMBACKEND_PROC_TRUE@am__append_2 = SystemBackendProc.la -@USERBACKEND_MYSQL_TRUE@am__append_3 = UserBackendMysql.la -subdir = src/modules -DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ - $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \ - $(top_srcdir)/m4/ax_boost_base.m4 \ - $(top_srcdir)/m4/ax_boost_regex.m4 \ - $(top_srcdir)/m4/ax_boost_signals.m4 \ - $(top_srcdir)/m4/ax_boost_thread.m4 \ - $(top_srcdir)/m4/ax_lib_mysql.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltdl.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/pkg.m4 \ - $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; -am__installdirs = "$(DESTDIR)$(moddir)" -modLTLIBRARIES_INSTALL = $(INSTALL) -LTLIBRARIES = $(mod_LTLIBRARIES) $(noinst_LTLIBRARIES) -FileLogger_la_LIBADD = -am_FileLogger_la_OBJECTS = FileLogger.lo -FileLogger_la_OBJECTS = $(am_FileLogger_la_OBJECTS) -FileLogger_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(FileLogger_la_LDFLAGS) $(LDFLAGS) -o $@ -SystemBackendPosix_la_DEPENDENCIES = -am_SystemBackendPosix_la_OBJECTS = SystemBackendPosix.lo -SystemBackendPosix_la_OBJECTS = $(am_SystemBackendPosix_la_OBJECTS) -SystemBackendPosix_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(SystemBackendPosix_la_LDFLAGS) $(LDFLAGS) -o $@ -@SYSTEMBACKEND_POSIX_TRUE@am_SystemBackendPosix_la_rpath = -SystemBackendProc_la_LIBADD = -am_SystemBackendProc_la_OBJECTS = SystemBackendProc.lo -SystemBackendProc_la_OBJECTS = $(am_SystemBackendProc_la_OBJECTS) -SystemBackendProc_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(SystemBackendProc_la_LDFLAGS) $(LDFLAGS) -o $@ -@SYSTEMBACKEND_PROC_TRUE@am_SystemBackendProc_la_rpath = -am__DEPENDENCIES_1 = -UserBackendMysql_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) -am_UserBackendMysql_la_OBJECTS = UserBackendMysql.lo -UserBackendMysql_la_OBJECTS = $(am_UserBackendMysql_la_OBJECTS) -UserBackendMysql_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(UserBackendMysql_la_LDFLAGS) $(LDFLAGS) -o $@ -@USERBACKEND_MYSQL_TRUE@am_UserBackendMysql_la_rpath = -rpath \ -@USERBACKEND_MYSQL_TRUE@ $(moddir) -DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/config/depcomp -am__depfiles_maybe = depfiles -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -CXXLD = $(CXX) -CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ - $(LDFLAGS) -o $@ -SOURCES = $(FileLogger_la_SOURCES) $(SystemBackendPosix_la_SOURCES) \ - $(SystemBackendProc_la_SOURCES) $(UserBackendMysql_la_SOURCES) -DIST_SOURCES = $(FileLogger_la_SOURCES) \ - $(SystemBackendPosix_la_SOURCES) \ - $(SystemBackendProc_la_SOURCES) $(UserBackendMysql_la_SOURCES) -HEADERS = $(noinst_HEADERS) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -AMTAR = @AMTAR@ -AR = @AR@ -ARGZ_H = @ARGZ_H@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BOOST_CPPFLAGS = @BOOST_CPPFLAGS@ -BOOST_LDFLAGS = @BOOST_LDFLAGS@ -BOOST_REGEX_LIB = @BOOST_REGEX_LIB@ -BOOST_SIGNALS_LIB = @BOOST_SIGNALS_LIB@ -BOOST_THREAD_LIB = @BOOST_THREAD_LIB@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -DSYMUTIL = @DSYMUTIL@ -DUMPBIN = @DUMPBIN@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -FGREP = @FGREP@ -GREP = @GREP@ -GSSAPI_LIBS = @GSSAPI_LIBS@ -GnuTLS_CFLAGS = @GnuTLS_CFLAGS@ -GnuTLS_LIBS = @GnuTLS_LIBS@ -INCLTDL = @INCLTDL@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBADD_DL = @LIBADD_DL@ -LIBADD_DLD_LINK = @LIBADD_DLD_LINK@ -LIBADD_DLOPEN = @LIBADD_DLOPEN@ -LIBADD_SHL_LOAD = @LIBADD_SHL_LOAD@ -LIBLTDL = @LIBLTDL@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBTOOL = @LIBTOOL@ -LIPO = @LIPO@ -LN_S = @LN_S@ -LTDLDEPS = @LTDLDEPS@ -LTDLINCL = @LTDLINCL@ -LTDLOPEN = @LTDLOPEN@ -LTLIBOBJS = @LTLIBOBJS@ -LT_CONFIG_H = @LT_CONFIG_H@ -LT_DLLOADERS = @LT_DLLOADERS@ -LT_DLPREOPEN = @LT_DLPREOPEN@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MKDIR_P = @MKDIR_P@ -MYSQL_CFLAGS = @MYSQL_CFLAGS@ -MYSQL_CONFIG = @MYSQL_CONFIG@ -MYSQL_LDFLAGS = @MYSQL_LDFLAGS@ -MYSQL_VERSION = @MYSQL_VERSION@ -NM = @NM@ -NMEDIT = @NMEDIT@ -OBJEXT = @OBJEXT@ -OTOOL = @OTOOL@ -OTOOL64 = @OTOOL64@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -PKG_CONFIG = @PKG_CONFIG@ -RANLIB = @RANLIB@ -READLINE_LIBS = @READLINE_LIBS@ -SED = @SED@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VERSION = @VERSION@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -builddir = @builddir@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -have_df = @have_df@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -libxml2_CFLAGS = @libxml2_CFLAGS@ -libxml2_LIBS = @libxml2_LIBS@ -localedir = @localedir@ -localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ -ltdl_LIBOBJS = @ltdl_LIBOBJS@ -ltdl_LTLIBOBJS = @ltdl_LTLIBOBJS@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -sys_symbol_underscore = @sys_symbol_underscore@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -moddir = ${pkglibdir}/modules -default_ldflags = -module -avoid-version -export-dynamic -static_ldflags = $(default_ldflags) -static -rpath $(moddir) -EXTRA_LTLIBTRARIES = SystemBackendPosix.la SystemBackendProc.la UserBackendMysql.la -mod_LTLIBRARIES = $(am__append_3) -noinst_LTLIBRARIES = FileLogger.la $(am__append_1) $(am__append_2) -FileLogger_la_SOURCES = FileLogger.cpp -FileLogger_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^FileLogger_LTX_' -SystemBackendPosix_la_SOURCES = SystemBackendPosix.cpp -SystemBackendPosix_la_LIBADD = $(sigc_LIBS) -SystemBackendPosix_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemBackendPosix_LTX_' -SystemBackendProc_la_SOURCES = SystemBackendProc.cpp -SystemBackendProc_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemBackendProc_LTX_' -UserBackendMysql_la_SOURCES = UserBackendMysql.cpp -UserBackendMysql_la_LIBADD = $(MYSQL_LDFLAGS) $(BOOST_REGEX_LIB) -UserBackendMysql_la_LDFLAGS = $(default_ldflags) -export-symbols-regex '^UserBackendMysql_LTX_' -noinst_HEADERS = FileLogger.h SystemBackendPosix.h SystemBackendProc.h UserBackendMysql.h -all: all-am - -.SUFFIXES: -.SUFFIXES: .cpp .lo .o .obj -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ - && { if test -f $@; then exit 0; else break; fi; }; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/modules/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu src/modules/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -install-modLTLIBRARIES: $(mod_LTLIBRARIES) - @$(NORMAL_INSTALL) - test -z "$(moddir)" || $(MKDIR_P) "$(DESTDIR)$(moddir)" - @list='$(mod_LTLIBRARIES)'; for p in $$list; do \ - if test -f $$p; then \ - f=$(am__strip_dir) \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(modLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(moddir)/$$f'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(modLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(moddir)/$$f"; \ - else :; fi; \ - done - -uninstall-modLTLIBRARIES: - @$(NORMAL_UNINSTALL) - @list='$(mod_LTLIBRARIES)'; for p in $$list; do \ - p=$(am__strip_dir) \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(moddir)/$$p'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(moddir)/$$p"; \ - done - -clean-modLTLIBRARIES: - -test -z "$(mod_LTLIBRARIES)" || rm -f $(mod_LTLIBRARIES) - @list='$(mod_LTLIBRARIES)'; for p in $$list; do \ - dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ - test "$$dir" != "$$p" || dir=.; \ - echo "rm -f \"$${dir}/so_locations\""; \ - rm -f "$${dir}/so_locations"; \ - done - -clean-noinstLTLIBRARIES: - -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) - @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ - dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ - test "$$dir" != "$$p" || dir=.; \ - echo "rm -f \"$${dir}/so_locations\""; \ - rm -f "$${dir}/so_locations"; \ - done -FileLogger.la: $(FileLogger_la_OBJECTS) $(FileLogger_la_DEPENDENCIES) - $(FileLogger_la_LINK) $(FileLogger_la_OBJECTS) $(FileLogger_la_LIBADD) $(LIBS) -SystemBackendPosix.la: $(SystemBackendPosix_la_OBJECTS) $(SystemBackendPosix_la_DEPENDENCIES) - $(SystemBackendPosix_la_LINK) $(am_SystemBackendPosix_la_rpath) $(SystemBackendPosix_la_OBJECTS) $(SystemBackendPosix_la_LIBADD) $(LIBS) -SystemBackendProc.la: $(SystemBackendProc_la_OBJECTS) $(SystemBackendProc_la_DEPENDENCIES) - $(SystemBackendProc_la_LINK) $(am_SystemBackendProc_la_rpath) $(SystemBackendProc_la_OBJECTS) $(SystemBackendProc_la_LIBADD) $(LIBS) -UserBackendMysql.la: $(UserBackendMysql_la_OBJECTS) $(UserBackendMysql_la_DEPENDENCIES) - $(UserBackendMysql_la_LINK) $(am_UserBackendMysql_la_rpath) $(UserBackendMysql_la_OBJECTS) $(UserBackendMysql_la_LIBADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileLogger.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackendPosix.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackendProc.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserBackendMysql.Plo@am__quote@ - -.cpp.o: -@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< - -.cpp.obj: -@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.cpp.lo: -@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(LTLIBRARIES) $(HEADERS) -installdirs: - for dir in "$(DESTDIR)$(moddir)"; do \ - test -z "$$dir" || $(MKDIR_P) "$$dir"; \ - done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic clean-libtool clean-modLTLIBRARIES \ - clean-noinstLTLIBRARIES mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -info: info-am - -info-am: - -install-data-am: install-modLTLIBRARIES - -install-dvi: install-dvi-am - -install-exec-am: - -install-html: install-html-am - -install-info: install-info-am - -install-man: - -install-pdf: install-pdf-am - -install-ps: install-ps-am - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-modLTLIBRARIES - -.MAKE: install-am install-strip - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool clean-modLTLIBRARIES clean-noinstLTLIBRARIES \ - ctags distclean distclean-compile distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-modLTLIBRARIES install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-modLTLIBRARIES - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/src/modules/SystemBackendPosix.cpp b/src/modules/SystemBackendPosix.cpp deleted file mode 100644 index 4969c6d..0000000 --- a/src/modules/SystemBackendPosix.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* - * SystemBackendPosix.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 3 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, see . - */ - -#include "SystemBackendPosix.h" - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define init SystemBackendPosix_LTX_init -#define deinit SystemBackendPosix_LTX_deinit - -namespace Mad { -namespace Modules { - -SystemBackendPosix *SystemBackendPosix::backend = 0; - -std::map > SystemBackendPosix::processes; -std::map > SystemBackendPosix::processesWithOutput; -std::map SystemBackendPosix::processesWOHandles; -std::map SystemBackendPosix::processesWOOutput; - - -void SystemBackendPosix::setChildHandler() { - struct sigaction action; - - action.sa_handler = childHandler; - sigemptyset(&action.sa_mask); - action.sa_flags = 0; - - sigaction(SIGCHLD, &action, 0); -} - -SystemBackendPosix::~SystemBackendPosix() { - struct sigaction action; - - action.sa_handler = SIG_DFL; - sigemptyset(&action.sa_mask); - action.sa_flags = 0; - - sigaction(SIGCHLD, &action, 0); -} - - -void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const boost::function1& > &callback) { - std::vector ret; - std::istringstream stream(output); - std::string str; - - std::getline(stream, str); // ignore first line - - while(!stream.eof()) { - std::getline(stream, str); - - char *fsName = new char[str.length()+1]; - char *mountedOn = new char[str.length()+1]; - - Common::SystemManager::FSInfo info; - - if(std::sscanf(str.c_str(), "%s %lld %lld %lld %*d%% %s", fsName, &info.total, &info.used, &info.available, mountedOn) == 5) { - info.fsName = fsName; - info.mountedOn = mountedOn; - - ret.push_back(info); - } - - delete [] fsName; - delete [] mountedOn; - } - - callback(ret); -} - -bool SystemBackendPosix::getFSInfo(const boost::function1& > &callback) { - std::vector argv; - - argv.push_back("/bin/df"); - argv.push_back("-P"); - argv.push_back("-k"); - - return execWithOutput(boost::bind(&SystemBackendPosix::fsInfoCallback, this, _1, _2, callback), "/bin/df", argv); -} - - -void SystemBackendPosix::childHandler(int) { - int status; - pid_t pid; - - while((pid = waitpid(-1, &status, WNOHANG)) > 0) { - std::map >::iterator it = processes.find(pid); - - if(it != processes.end()) { - Common::ActionManager::get()->add(boost::bind(it->second, status)); - processes.erase(it); - } - else { - std::map >::iterator it2 = processesWithOutput.find(pid); - - if(it2 != processesWithOutput.end()) { - char buffer[1024]; - ssize_t n; - std::string &output = processesWOOutput[pid]; - int handle = processesWOHandles[pid]; - - while((n = read(handle, buffer, sizeof(buffer))) > 0) - output += std::string(buffer, n); - - //Net::FdManager::get()->unregisterFd(handle); - //close(handle); - - //Common::ActionManager::get()->add(boost::bind(it2->second, status, output)); - processesWithOutput.erase(it2); - processesWOHandles.erase(pid); - processesWOOutput.erase(pid); - } - } - } - - setChildHandler(); -} - -void SystemBackendPosix::outputHandler(short events, pid_t pid) { - char buf[1024]; - - if(events & POLLIN) { - sigset_t set, oldset; - sigemptyset(&set); - sigaddset(&set, SIGCHLD); - sigprocmask(SIG_BLOCK, &set, &oldset); - - ssize_t ret; - - std::map::iterator handle = processesWOHandles.find(pid); - if(handle == processesWOHandles.end()) - return; - - while((ret = read(handle->second, buf, sizeof(buf))) > 0) - processesWOOutput[pid] += std::string(buf, ret); - - sigprocmask(SIG_SETMASK, &oldset, 0); - } -} - -std::pair SystemBackendPosix::makeArgs(const std::string &filename, const std::vector &argv, const std::vector &env) { - char **argvp, **envp; - - if(argv.empty()) { - argvp = new char*[2]; - - argvp[0] = strdup(filename.c_str()); - argvp[1] = 0; - } - else { - argvp = new char*[argv.size() + 1]; - - for(size_t s = 0; s < argv.size(); ++s) { - argvp[s] = strdup(argv[s].c_str()); - } - - argvp[argv.size()] = 0; - } - - if(env.empty()) { - envp = environ; - } - else { - envp = new char*[env.size() + 1]; - - for(size_t s = 0; s < env.size(); ++s) { - envp[0] = strdup(env[s].c_str()); - } - - envp[env.size()] = 0; - } - - return std::make_pair(argvp, envp); -} - -void SystemBackendPosix::destroyArgs(std::pair args) { - for(char **p = args.first; *p != 0; ++p) - std::free(*p); - - delete [] args.first; - - if(args.second != environ) { - for(char **p = args.second; *p != 0; ++p) - std::free(*p); - - delete [] args.second; - } -} - -bool SystemBackendPosix::exec(const boost::function1 &resultHandler, const std::string &filename, const std::vector &argv, const std::vector &env) { - pid_t pid; - std::pair args = makeArgs(filename, argv, env); - - sigset_t set, oldset; - sigemptyset(&set); - sigaddset(&set, SIGCHLD); - sigprocmask(SIG_BLOCK, &set, &oldset); - - bool ret = (posix_spawnp(&pid, filename.c_str(), 0, 0, args.first, args.second) == 0); - - if(ret) - processes.insert(std::make_pair(pid, resultHandler)); - - sigprocmask(SIG_SETMASK, &oldset, 0); - - destroyArgs(args); - - return ret; -} - -bool SystemBackendPosix::execWithOutput(const boost::function2 &resultHandler, const std::string &filename, const std::vector &argv, const std::vector &env) { - pid_t pid; - std::pair args = makeArgs(filename, argv, env); - - int saveStdout = dup(STDOUT_FILENO); - int pipeHandles[2]; - - pipe(pipeHandles); - - fcntl(pipeHandles[0], F_SETFD, FD_CLOEXEC); - - int flags = fcntl(pipeHandles[0], F_GETFL, 0); - fcntl(pipeHandles[0], F_SETFL, flags | O_NONBLOCK); - - sigset_t set, oldset; - sigemptyset(&set); - sigaddset(&set, SIGCHLD); - sigprocmask(SIG_BLOCK, &set, &oldset); - - dup2(pipeHandles[1], STDOUT_FILENO); // set the new pipe as stdout - close(pipeHandles[1]); - - bool ret = (posix_spawnp(&pid, filename.c_str(), 0, 0, args.first, args.second) == 0); - - if(ret) { - processesWithOutput.insert(std::make_pair(pid, resultHandler)); - processesWOHandles.insert(std::make_pair(pid, pipeHandles[0])); - processesWOOutput.insert(std::make_pair(pid, std::string())); - - Net::FdManager::get()->registerFd(pipeHandles[0], boost::bind(&SystemBackendPosix::outputHandler, _1, pid), POLLIN); - } - - dup2(saveStdout, STDOUT_FILENO); // restore old stdout - close(saveStdout); - - sigprocmask(SIG_SETMASK, &oldset, 0); - - destroyArgs(args); - - return ret; -} - -} -} - -extern "C" { - -void init() { - Mad::Modules::SystemBackendPosix::registerBackend(); -} - -void deinit() { - Mad::Modules::SystemBackendPosix::unregisterBackend(); -} - -} - diff --git a/src/modules/SystemBackendPosix.h b/src/modules/SystemBackendPosix.h deleted file mode 100644 index 6d9b65f..0000000 --- a/src/modules/SystemBackendPosix.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SystemBackendPosix.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 3 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, see . - */ - -#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_H_ -#define MAD_MODULES_SYSTEMBACKENDPOSIX_H_ - -#include - -#include -#include -#include - -#include - -#include - -namespace Mad { -namespace Modules { - -// TODO SystemBackendPosix doesn't work !!! - -class SystemBackendPosix : private Common::SystemBackend { - private: - static SystemBackendPosix *backend; - static std::map > processes; - - static std::map > processesWithOutput; - static std::map processesWOHandles; - static std::map processesWOOutput; - - static void setChildHandler(); - - static void childHandler(int); - - static void outputHandler(short events, pid_t pid); - - static std::pair makeArgs(const std::string &filename, const std::vector &argv, const std::vector &env); - static void destroyArgs(std::pair args); - - SystemBackendPosix() { - setChildHandler(); - } - - void fsInfoCallback(int, const std::string &output, const boost::function1& > &callback); - - protected: - virtual bool getFSInfo(const boost::function1& > &callback); - - virtual bool shutdown(const boost::function0 &callback) {return exec(boost::bind(callback), "/sbin/halt");} - virtual bool reboot(const boost::function0 &callback) {return exec(boost::bind(callback), "/sbin/reboot");} - - public: - ~SystemBackendPosix(); - - static void registerBackend() { - if(backend) - return; - - backend = new SystemBackendPosix(); - Common::SystemManager::get()->registerBackend(backend); - } - - static void unregisterBackend() { - if(!backend) - return; - - Common::SystemManager::get()->unregisterBackend(backend); - delete backend; - backend = 0; - } - - static bool exec(const boost::function1 &resultHandler, const std::string &filename, const std::vector &argv = std::vector(), - const std::vector &env = std::vector()); - - static bool execWithOutput(const boost::function2 &resultHandler, const std::string &filename, const std::vector &argv = std::vector(), - const std::vector &env = std::vector()); -}; - -} -} - -#endif /* MAD_MODULES_SYSTEMBACKENDPOSIX_H_ */ diff --git a/src/modules/SystemBackendPosix/SystemBackendPosix.cpp b/src/modules/SystemBackendPosix/SystemBackendPosix.cpp new file mode 100644 index 0000000..4969c6d --- /dev/null +++ b/src/modules/SystemBackendPosix/SystemBackendPosix.cpp @@ -0,0 +1,296 @@ +/* + * SystemBackendPosix.cpp + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 3 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, see . + */ + +#include "SystemBackendPosix.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define init SystemBackendPosix_LTX_init +#define deinit SystemBackendPosix_LTX_deinit + +namespace Mad { +namespace Modules { + +SystemBackendPosix *SystemBackendPosix::backend = 0; + +std::map > SystemBackendPosix::processes; +std::map > SystemBackendPosix::processesWithOutput; +std::map SystemBackendPosix::processesWOHandles; +std::map SystemBackendPosix::processesWOOutput; + + +void SystemBackendPosix::setChildHandler() { + struct sigaction action; + + action.sa_handler = childHandler; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + + sigaction(SIGCHLD, &action, 0); +} + +SystemBackendPosix::~SystemBackendPosix() { + struct sigaction action; + + action.sa_handler = SIG_DFL; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + + sigaction(SIGCHLD, &action, 0); +} + + +void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const boost::function1& > &callback) { + std::vector ret; + std::istringstream stream(output); + std::string str; + + std::getline(stream, str); // ignore first line + + while(!stream.eof()) { + std::getline(stream, str); + + char *fsName = new char[str.length()+1]; + char *mountedOn = new char[str.length()+1]; + + Common::SystemManager::FSInfo info; + + if(std::sscanf(str.c_str(), "%s %lld %lld %lld %*d%% %s", fsName, &info.total, &info.used, &info.available, mountedOn) == 5) { + info.fsName = fsName; + info.mountedOn = mountedOn; + + ret.push_back(info); + } + + delete [] fsName; + delete [] mountedOn; + } + + callback(ret); +} + +bool SystemBackendPosix::getFSInfo(const boost::function1& > &callback) { + std::vector argv; + + argv.push_back("/bin/df"); + argv.push_back("-P"); + argv.push_back("-k"); + + return execWithOutput(boost::bind(&SystemBackendPosix::fsInfoCallback, this, _1, _2, callback), "/bin/df", argv); +} + + +void SystemBackendPosix::childHandler(int) { + int status; + pid_t pid; + + while((pid = waitpid(-1, &status, WNOHANG)) > 0) { + std::map >::iterator it = processes.find(pid); + + if(it != processes.end()) { + Common::ActionManager::get()->add(boost::bind(it->second, status)); + processes.erase(it); + } + else { + std::map >::iterator it2 = processesWithOutput.find(pid); + + if(it2 != processesWithOutput.end()) { + char buffer[1024]; + ssize_t n; + std::string &output = processesWOOutput[pid]; + int handle = processesWOHandles[pid]; + + while((n = read(handle, buffer, sizeof(buffer))) > 0) + output += std::string(buffer, n); + + //Net::FdManager::get()->unregisterFd(handle); + //close(handle); + + //Common::ActionManager::get()->add(boost::bind(it2->second, status, output)); + processesWithOutput.erase(it2); + processesWOHandles.erase(pid); + processesWOOutput.erase(pid); + } + } + } + + setChildHandler(); +} + +void SystemBackendPosix::outputHandler(short events, pid_t pid) { + char buf[1024]; + + if(events & POLLIN) { + sigset_t set, oldset; + sigemptyset(&set); + sigaddset(&set, SIGCHLD); + sigprocmask(SIG_BLOCK, &set, &oldset); + + ssize_t ret; + + std::map::iterator handle = processesWOHandles.find(pid); + if(handle == processesWOHandles.end()) + return; + + while((ret = read(handle->second, buf, sizeof(buf))) > 0) + processesWOOutput[pid] += std::string(buf, ret); + + sigprocmask(SIG_SETMASK, &oldset, 0); + } +} + +std::pair SystemBackendPosix::makeArgs(const std::string &filename, const std::vector &argv, const std::vector &env) { + char **argvp, **envp; + + if(argv.empty()) { + argvp = new char*[2]; + + argvp[0] = strdup(filename.c_str()); + argvp[1] = 0; + } + else { + argvp = new char*[argv.size() + 1]; + + for(size_t s = 0; s < argv.size(); ++s) { + argvp[s] = strdup(argv[s].c_str()); + } + + argvp[argv.size()] = 0; + } + + if(env.empty()) { + envp = environ; + } + else { + envp = new char*[env.size() + 1]; + + for(size_t s = 0; s < env.size(); ++s) { + envp[0] = strdup(env[s].c_str()); + } + + envp[env.size()] = 0; + } + + return std::make_pair(argvp, envp); +} + +void SystemBackendPosix::destroyArgs(std::pair args) { + for(char **p = args.first; *p != 0; ++p) + std::free(*p); + + delete [] args.first; + + if(args.second != environ) { + for(char **p = args.second; *p != 0; ++p) + std::free(*p); + + delete [] args.second; + } +} + +bool SystemBackendPosix::exec(const boost::function1 &resultHandler, const std::string &filename, const std::vector &argv, const std::vector &env) { + pid_t pid; + std::pair args = makeArgs(filename, argv, env); + + sigset_t set, oldset; + sigemptyset(&set); + sigaddset(&set, SIGCHLD); + sigprocmask(SIG_BLOCK, &set, &oldset); + + bool ret = (posix_spawnp(&pid, filename.c_str(), 0, 0, args.first, args.second) == 0); + + if(ret) + processes.insert(std::make_pair(pid, resultHandler)); + + sigprocmask(SIG_SETMASK, &oldset, 0); + + destroyArgs(args); + + return ret; +} + +bool SystemBackendPosix::execWithOutput(const boost::function2 &resultHandler, const std::string &filename, const std::vector &argv, const std::vector &env) { + pid_t pid; + std::pair args = makeArgs(filename, argv, env); + + int saveStdout = dup(STDOUT_FILENO); + int pipeHandles[2]; + + pipe(pipeHandles); + + fcntl(pipeHandles[0], F_SETFD, FD_CLOEXEC); + + int flags = fcntl(pipeHandles[0], F_GETFL, 0); + fcntl(pipeHandles[0], F_SETFL, flags | O_NONBLOCK); + + sigset_t set, oldset; + sigemptyset(&set); + sigaddset(&set, SIGCHLD); + sigprocmask(SIG_BLOCK, &set, &oldset); + + dup2(pipeHandles[1], STDOUT_FILENO); // set the new pipe as stdout + close(pipeHandles[1]); + + bool ret = (posix_spawnp(&pid, filename.c_str(), 0, 0, args.first, args.second) == 0); + + if(ret) { + processesWithOutput.insert(std::make_pair(pid, resultHandler)); + processesWOHandles.insert(std::make_pair(pid, pipeHandles[0])); + processesWOOutput.insert(std::make_pair(pid, std::string())); + + Net::FdManager::get()->registerFd(pipeHandles[0], boost::bind(&SystemBackendPosix::outputHandler, _1, pid), POLLIN); + } + + dup2(saveStdout, STDOUT_FILENO); // restore old stdout + close(saveStdout); + + sigprocmask(SIG_SETMASK, &oldset, 0); + + destroyArgs(args); + + return ret; +} + +} +} + +extern "C" { + +void init() { + Mad::Modules::SystemBackendPosix::registerBackend(); +} + +void deinit() { + Mad::Modules::SystemBackendPosix::unregisterBackend(); +} + +} + diff --git a/src/modules/SystemBackendPosix/SystemBackendPosix.h b/src/modules/SystemBackendPosix/SystemBackendPosix.h new file mode 100644 index 0000000..6d9b65f --- /dev/null +++ b/src/modules/SystemBackendPosix/SystemBackendPosix.h @@ -0,0 +1,98 @@ +/* + * SystemBackendPosix.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 3 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, see . + */ + +#ifndef MAD_MODULES_SYSTEMBACKENDPOSIX_H_ +#define MAD_MODULES_SYSTEMBACKENDPOSIX_H_ + +#include + +#include +#include +#include + +#include + +#include + +namespace Mad { +namespace Modules { + +// TODO SystemBackendPosix doesn't work !!! + +class SystemBackendPosix : private Common::SystemBackend { + private: + static SystemBackendPosix *backend; + static std::map > processes; + + static std::map > processesWithOutput; + static std::map processesWOHandles; + static std::map processesWOOutput; + + static void setChildHandler(); + + static void childHandler(int); + + static void outputHandler(short events, pid_t pid); + + static std::pair makeArgs(const std::string &filename, const std::vector &argv, const std::vector &env); + static void destroyArgs(std::pair args); + + SystemBackendPosix() { + setChildHandler(); + } + + void fsInfoCallback(int, const std::string &output, const boost::function1& > &callback); + + protected: + virtual bool getFSInfo(const boost::function1& > &callback); + + virtual bool shutdown(const boost::function0 &callback) {return exec(boost::bind(callback), "/sbin/halt");} + virtual bool reboot(const boost::function0 &callback) {return exec(boost::bind(callback), "/sbin/reboot");} + + public: + ~SystemBackendPosix(); + + static void registerBackend() { + if(backend) + return; + + backend = new SystemBackendPosix(); + Common::SystemManager::get()->registerBackend(backend); + } + + static void unregisterBackend() { + if(!backend) + return; + + Common::SystemManager::get()->unregisterBackend(backend); + delete backend; + backend = 0; + } + + static bool exec(const boost::function1 &resultHandler, const std::string &filename, const std::vector &argv = std::vector(), + const std::vector &env = std::vector()); + + static bool execWithOutput(const boost::function2 &resultHandler, const std::string &filename, const std::vector &argv = std::vector(), + const std::vector &env = std::vector()); +}; + +} +} + +#endif /* MAD_MODULES_SYSTEMBACKENDPOSIX_H_ */ diff --git a/src/modules/SystemBackendProc.cpp b/src/modules/SystemBackendProc.cpp deleted file mode 100644 index 68f9cec..0000000 --- a/src/modules/SystemBackendProc.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * SystemBackendProc.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 3 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, see . - */ - -#include "SystemBackendProc.h" - -#include - -#include -#include - -#include - -#define init SystemBackendProc_LTX_init -#define deinit SystemBackendProc_LTX_deinit - -namespace Mad { -namespace Modules { - -SystemBackendProc *SystemBackendProc::backend = 0; - -bool SystemBackendProc::getUptimeInfo(const boost::function2 &callback) { - unsigned long uptime = 0, idleTime = 0; - - uptimeFile.seekg(0, std::ios::beg); - - if(!uptimeFile.good()) - return false; - - float f; - uptimeFile >> f; - if(!uptimeFile.good()) - return false; - - uptime = (unsigned long)f; - - uptimeFile >> f; - if(uptimeFile.good()) - idleTime = (unsigned long)f; - - Common::ActionManager::get()->add(boost::bind(callback, uptime, idleTime)); - - return true; -} - -bool SystemBackendProc::getMemoryInfo(const boost::function4 &callback) { - unsigned long totalMem = 0, freeMem = 0, totalSwap = 0, freeSwap = 0; - - meminfoFile.seekg(0, std::ios::beg); - - if(!meminfoFile.good()) - return false; - - while(!meminfoFile.eof() && meminfoFile.good()) { - std::string line; - std::getline(meminfoFile, line); - - char *name = new char[line.length()+1]; // is always long enough - unsigned long value; - - if(std::sscanf(line.c_str(), "%s %lu", name, &value) == 2) { - if(std::strcmp(name, "MemTotal:") == 0) - totalMem = value; - else if(std::strcmp(name, "MemFree:") == 0) - freeMem = value; - else if(std::strcmp(name, "SwapTotal:") == 0) - totalSwap = value; - else if(std::strcmp(name, "SwapFree:") == 0) - freeSwap = value; - } - - delete [] name; - - if(totalMem && freeMem && totalSwap && freeSwap) - break; - } - - Common::ActionManager::get()->add(boost::bind(callback, totalMem, freeMem, totalSwap, freeSwap)); - - return true; -} - -bool SystemBackendProc::getLoadInfo(const boost::function5 &callback) { - unsigned long currentLoad = 0, nProcesses = 0; - float loadAvg1 = 0, loadAvg5 = 0, loadAvg15 = 0; - - loadFile.seekg(0, std::ios::beg); - - if(!loadFile.good()) - return false; - - std::string line; - std::getline(loadFile, line); - - if(line.empty()) - return false; - - std::sscanf(line.c_str(), "%f %f %f %lu/%lu", &loadAvg1, &loadAvg5, &loadAvg15, ¤tLoad, &nProcesses); - - Common::ActionManager::get()->add(boost::bind(callback, currentLoad, nProcesses, loadAvg1, loadAvg5, loadAvg15)); - - return true; -} - -} -} - - -extern "C" { - -void init() { - Mad::Modules::SystemBackendProc::registerBackend(); -} - -void deinit() { - Mad::Modules::SystemBackendProc::unregisterBackend(); -} - -} diff --git a/src/modules/SystemBackendProc.h b/src/modules/SystemBackendProc.h deleted file mode 100644 index bf19e22..0000000 --- a/src/modules/SystemBackendProc.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SystemBackendProc.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 3 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, see . - */ - -#ifndef MAD_MODULES_SYSTEMBACKENDPROC_H_ -#define MAD_MODULES_SYSTEMBACKENDPROC_H_ - -#include - -#include - -namespace Mad { -namespace Modules { - -class SystemBackendProc : private Common::SystemBackend { - private: - static SystemBackendProc *backend; - - std::ifstream uptimeFile; - std::ifstream meminfoFile; - std::ifstream loadFile; - - SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {} - - protected: - virtual bool getUptimeInfo(const boost::function2 &callback); - virtual bool getMemoryInfo(const boost::function4 &callback); - virtual bool getLoadInfo(const boost::function5 &callback); - - public: - static void registerBackend() { - if(backend) - return; - - backend = new SystemBackendProc(); - Common::SystemManager::get()->registerBackend(backend); - } - - static void unregisterBackend() { - if(!backend) - return; - - Common::SystemManager::get()->unregisterBackend(backend); - delete backend; - backend = 0; - } -}; - -} -} - -#endif /* MAD_MODULES_SYSTEMBACKENDPROC_H_ */ diff --git a/src/modules/SystemBackendProc/SystemBackendProc.cpp b/src/modules/SystemBackendProc/SystemBackendProc.cpp new file mode 100644 index 0000000..68f9cec --- /dev/null +++ b/src/modules/SystemBackendProc/SystemBackendProc.cpp @@ -0,0 +1,134 @@ +/* + * SystemBackendProc.cpp + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 3 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, see . + */ + +#include "SystemBackendProc.h" + +#include + +#include +#include + +#include + +#define init SystemBackendProc_LTX_init +#define deinit SystemBackendProc_LTX_deinit + +namespace Mad { +namespace Modules { + +SystemBackendProc *SystemBackendProc::backend = 0; + +bool SystemBackendProc::getUptimeInfo(const boost::function2 &callback) { + unsigned long uptime = 0, idleTime = 0; + + uptimeFile.seekg(0, std::ios::beg); + + if(!uptimeFile.good()) + return false; + + float f; + uptimeFile >> f; + if(!uptimeFile.good()) + return false; + + uptime = (unsigned long)f; + + uptimeFile >> f; + if(uptimeFile.good()) + idleTime = (unsigned long)f; + + Common::ActionManager::get()->add(boost::bind(callback, uptime, idleTime)); + + return true; +} + +bool SystemBackendProc::getMemoryInfo(const boost::function4 &callback) { + unsigned long totalMem = 0, freeMem = 0, totalSwap = 0, freeSwap = 0; + + meminfoFile.seekg(0, std::ios::beg); + + if(!meminfoFile.good()) + return false; + + while(!meminfoFile.eof() && meminfoFile.good()) { + std::string line; + std::getline(meminfoFile, line); + + char *name = new char[line.length()+1]; // is always long enough + unsigned long value; + + if(std::sscanf(line.c_str(), "%s %lu", name, &value) == 2) { + if(std::strcmp(name, "MemTotal:") == 0) + totalMem = value; + else if(std::strcmp(name, "MemFree:") == 0) + freeMem = value; + else if(std::strcmp(name, "SwapTotal:") == 0) + totalSwap = value; + else if(std::strcmp(name, "SwapFree:") == 0) + freeSwap = value; + } + + delete [] name; + + if(totalMem && freeMem && totalSwap && freeSwap) + break; + } + + Common::ActionManager::get()->add(boost::bind(callback, totalMem, freeMem, totalSwap, freeSwap)); + + return true; +} + +bool SystemBackendProc::getLoadInfo(const boost::function5 &callback) { + unsigned long currentLoad = 0, nProcesses = 0; + float loadAvg1 = 0, loadAvg5 = 0, loadAvg15 = 0; + + loadFile.seekg(0, std::ios::beg); + + if(!loadFile.good()) + return false; + + std::string line; + std::getline(loadFile, line); + + if(line.empty()) + return false; + + std::sscanf(line.c_str(), "%f %f %f %lu/%lu", &loadAvg1, &loadAvg5, &loadAvg15, ¤tLoad, &nProcesses); + + Common::ActionManager::get()->add(boost::bind(callback, currentLoad, nProcesses, loadAvg1, loadAvg5, loadAvg15)); + + return true; +} + +} +} + + +extern "C" { + +void init() { + Mad::Modules::SystemBackendProc::registerBackend(); +} + +void deinit() { + Mad::Modules::SystemBackendProc::unregisterBackend(); +} + +} diff --git a/src/modules/SystemBackendProc/SystemBackendProc.h b/src/modules/SystemBackendProc/SystemBackendProc.h new file mode 100644 index 0000000..bf19e22 --- /dev/null +++ b/src/modules/SystemBackendProc/SystemBackendProc.h @@ -0,0 +1,67 @@ +/* + * SystemBackendProc.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 3 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, see . + */ + +#ifndef MAD_MODULES_SYSTEMBACKENDPROC_H_ +#define MAD_MODULES_SYSTEMBACKENDPROC_H_ + +#include + +#include + +namespace Mad { +namespace Modules { + +class SystemBackendProc : private Common::SystemBackend { + private: + static SystemBackendProc *backend; + + std::ifstream uptimeFile; + std::ifstream meminfoFile; + std::ifstream loadFile; + + SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo"), loadFile("/proc/loadavg") {} + + protected: + virtual bool getUptimeInfo(const boost::function2 &callback); + virtual bool getMemoryInfo(const boost::function4 &callback); + virtual bool getLoadInfo(const boost::function5 &callback); + + public: + static void registerBackend() { + if(backend) + return; + + backend = new SystemBackendProc(); + Common::SystemManager::get()->registerBackend(backend); + } + + static void unregisterBackend() { + if(!backend) + return; + + Common::SystemManager::get()->unregisterBackend(backend); + delete backend; + backend = 0; + } +}; + +} +} + +#endif /* MAD_MODULES_SYSTEMBACKENDPROC_H_ */ diff --git a/src/modules/UserBackendMysql.cpp b/src/modules/UserBackendMysql.cpp deleted file mode 100644 index af25f5b..0000000 --- a/src/modules/UserBackendMysql.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - * UserBackendMysql.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 3 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, see . - */ - -#include - -#include "UserBackendMysql.h" -#include -#include -#include -#include - -#include - -#include -#include - -#define init UserBackendMysql_LTX_init -#define deinit UserBackendMysql_LTX_deinit - - -namespace Mad { -namespace Modules { - -UserBackendMysql *UserBackendMysql::backend; - -bool UserBackendMysql::handleConfigEntry(const Common::ConfigEntry &entry, bool handled) { - if(handled) - return false; - - if(entry[0].getKey().matches("UserBackendMysql")) { - if(entry[1].getKey().matches("Host")) { - if(entry[2].empty()) - host = entry[1][0]; - } - else if(entry[1].getKey().matches("Username")) { - if(entry[2].empty()) - username = entry[1][0]; - } - else if(entry[1].getKey().matches("Password")) { - if(entry[2].empty()) - passwd = entry[1][0]; - } - else if(entry[1].getKey().matches("Database")) { - if(entry[2].empty()) - db = entry[1][0]; - } - else if(entry[1].getKey().matches("Port")) { - if(entry[2].empty()) { - char *endptr; - long val; - - val = strtol(entry[1][0].c_str(), &endptr, 10); - - if(endptr != 0 || val < 0 || val > 65535) - Common::Logger::log(Common::Logger::WARNING, "UserBackendMysql: Invalid port"); - else - port = val; - } - } - else if(entry[1].getKey().matches("UnixSocket")) { - if(entry[2].empty()) - unixSocket = entry[1][0]; - } - else if(entry[1].getKey().matches("Queries")) { - if(entry[2].getKey().matches("ListUsers")) { - if(entry[3].empty()) - queryListUsers = entry[2][0]; - } - else if(entry[2].getKey().matches("ListGroups")) { - if(entry[3].empty()) - queryListGroups = entry[2][0]; - } - else if(entry[2].getKey().matches("ListUserGroups")) { - if(entry[3].empty()) - queryListUserGroups = entry[2][0]; - } - else if(entry[2].getKey().matches("ListGroupUsers")) { - if(entry[3].empty()) - queryListGroupUsers = entry[2][0]; - } - else if(entry[2].getKey().matches("UserById")) { - if(entry[3].empty()) - queryUserById = entry[2][0]; - } - else if(entry[2].getKey().matches("UserByName")) { - if(entry[3].empty()) - queryUserByName = entry[2][0]; - } - else if(entry[2].getKey().matches("GroupById")) { - if(entry[3].empty()) - queryGroupById = entry[2][0]; - } - else if(entry[2].getKey().matches("GroupByName")) { - if(entry[3].empty()) - queryGroupByName = entry[2][0]; - } - else if(!entry[2].empty()) - return false; - } - else if(!entry[1].empty()) - return false; - - return true; - } - - return false; -} - -void UserBackendMysql::configFinished() { - if(db.empty()) { - Common::Logger::log(Common::Logger::ERROR, "UserBackendMysql: No database name given"); - return; - } - - mysql = mysql_init(0); - mysql_real_connect(mysql, host.c_str(), username.c_str(), passwd.c_str(), db.c_str(), port, unixSocket.empty() ? 0 : unixSocket.c_str(), 0); - - Server::UserManager::get()->registerBackend(backend); -} - - -bool UserBackendMysql::getUserList(const boost::function1& > &callback) { - mysql_ping(mysql); - - mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length()); - MYSQL_RES *result = mysql_use_result(mysql); - - if(mysql_num_fields(result) < 4) - return true; // TODO Error - - std::map users; - - while(MYSQL_ROW row = mysql_fetch_row(result)) { - Common::UserInfo user(strtoul(row[0], 0, 10), row[2]); - - user.setGid(strtoul(row[1], 0, 10)); - user.setFullName(row[3]); - - users.insert(std::make_pair(user.getUid(), user)); - } - - Common::ActionManager::get()->add(boost::bind(callback, users)); - - return true; -} - -bool UserBackendMysql::getUserInfo(unsigned long uid, const boost::function1 &callback) { - mysql_ping(mysql); - - std::string query = queryUserById; - - std::ostringstream tmp; - tmp << '"'; - tmp << uid; - tmp << '"'; - - query = boost::regex_replace(query, boost::regex("\\{ID\\}"), tmp.str(), boost::match_default); - - mysql_real_query(mysql, query.c_str(), query.length()); - MYSQL_RES *result = mysql_use_result(mysql); - - if(mysql_num_fields(result) < 4) - return true; // TODO Error - - MYSQL_ROW row = mysql_fetch_row(result); - - if(row) { - Common::UserInfo user(strtoul(row[0], 0, 10), row[2]); - - user.setGid(strtoul(row[1], 0, 10)); - user.setFullName(row[3]); - - Common::ActionManager::get()->add(boost::bind(callback, user)); - - while((row = mysql_fetch_row(result)) != 0) {} - } - else { - Common::ActionManager::get()->add(boost::bind(callback, Common::UserInfo())); - } - - return true; -} - - -void UserBackendMysql::registerBackend() { - if(backend) - return; - - backend = new UserBackendMysql(); - Common::ConfigManager::get()->registerConfigurable(backend); -} - -void UserBackendMysql::unregisterBackend() { - if(!backend) - return; - - Common::ConfigManager::get()->unregisterConfigurable(backend); - Server::UserManager::get()->unregisterBackend(backend); - - delete backend; - backend = 0; -} - -} -} - -extern "C" { - -void init() { - Mad::Modules::UserBackendMysql::registerBackend(); -} - -void deinit() { - Mad::Modules::UserBackendMysql::unregisterBackend(); -} - -} diff --git a/src/modules/UserBackendMysql.h b/src/modules/UserBackendMysql.h deleted file mode 100644 index 2e4f1ff..0000000 --- a/src/modules/UserBackendMysql.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * UserBackendMysql.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 3 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, see . - */ - -#ifndef MAD_MODULES_USERBACKENDMYSQL_H_ -#define MAD_MODULES_USERBACKENDMYSQL_H_ - -#include -#include -#include - -#include - - -namespace Mad { -namespace Modules { - -class UserBackendMysql : private Server::UserBackend, private Common::Configurable { - private: - static UserBackendMysql *backend; - - std::string host, username, passwd, db, unixSocket; - uint16_t port; - - std::string queryListUsers, queryListGroups; - std::string queryListUserGroups, queryListGroupUsers; - std::string queryUserById, queryUserByName; - std::string queryGroupById, queryGroupByName; - - MYSQL *mysql; - - UserBackendMysql() : port(0), mysql(0) {} - - protected: - virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool); - virtual void configFinished(); - - virtual bool getUserList(const boost::function1& > &callback); - virtual bool getUserInfo(unsigned long uid, const boost::function1 &callback); - - public: - virtual ~UserBackendMysql() { - if(mysql) { - mysql_close(mysql); - mysql = 0; - } - } - - static void registerBackend(); - static void unregisterBackend(); -}; - -} -} - -#endif /* MAD_MODULES_USERBACKENDMYSQL_H_ */ diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp new file mode 100644 index 0000000..af25f5b --- /dev/null +++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp @@ -0,0 +1,233 @@ +/* + * UserBackendMysql.cpp + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 3 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, see . + */ + +#include + +#include "UserBackendMysql.h" +#include +#include +#include +#include + +#include + +#include +#include + +#define init UserBackendMysql_LTX_init +#define deinit UserBackendMysql_LTX_deinit + + +namespace Mad { +namespace Modules { + +UserBackendMysql *UserBackendMysql::backend; + +bool UserBackendMysql::handleConfigEntry(const Common::ConfigEntry &entry, bool handled) { + if(handled) + return false; + + if(entry[0].getKey().matches("UserBackendMysql")) { + if(entry[1].getKey().matches("Host")) { + if(entry[2].empty()) + host = entry[1][0]; + } + else if(entry[1].getKey().matches("Username")) { + if(entry[2].empty()) + username = entry[1][0]; + } + else if(entry[1].getKey().matches("Password")) { + if(entry[2].empty()) + passwd = entry[1][0]; + } + else if(entry[1].getKey().matches("Database")) { + if(entry[2].empty()) + db = entry[1][0]; + } + else if(entry[1].getKey().matches("Port")) { + if(entry[2].empty()) { + char *endptr; + long val; + + val = strtol(entry[1][0].c_str(), &endptr, 10); + + if(endptr != 0 || val < 0 || val > 65535) + Common::Logger::log(Common::Logger::WARNING, "UserBackendMysql: Invalid port"); + else + port = val; + } + } + else if(entry[1].getKey().matches("UnixSocket")) { + if(entry[2].empty()) + unixSocket = entry[1][0]; + } + else if(entry[1].getKey().matches("Queries")) { + if(entry[2].getKey().matches("ListUsers")) { + if(entry[3].empty()) + queryListUsers = entry[2][0]; + } + else if(entry[2].getKey().matches("ListGroups")) { + if(entry[3].empty()) + queryListGroups = entry[2][0]; + } + else if(entry[2].getKey().matches("ListUserGroups")) { + if(entry[3].empty()) + queryListUserGroups = entry[2][0]; + } + else if(entry[2].getKey().matches("ListGroupUsers")) { + if(entry[3].empty()) + queryListGroupUsers = entry[2][0]; + } + else if(entry[2].getKey().matches("UserById")) { + if(entry[3].empty()) + queryUserById = entry[2][0]; + } + else if(entry[2].getKey().matches("UserByName")) { + if(entry[3].empty()) + queryUserByName = entry[2][0]; + } + else if(entry[2].getKey().matches("GroupById")) { + if(entry[3].empty()) + queryGroupById = entry[2][0]; + } + else if(entry[2].getKey().matches("GroupByName")) { + if(entry[3].empty()) + queryGroupByName = entry[2][0]; + } + else if(!entry[2].empty()) + return false; + } + else if(!entry[1].empty()) + return false; + + return true; + } + + return false; +} + +void UserBackendMysql::configFinished() { + if(db.empty()) { + Common::Logger::log(Common::Logger::ERROR, "UserBackendMysql: No database name given"); + return; + } + + mysql = mysql_init(0); + mysql_real_connect(mysql, host.c_str(), username.c_str(), passwd.c_str(), db.c_str(), port, unixSocket.empty() ? 0 : unixSocket.c_str(), 0); + + Server::UserManager::get()->registerBackend(backend); +} + + +bool UserBackendMysql::getUserList(const boost::function1& > &callback) { + mysql_ping(mysql); + + mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length()); + MYSQL_RES *result = mysql_use_result(mysql); + + if(mysql_num_fields(result) < 4) + return true; // TODO Error + + std::map users; + + while(MYSQL_ROW row = mysql_fetch_row(result)) { + Common::UserInfo user(strtoul(row[0], 0, 10), row[2]); + + user.setGid(strtoul(row[1], 0, 10)); + user.setFullName(row[3]); + + users.insert(std::make_pair(user.getUid(), user)); + } + + Common::ActionManager::get()->add(boost::bind(callback, users)); + + return true; +} + +bool UserBackendMysql::getUserInfo(unsigned long uid, const boost::function1 &callback) { + mysql_ping(mysql); + + std::string query = queryUserById; + + std::ostringstream tmp; + tmp << '"'; + tmp << uid; + tmp << '"'; + + query = boost::regex_replace(query, boost::regex("\\{ID\\}"), tmp.str(), boost::match_default); + + mysql_real_query(mysql, query.c_str(), query.length()); + MYSQL_RES *result = mysql_use_result(mysql); + + if(mysql_num_fields(result) < 4) + return true; // TODO Error + + MYSQL_ROW row = mysql_fetch_row(result); + + if(row) { + Common::UserInfo user(strtoul(row[0], 0, 10), row[2]); + + user.setGid(strtoul(row[1], 0, 10)); + user.setFullName(row[3]); + + Common::ActionManager::get()->add(boost::bind(callback, user)); + + while((row = mysql_fetch_row(result)) != 0) {} + } + else { + Common::ActionManager::get()->add(boost::bind(callback, Common::UserInfo())); + } + + return true; +} + + +void UserBackendMysql::registerBackend() { + if(backend) + return; + + backend = new UserBackendMysql(); + Common::ConfigManager::get()->registerConfigurable(backend); +} + +void UserBackendMysql::unregisterBackend() { + if(!backend) + return; + + Common::ConfigManager::get()->unregisterConfigurable(backend); + Server::UserManager::get()->unregisterBackend(backend); + + delete backend; + backend = 0; +} + +} +} + +extern "C" { + +void init() { + Mad::Modules::UserBackendMysql::registerBackend(); +} + +void deinit() { + Mad::Modules::UserBackendMysql::unregisterBackend(); +} + +} diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h new file mode 100644 index 0000000..2e4f1ff --- /dev/null +++ b/src/modules/UserBackendMysql/UserBackendMysql.h @@ -0,0 +1,71 @@ +/* + * UserBackendMysql.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 3 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, see . + */ + +#ifndef MAD_MODULES_USERBACKENDMYSQL_H_ +#define MAD_MODULES_USERBACKENDMYSQL_H_ + +#include +#include +#include + +#include + + +namespace Mad { +namespace Modules { + +class UserBackendMysql : private Server::UserBackend, private Common::Configurable { + private: + static UserBackendMysql *backend; + + std::string host, username, passwd, db, unixSocket; + uint16_t port; + + std::string queryListUsers, queryListGroups; + std::string queryListUserGroups, queryListGroupUsers; + std::string queryUserById, queryUserByName; + std::string queryGroupById, queryGroupByName; + + MYSQL *mysql; + + UserBackendMysql() : port(0), mysql(0) {} + + protected: + virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool); + virtual void configFinished(); + + virtual bool getUserList(const boost::function1& > &callback); + virtual bool getUserInfo(unsigned long uid, const boost::function1 &callback); + + public: + virtual ~UserBackendMysql() { + if(mysql) { + mysql_close(mysql); + mysql = 0; + } + } + + static void registerBackend(); + static void unregisterBackend(); +}; + +} +} + +#endif /* MAD_MODULES_USERBACKENDMYSQL_H_ */ -- cgit v1.2.3