From: Sebastian Harl Date: Wed, 2 Jan 2013 21:10:00 +0000 (+0100) Subject: Renamed the project to SysDB (System DataBase). X-Git-Tag: sysdb-0.1.0~442 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bef7167f0dc1fd405e35d5cbffb3c0820945a9ea;p=sysdb.git Renamed the project to SysDB (System DataBase). This name more closely resembles the actual intent / goal of the project. The prefix for defines / function / etc. has been changed to sdb_. --- diff --git a/.gitignore b/.gitignore index 5edd76f..076c35e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,13 +6,14 @@ m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 +src/config.h* .deps Makefile Makefile.in aclocal.m4 autom4te.cache compile -config.* +/config.* configure depcomp install-sh @@ -35,7 +36,7 @@ src/liboconfig/scanner.c *.la *.lo *.o -syscollectord -syscollectord.1 -syscollector.h +sysdbd +sysdbd.1 +sysdb.h diff --git a/README b/README index 20cbce9..55a8be8 100644 --- a/README +++ b/README @@ -1,21 +1,21 @@ - syscollector -- a system management / inventory collection service - ==================================================================== - - “System Collector” (syscollector) is a multi-backend system management and - inventory collection service. It may be used to collect information from - various backends (inventory services, monitoring services, etc.) and - provides a unique interface to access the information independent of the - active backends. This is done by mapping the backend objects to generic - objects and correlating the attributes to create a single hierarchy of your - infrastructure. - - This is free and open source software, licensed under the 2-clause BSD + SysDB -- a system management and inventory collection service + =============================================================== + + “System DataBase” (SysDB) is a multi-backend system management and inventory + collection service. It may be used to (continuously) collect information + about your systems from various backends (inventory services, monitoring + services, etc.) and provides a unique interface to access the information + independent of the active backends. This is done by storing and mapping the + backend objects to generic objects and correlating the attributes to create + a single hierarchical view of your infrastructure. + + SysDB is free and open source software, licensed under the 2-clause BSD license. See COPYING for details. Prerequisites ------------- - To compile the syscollector package from source you need: + To compile the SysDB package from source you need: * A build environment: autotools, libtool, C compiler, ... @@ -27,16 +27,16 @@ Prerequisites Configuring / Compiling / Installing ------------------------------------ - To configure, build and install syscollector with the default settings, run + To configure, build and install SysDB with the default settings, run `./configure && make && make install'. For detailed, generic instructions see INSTALL. For a complete list of configure options and their description, run `./configure --help'. - By default, syscollector will be installed into `/opt/syscollector'. You can - adjust this setting by specifying the `--prefix' configure option - see - INSTALL for details. If you pass DESTDIR= to `make install', - will be prefixed to all installation directories. This might be useful when - creating packages for syscollector. + By default, SysDB will be installed into `/opt/sysdb'. You can adjust this + setting by specifying the `--prefix' configure option - see INSTALL for + details. If you pass DESTDIR= to `make install', will be + prefixed to all installation directories. This might be useful when creating + packages for SysDB. Author ------ diff --git a/THANKS b/THANKS index 5424ef9..e58d4f3 100644 --- a/THANKS +++ b/THANKS @@ -1,4 +1,4 @@ Special thanks goes to Florian 'octo' Forster and everybody involved in collectd . The project has greatly -influenced the architectural design of syscollector. +influenced the architectural design of SysDB. diff --git a/configure.ac b/configure.ac index c970c1d..fac681d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. dnl -dnl This is the syscollector configure script. +dnl This is the SysDB configure script. dnl dnl Copyright (C) 2012 Sebastian 'tokkee' Harl dnl All rights reserved. @@ -26,16 +26,16 @@ dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF dnl ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -AC_INIT([system collector],[m4_esyscmd(./version-gen.sh)], +AC_INIT([System DataBase],[m4_esyscmd(./version-gen.sh)], [sh@tokkee.org], - [syscollector], - [http://git.tokkee.org/?p=syscollector.git]) + [SysDB], + [http://git.tokkee.org/?p=sysdb.git]) PACKAGE_MAINTAINER="Sebastian 'tokkee' Harl " AC_DEFINE_UNQUOTED([PACKAGE_MAINTAINER], ["$PACKAGE_MAINTAINER"], [Define to the name of the maintainer of this package.]) -AC_CONFIG_SRCDIR([src/syscollector.c]) +AC_CONFIG_SRCDIR([src/sysdb.c]) AC_CONFIG_HEADERS([src/config.h]) -AC_PREFIX_DEFAULT([/opt/syscollector]) +AC_PREFIX_DEFAULT([/opt/sysdb]) AM_INIT_AUTOMAKE([foreign -Wall]) @@ -231,12 +231,12 @@ fi m4_divert_once([HELP_ENABLE], [ Backends:]) -AC_SC_PLUGIN_INIT -AC_SC_PLUGIN([collectd], [yes], +AC_SDB_PLUGIN_INIT +AC_SDB_PLUGIN([collectd], [yes], [backend accessing the system statistics collection daemon]) -AC_SC_PLUGIN([mk-livestatus], [yes], +AC_SDB_PLUGIN([mk-livestatus], [yes], [backend accessing Nagios/Icinga/Shinken using MK Livestatus]) -AC_SC_PLUGIN([puppet-storeconfigs], [$enable_puppet_storeconfigs], +AC_SDB_PLUGIN([puppet-storeconfigs], [$enable_puppet_storeconfigs], [backend accessing the Puppet stored configuration database]) AM_CONDITIONAL([BUILD_DOCUMENTATION], test "x$build_documentation" = "xyes") diff --git a/doc/Makefile.am b/doc/Makefile.am index b658384..029d95e 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,9 +1,9 @@ -EXTRA_DIST = syscollectord.1.txt -CLEANFILES = syscollectord.1 +EXTRA_DIST = sysdbd.1.txt +CLEANFILES = sysdbd.1 -man_MANS = syscollectord.1 +man_MANS = sysdbd.1 -syscollectord.1: syscollectord.1.txt ../version +sysdbd.1: sysdbd.1.txt ../version %.1: %.1.txt @A2X@ -d manpage -f manpage \ diff --git a/doc/syscollectord.1.txt b/doc/syscollectord.1.txt deleted file mode 100644 index 70b1b38..0000000 --- a/doc/syscollectord.1.txt +++ /dev/null @@ -1,71 +0,0 @@ -syscollectord(1) -================ -Sebastian "tokkee" Harl -version {package_version}, {build_date} -:doctype: manpage - -NAME ----- -syscollectord - system management collection service - -SYNOPSIS --------- -*syscollectord* ['options'] - -DESCRIPTION ------------ -*syscollectord* is a multi-backend system management and inventory collection -daemon. It may be used to collect information from various backends (e.g., -inventory services, monitoring services, configuration services) and provides -a uniform combined view of all data. - -The main daemon itself is the central instance managing all collected -information and doing the correlation of objects provided by different -backends. It can be thought of as a database server. All data retrieval, -any further processing, storing and exporting of data is done by plugins. - -OPTIONS -------- -*syscollectord* accepts the following command-line options. - -*-C* '':: - The main configuration file. This file defines the behavior of - *syscollectord* by specifying default settings and the plugins to be - loaded. - -*-d*:: - Daemonize on startup: Start *syscollectord* as a background process - detached from the current terminal and session. - -*-h*:: - Display a usage and help summary and exit. - -*-V*:: - Display the version number and copyright information. - -EXIT CODES ----------- -*0*:: - Success. - -*1*:: - Failure (syntax or usage error). - -BUGS ----- -None known. - -AUTHOR ------- -syscollectord was written by Sebastian "tokkee" Harl . - -COPYRIGHT ---------- -Copyright (C) 2012 Sebastian "tokkee" Harl - -This is free software under the terms of the BSD license, see the source for -copying conditions. There is NO WARRANTY; not even for MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. - -// vim: set tw=78 sw=4 ts=4 noexpandtab spell spelllang=en_us : - diff --git a/doc/sysdbd.1.txt b/doc/sysdbd.1.txt new file mode 100644 index 0000000..33ec8cf --- /dev/null +++ b/doc/sysdbd.1.txt @@ -0,0 +1,70 @@ +sysdbd(1) +========= +Sebastian "tokkee" Harl +version {package_version}, {build_date} +:doctype: manpage + +NAME +---- +sysdbd - system management and inventory collection service + +SYNOPSIS +-------- +*sysdbd* ['options'] + +DESCRIPTION +----------- +*sysdbd* is a multi-backend system management and inventory collection daemon. +It may be used to (continuously) collect information from various backends +(e.g., inventory services, monitoring services, configuration services) and +provides a uniform combined view of all data. + +The main daemon itself is the central instance managing all collected +information and doing the correlation of objects provided by different +backends. It basically acts as a database server. All data retrieval, any +further processing, storing and exporting of data is done by plugins. + +OPTIONS +------- +*sysdbd* accepts the following command-line options. + +*-C* '':: + The main configuration file. This file defines the behavior of *sysdbd* by + specifying default settings and the plugins to be loaded. + +*-d*:: + Daemonize on startup: Start *sysdbd* as a background process detached from + the current terminal and session. + +*-h*:: + Display a usage and help summary and exit. + +*-V*:: + Display the version number and copyright information. + +EXIT CODES +---------- +*0*:: + Success. + +*1*:: + Failure (syntax or usage error). + +BUGS +---- +None known. + +AUTHOR +------ +sysdbd was written by Sebastian "tokkee" Harl . + +COPYRIGHT +--------- +Copyright (C) 2012 Sebastian "tokkee" Harl + +This is free software under the terms of the BSD license, see the source for +copying conditions. There is NO WARRANTY; not even for MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. + +// vim: set tw=78 sw=4 ts=4 noexpandtab spell spelllang=en_us : + diff --git a/m4/sc_plugin.m4 b/m4/sc_plugin.m4 deleted file mode 100644 index fccc087..0000000 --- a/m4/sc_plugin.m4 +++ /dev/null @@ -1,85 +0,0 @@ -dnl Autoconf helper functions for the syscollector plugin handling. -dnl -dnl Copyright (C) 2005-2012 Florian 'octo' Forster -dnl Copyright (C) 2009-2012 Sebastian 'tokkee' Harl -dnl -dnl This program is free software; you can redistribute it and/or modify it -dnl under the terms of the GNU General Public License as published by the -dnl Free Software Foundation; only version 2 of the License is applicable. -dnl -dnl This program is distributed in the hope that it will be useful, but -dnl WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -dnl General Public License for more details. -dnl -dnl You should have received a copy of the GNU General Public License along -dnl with this program; if not, write to the Free Software Foundation, Inc., -dnl 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -AC_DEFUN([AC_SC_PLUGIN_INIT], - [ - dependency_error="no" - dependency_warning="no" - AC_ARG_ENABLE([all-plugins], - AS_HELP_STRING([--enable-all-plugins], - [enable all plugins (auto by default)]), - [ - if test "x$enableval" = "xyes"; then - enable_all_plugins="yes" - else if test "x$enableval" = "xauto"; then - enable_all_plugins="auto" - else - enable_all_plugins="no" - fi; fi - ], - [enable_all_plugins="auto"] - ) - ] -) - -dnl AC_SC_PLUGIN(name, default, info) -dnl -dnl Based on AC_PLUGIN of the collectd package. -AC_DEFUN([AC_SC_PLUGIN], - [ - enable_plugin="no" - force="no" - AC_ARG_ENABLE([$1], AS_HELP_STRING([--enable-$1], [$3]), - [ - if test "x$enableval" = "xyes"; then - enable_plugin="yes" - else if test "x$enableval" = "xforce"; then - enable_plugin="yes" - force="yes" - else - enable_plugin="no (disabled on command line)" - fi; fi - ], - [ - if test "x$enable_all_plugins" = "xauto"; then - if test "x$2" = "xyes"; then - enable_plugin="yes" - else - enable_plugin="no" - fi - else - enable_plugin="$enable_all_plugins" - fi - ] - ) - if test "x$enable_plugin" = "xyes"; then - if test "x$2" = "xyes" || test "x$force" = "xyes"; then - AC_DEFINE([HAVE_PLUGIN_]m4_translit(m4_toupper([$1]),[-],[_]), 1, [Define to 1 if the $1 plugin is enabled.]) - if test "x$2" != "xyes"; then - dependency_warning="yes" - fi - else # User passed "yes" but dependency checking yielded "no" => Dependency problem. - dependency_error="yes" - enable_plugin="no (dependency error)" - fi - fi - AM_CONDITIONAL([BUILD_PLUGIN_]m4_translit(m4_toupper([$1]),[-][_]), test "x$enable_plugin" = "xyes") - m4_translit(enable_$1,[-],[_])="$enable_plugin" - ] -) - diff --git a/m4/sdb_plugin.m4 b/m4/sdb_plugin.m4 new file mode 100644 index 0000000..1cf916c --- /dev/null +++ b/m4/sdb_plugin.m4 @@ -0,0 +1,85 @@ +dnl Autoconf helper functions for the SysDB plugin handling. +dnl +dnl Copyright (C) 2005-2012 Florian 'octo' Forster +dnl Copyright (C) 2009-2012 Sebastian 'tokkee' Harl +dnl +dnl This program is free software; you can redistribute it and/or modify it +dnl under the terms of the GNU General Public License as published by the +dnl Free Software Foundation; only version 2 of the License is applicable. +dnl +dnl This program is distributed in the hope that it will be useful, but +dnl WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License along +dnl with this program; if not, write to the Free Software Foundation, Inc., +dnl 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +AC_DEFUN([AC_SDB_PLUGIN_INIT], + [ + dependency_error="no" + dependency_warning="no" + AC_ARG_ENABLE([all-plugins], + AS_HELP_STRING([--enable-all-plugins], + [enable all plugins (auto by default)]), + [ + if test "x$enableval" = "xyes"; then + enable_all_plugins="yes" + else if test "x$enableval" = "xauto"; then + enable_all_plugins="auto" + else + enable_all_plugins="no" + fi; fi + ], + [enable_all_plugins="auto"] + ) + ] +) + +dnl AC_SDB_PLUGIN(name, default, info) +dnl +dnl Based on AC_PLUGIN of the collectd package. +AC_DEFUN([AC_SDB_PLUGIN], + [ + enable_plugin="no" + force="no" + AC_ARG_ENABLE([$1], AS_HELP_STRING([--enable-$1], [$3]), + [ + if test "x$enableval" = "xyes"; then + enable_plugin="yes" + else if test "x$enableval" = "xforce"; then + enable_plugin="yes" + force="yes" + else + enable_plugin="no (disabled on command line)" + fi; fi + ], + [ + if test "x$enable_all_plugins" = "xauto"; then + if test "x$2" = "xyes"; then + enable_plugin="yes" + else + enable_plugin="no" + fi + else + enable_plugin="$enable_all_plugins" + fi + ] + ) + if test "x$enable_plugin" = "xyes"; then + if test "x$2" = "xyes" || test "x$force" = "xyes"; then + AC_DEFINE([HAVE_PLUGIN_]m4_translit(m4_toupper([$1]),[-],[_]), 1, [Define to 1 if the $1 plugin is enabled.]) + if test "x$2" != "xyes"; then + dependency_warning="yes" + fi + else # User passed "yes" but dependency checking yielded "no" => Dependency problem. + dependency_error="yes" + enable_plugin="no (dependency error)" + fi + fi + AM_CONDITIONAL([BUILD_PLUGIN_]m4_translit(m4_toupper([$1]),[-][_]), test "x$enable_plugin" = "xyes") + m4_translit(enable_$1,[-],[_])="$enable_plugin" + ] +) + diff --git a/src/Makefile.am b/src/Makefile.am index 2e3eb45..787ecda 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,9 +4,9 @@ AM_CFLAGS = @STRICT_CFLAGS@ -Iinclude AM_CPPFLAGS = -DSYSCONFDIR='"${sysconfdir}"' AM_CPPFLAGS += -DPKGLIBDIR='"${pkglibdir}"' -BUILT_SOURCES = include/syscollector.h +BUILT_SOURCES = include/sysdb.h -pkginclude_HEADERS = include/syscollector.h +pkginclude_HEADERS = include/sysdb.h pkgcoreincludedir = $(pkgincludedir)/core pkgcoreinclude_HEADERS = \ include/core/object.h \ @@ -16,10 +16,10 @@ pkgutilsinclude_HEADERS = \ include/utils/llist.h \ include/utils/string.h -lib_LTLIBRARIES = libsyscollector.la +lib_LTLIBRARIES = libsysdb.la -libsyscollector_la_SOURCES = \ - syscollector.c include/syscollector.h \ +libsysdb_la_SOURCES = \ + sysdb.c include/sysdb.h \ core/object.c include/core/object.h \ core/plugin.c include/core/plugin.h \ core/store.c include/core/store.h \ @@ -28,25 +28,25 @@ libsyscollector_la_SOURCES = \ utils/string.c include/utils/string.h \ utils/time.c include/utils/time.h \ utils/unixsock.c include/utils/unixsock.h -libsyscollector_la_CFLAGS = $(AM_CFLAGS) -libsyscollector_la_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL) -libsyscollector_la_LDFLAGS = -version-info 0:0:0 -pthread -libsyscollector_la_LIBADD = $(LIBLTDL) -lrt liboconfig/liboconfig.la -libsyscollector_la_DEPENDENCIES = liboconfig/liboconfig.la +libsysdb_la_CFLAGS = $(AM_CFLAGS) +libsysdb_la_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL) +libsysdb_la_LDFLAGS = -version-info 0:0:0 -pthread +libsysdb_la_LIBADD = $(LIBLTDL) -lrt liboconfig/liboconfig.la +libsysdb_la_DEPENDENCIES = liboconfig/liboconfig.la if BUILD_WITH_LIBDBI -libsyscollector_la_SOURCES += \ +libsysdb_la_SOURCES += \ utils/dbi.c include/utils/dbi.h -libsyscollector_la_LIBADD += -ldbi +libsysdb_la_LIBADD += -ldbi endif -bin_PROGRAMS = syscollectord +bin_PROGRAMS = sysdbd -syscollectord_SOURCES = daemon/syscollectord.c include/syscollector.h \ +sysdbd_SOURCES = daemon/sysdbd.c include/sysdb.h \ daemon/config.c include/daemon/config.h -syscollectord_CFLAGS = $(AM_CFLAGS) -DBUILD_DATE="\"$$( date --utc '+%F %T' ) (UTC)\"" -syscollectord_LDADD = libsyscollector.la liboconfig/liboconfig.la -syscollectord_DEPENDENCIES = liboconfig/liboconfig.la +sysdbd_CFLAGS = $(AM_CFLAGS) -DBUILD_DATE="\"$$( date --utc '+%F %T' ) (UTC)\"" +sysdbd_LDADD = libsysdb.la liboconfig/liboconfig.la +sysdbd_DEPENDENCIES = liboconfig/liboconfig.la pkgbackendlibdir = $(pkglibdir)/backend @@ -56,42 +56,42 @@ if BUILD_PLUGIN_COLLECTD pkgbackendlib_LTLIBRARIES += backend/collectd.la backend_collectd_la_SOURCES = backend/collectd.c backend_collectd_la_LDFLAGS = -module -avoid-version -libsyscollector_la_LIBADD += -dlopen backend/collectd.la -libsyscollector_la_DEPENDENCIES += backend/collectd.la +libsysdb_la_LIBADD += -dlopen backend/collectd.la +libsysdb_la_DEPENDENCIES += backend/collectd.la endif if BUILD_PLUGIN_MKLIVESTATUS pkgbackendlib_LTLIBRARIES += backend/mk-livestatus.la backend_mk_livestatus_la_SOURCES = backend/mk-livestatus.c backend_mk_livestatus_la_LDFLAGS = -module -avoid-version -libsyscollector_la_LIBADD += -dlopen backend/mk-livestatus.la -libsyscollector_la_DEPENDENCIES += backend/mk-livestatus.la +libsysdb_la_LIBADD += -dlopen backend/mk-livestatus.la +libsysdb_la_DEPENDENCIES += backend/mk-livestatus.la endif if BUILD_PLUGIN_PUPPETSTORECONFIGS pkgbackendlib_LTLIBRARIES += backend/puppet-storeconfigs.la backend_puppet_storeconfigs_la_SOURCES = backend/puppet-storeconfigs.c backend_puppet_storeconfigs_la_LDFLAGS = -module -avoid-version -libsyscollector_la_LIBADD += -dlopen backend/puppet-storeconfigs.la -libsyscollector_la_DEPENDENCIES += backend/puppet-storeconfigs.la +libsysdb_la_LIBADD += -dlopen backend/puppet-storeconfigs.la +libsysdb_la_DEPENDENCIES += backend/puppet-storeconfigs.la endif -include/syscollector.h: include/syscollector.h.in ../version +include/sysdb.h: include/sysdb.h.in ../version source ../version; sed \ - -e "s/@SC_VERSION_MAJOR@/$$VERSION_MAJOR/g" \ - -e "s/@SC_VERSION_MINOR@/$$VERSION_MINOR/g" \ - -e "s/@SC_VERSION_PATCH@/$$VERSION_PATCH/g" \ - -e "s/@SC_VERSION_EXTRA@/$$VERSION_EXTRA/g" \ - -e "s/@SC_VERSION_STRING@/$$VERSION_STRING/g" \ - include/syscollector.h.in > include/syscollector.h + -e "s/@SDB_VERSION_MAJOR@/$$VERSION_MAJOR/g" \ + -e "s/@SDB_VERSION_MINOR@/$$VERSION_MINOR/g" \ + -e "s/@SDB_VERSION_PATCH@/$$VERSION_PATCH/g" \ + -e "s/@SDB_VERSION_EXTRA@/$$VERSION_EXTRA/g" \ + -e "s/@SDB_VERSION_STRING@/$$VERSION_STRING/g" \ + include/sysdb.h.in > include/sysdb.h install-exec-hook: - $(mkinstalldirs) $(DESTDIR)$(sysconfdir)/syscollector - if test -e $(DESTDIR)$(sysconfdir)/syscollector/syscollectord.conf; then \ - $(INSTALL) -m 0640 daemon/syscollectord.conf \ - $(DESTDIR)$(sysconfdir)/syscollector/syscollectord.conf.pkg-orig; \ + $(mkinstalldirs) $(DESTDIR)$(sysconfdir)/sysdb + if test -e $(DESTDIR)$(sysconfdir)/sysdb/sysdbd.conf; then \ + $(INSTALL) -m 0640 daemon/sysdbd.conf \ + $(DESTDIR)$(sysconfdir)/sysdb/sysdbd.conf.pkg-orig; \ else \ - $(INSTALL) -m 0640 daemon/syscollectord.conf \ - $(DESTDIR)$(sysconfdir)/syscollector/syscollectord.conf; \ + $(INSTALL) -m 0640 daemon/sysdbd.conf \ + $(DESTDIR)$(sysconfdir)/sysdb/sysdbd.conf; \ fi diff --git a/src/backend/collectd.c b/src/backend/collectd.c index 1cd650e..f745fc9 100644 --- a/src/backend/collectd.c +++ b/src/backend/collectd.c @@ -1,5 +1,5 @@ /* - * syscollector - src/backend/collectd.c + * SysDB - src/backend/collectd.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,7 +25,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "syscollector.h" +#include "sysdb.h" #include "core/plugin.h" #include "core/store.h" #include "utils/string.h" @@ -41,7 +41,7 @@ #include #include -SC_PLUGIN_MAGIC; +SDB_PLUGIN_MAGIC; /* * private data types @@ -49,20 +49,20 @@ SC_PLUGIN_MAGIC; typedef struct { char *current_host; - sc_time_t current_timestamp; + sdb_time_t current_timestamp; int svc_updated; int svc_failed; -} sc_collectd_state_t; -#define SC_COLLECTD_STATE_INIT { NULL, 0, 0, 0 } +} sdb_collectd_state_t; +#define SDB_COLLECTD_STATE_INIT { NULL, 0, 0, 0 } /* * private helper functions */ static int -sc_collectd_add_host(const char *hostname, sc_time_t last_update) +sdb_collectd_add_host(const char *hostname, sdb_time_t last_update) { - sc_host_t host = SC_HOST_INIT; + sdb_host_t host = SDB_HOST_INIT; char name[strlen(hostname) + 1]; int status; @@ -72,7 +72,7 @@ sc_collectd_add_host(const char *hostname, sc_time_t last_update) host.host_name = name; host.host_last_update = last_update; - status = sc_store_host(&host); + status = sdb_store_host(&host); if (status < 0) { fprintf(stderr, "collectd backend: Failed to store/update " @@ -86,13 +86,13 @@ sc_collectd_add_host(const char *hostname, sc_time_t last_update) "(last update timestamp = %"PRIscTIME").\n", name, last_update); return 0; -} /* sc_collectd_add_host */ +} /* sdb_collectd_add_host */ static int -sc_collectd_add_svc(const char *hostname, const char *plugin, - const char *type, sc_time_t last_update) +sdb_collectd_add_svc(const char *hostname, const char *plugin, + const char *type, sdb_time_t last_update) { - sc_service_t svc = SC_SVC_INIT; + sdb_service_t svc = SDB_SVC_INIT; char host[strlen(hostname) + 1]; char name[strlen(plugin) + strlen(type) + 2]; @@ -105,40 +105,40 @@ sc_collectd_add_svc(const char *hostname, const char *plugin, svc.svc_name = name; svc.svc_last_update = last_update; - status = sc_store_service(&svc); + status = sdb_store_service(&svc); if (status < 0) { fprintf(stderr, "collectd backend: Failed to store/update " "service '%s/%s'.\n", host, name); return -1; } return 0; -} /* sc_collectd_add_svc */ +} /* sdb_collectd_add_svc */ static int -sc_collectd_get_data(sc_unixsock_client_t __attribute__((unused)) *client, - size_t n, sc_data_t *data, sc_object_t *user_data) +sdb_collectd_get_data(sdb_unixsock_client_t __attribute__((unused)) *client, + size_t n, sdb_data_t *data, sdb_object_t *user_data) { - sc_collectd_state_t *state; + sdb_collectd_state_t *state; const char *hostname; const char *plugin; const char *type; - sc_time_t last_update; + sdb_time_t last_update; assert(user_data); assert(n == 4); - assert((data[0].type == SC_TYPE_DATETIME) - && (data[1].type == SC_TYPE_STRING) - && (data[2].type == SC_TYPE_STRING) - && (data[3].type == SC_TYPE_STRING)); + assert((data[0].type == SDB_TYPE_DATETIME) + && (data[1].type == SDB_TYPE_STRING) + && (data[2].type == SDB_TYPE_STRING) + && (data[3].type == SDB_TYPE_STRING)); last_update = data[0].data.datetime; hostname = data[1].data.string; plugin = data[2].data.string; type = data[3].data.string; - state = SC_OBJ_WRAPPER(user_data)->data; + state = SDB_OBJ_WRAPPER(user_data)->data; if (! state->current_host) { state->current_host = strdup(hostname); @@ -149,14 +149,14 @@ sc_collectd_get_data(sc_unixsock_client_t __attribute__((unused)) *client, char errbuf[1024]; fprintf(stderr, "collectd backend: Failed to allocate " "string buffer: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } - if (! sc_store_get_host(hostname)) - sc_collectd_add_host(hostname, last_update); + if (! sdb_store_get_host(hostname)) + sdb_collectd_add_host(hostname, last_update); - if (sc_collectd_add_svc(hostname, plugin, type, last_update)) + if (sdb_collectd_add_svc(hostname, plugin, type, last_update)) ++state->svc_failed; else ++state->svc_updated; @@ -168,7 +168,7 @@ sc_collectd_get_data(sc_unixsock_client_t __attribute__((unused)) *client, } /* new host */ - sc_collectd_add_host(hostname, last_update); + sdb_collectd_add_host(hostname, last_update); fprintf(stderr, "collectd backend: Added/updated " "%i service%s (%i failed) for host '%s'.\n", @@ -180,22 +180,22 @@ sc_collectd_get_data(sc_unixsock_client_t __attribute__((unused)) *client, state->current_host = strdup(hostname); state->current_timestamp = last_update; return 0; -} /* sc_collectd_get_data */ +} /* sdb_collectd_get_data */ /* * plugin API */ static int -sc_collectd_init(sc_object_t *user_data) +sdb_collectd_init(sdb_object_t *user_data) { - sc_unixsock_client_t *client; + sdb_unixsock_client_t *client; if (! user_data) return -1; - client = SC_OBJ_WRAPPER(user_data)->data; - if (sc_unixsock_client_connect(client)) { + client = SDB_OBJ_WRAPPER(user_data)->data; + if (sdb_unixsock_client_connect(client)) { fprintf(stderr, "collectd backend: " "Failed to connect to collectd.\n"); return -1; @@ -203,20 +203,20 @@ sc_collectd_init(sc_object_t *user_data) fprintf(stderr, "collectd backend: Successfully " "connected to collectd @ %s.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return 0; -} /* sc_collectd_init */ +} /* sdb_collectd_init */ static int -sc_collectd_shutdown(__attribute__((unused)) sc_object_t *user_data) +sdb_collectd_shutdown(__attribute__((unused)) sdb_object_t *user_data) { return 0; -} /* sc_collectd_shutdown */ +} /* sdb_collectd_shutdown */ static int -sc_collectd_collect(sc_object_t *user_data) +sdb_collectd_collect(sdb_object_t *user_data) { - sc_unixsock_client_t *client; + sdb_unixsock_client_t *client; char buffer[1024]; char *line; @@ -225,26 +225,26 @@ sc_collectd_collect(sc_object_t *user_data) char *endptr = NULL; long int count; - sc_collectd_state_t state = SC_COLLECTD_STATE_INIT; - sc_object_wrapper_t state_obj = SC_OBJECT_WRAPPER_STATIC(&state, + sdb_collectd_state_t state = SDB_COLLECTD_STATE_INIT; + sdb_object_wrapper_t state_obj = SDB_OBJECT_WRAPPER_STATIC(&state, /* destructor = */ NULL); if (! user_data) return -1; - client = SC_OBJ_WRAPPER(user_data)->data; + client = SDB_OBJ_WRAPPER(user_data)->data; - if (sc_unixsock_client_send(client, "LISTVAL") <= 0) { + if (sdb_unixsock_client_send(client, "LISTVAL") <= 0) { fprintf(stderr, "collectd backend: Failed to send LISTVAL command " - "to collectd @ %s.\n", sc_unixsock_client_path(client)); + "to collectd @ %s.\n", sdb_unixsock_client_path(client)); return -1; } - line = sc_unixsock_client_recv(client, buffer, sizeof(buffer)); + line = sdb_unixsock_client_recv(client, buffer, sizeof(buffer)); if (! line) { fprintf(stderr, "collectd backend: Failed to read status " "of LISTVAL command from collectd @ %s.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return -1; } @@ -259,47 +259,47 @@ sc_collectd_collect(sc_object_t *user_data) if (errno || (line == endptr)) { fprintf(stderr, "collectd backend: Failed to parse status " "of LISTVAL command from collectd @ %s.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return -1; } if (count < 0) { fprintf(stderr, "collectd backend: Failed to get value list " - "from collectd @ %s: %s\n", sc_unixsock_client_path(client), + "from collectd @ %s: %s\n", sdb_unixsock_client_path(client), msg ? msg : line); return -1; } - if (sc_unixsock_client_process_lines(client, sc_collectd_get_data, - SC_OBJ(&state_obj), count, /* delim */ " /", + if (sdb_unixsock_client_process_lines(client, sdb_collectd_get_data, + SDB_OBJ(&state_obj), count, /* delim */ " /", /* column count = */ 4, - SC_TYPE_DATETIME, SC_TYPE_STRING, - SC_TYPE_STRING, SC_TYPE_STRING)) { + SDB_TYPE_DATETIME, SDB_TYPE_STRING, + SDB_TYPE_STRING, SDB_TYPE_STRING)) { fprintf(stderr, "collectd backend: Failed to read response " - "from collectd @ %s.\n", sc_unixsock_client_path(client)); + "from collectd @ %s.\n", sdb_unixsock_client_path(client)); return -1; } if (state.current_host) { - sc_collectd_add_host(state.current_host, state.current_timestamp); + sdb_collectd_add_host(state.current_host, state.current_timestamp); fprintf(stderr, "collectd backend: Added/updated " "%i service%s (%i failed) for host '%s'.\n", state.svc_updated, state.svc_updated == 1 ? "" : "s", state.svc_failed, state.current_host); } return 0; -} /* sc_collectd_collect */ +} /* sdb_collectd_collect */ static int -sc_collectd_config_instance(oconfig_item_t *ci) +sdb_collectd_config_instance(oconfig_item_t *ci) { char *name = NULL; char *socket = NULL; char cb_name[1024]; - sc_object_t *user_data; - sc_unixsock_client_t *client; + sdb_object_t *user_data; + sdb_unixsock_client_t *client; int i; @@ -329,35 +329,35 @@ sc_collectd_config_instance(oconfig_item_t *ci) snprintf(cb_name, sizeof(cb_name), "collectd-%s", name); cb_name[sizeof(cb_name) - 1] = '\0'; - client = sc_unixsock_client_create(socket); + client = sdb_unixsock_client_create(socket); if (! client) { char errbuf[1024]; fprintf(stderr, "collectd backend: Failed to create unixsock client: " - "%s\n", sc_strerror(errno, errbuf, sizeof(errbuf))); + "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } - user_data = sc_object_create_wrapper(client, - (void (*)(void *))sc_unixsock_client_destroy); + user_data = sdb_object_create_wrapper(client, + (void (*)(void *))sdb_unixsock_client_destroy); if (! user_data) { - sc_unixsock_client_destroy(client); - fprintf(stderr, "collectd backend: Failed to allocate sc_object_t\n"); + sdb_unixsock_client_destroy(client); + fprintf(stderr, "collectd backend: Failed to allocate sdb_object_t\n"); return -1; } - sc_plugin_register_init(cb_name, sc_collectd_init, user_data); - sc_plugin_register_shutdown(cb_name, sc_collectd_shutdown, user_data); + sdb_plugin_register_init(cb_name, sdb_collectd_init, user_data); + sdb_plugin_register_shutdown(cb_name, sdb_collectd_shutdown, user_data); - sc_plugin_register_collector(cb_name, sc_collectd_collect, + sdb_plugin_register_collector(cb_name, sdb_collectd_collect, /* interval */ NULL, user_data); /* pass control to the list */ - sc_object_deref(user_data); + sdb_object_deref(user_data); return 0; -} /* sc_collectd_config_instance */ +} /* sdb_collectd_config_instance */ static int -sc_collectd_config(oconfig_item_t *ci) +sdb_collectd_config(oconfig_item_t *ci) { int i; @@ -365,29 +365,29 @@ sc_collectd_config(oconfig_item_t *ci) oconfig_item_t *child = ci->children + i; if (! strcasecmp(child->key, "Instance")) - sc_collectd_config_instance(child); + sdb_collectd_config_instance(child); else fprintf(stderr, "collectd backend: Ignoring unknown config " "option '%s'.\n", child->key); } return 0; -} /* sc_collectd_config */ +} /* sdb_collectd_config */ int -sc_module_init(sc_plugin_info_t *info) +sdb_module_init(sdb_plugin_info_t *info) { - sc_plugin_set_info(info, SC_PLUGIN_INFO_NAME, "collectd"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_DESC, + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "collectd"); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC, "backend accessing the system statistics collection daemon"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_COPYRIGHT, + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT, "Copyright (C) 2012 Sebastian 'tokkee' Harl "); - sc_plugin_set_info(info, SC_PLUGIN_INFO_LICENSE, "BSD"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_VERSION, SC_VERSION); - sc_plugin_set_info(info, SC_PLUGIN_INFO_PLUGIN_VERSION, SC_VERSION); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_LICENSE, "BSD"); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION); - sc_plugin_register_config("collectd", sc_collectd_config); + sdb_plugin_register_config("collectd", sdb_collectd_config); return 0; -} /* sc_version_extra */ +} /* sdb_version_extra */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/backend/mk-livestatus.c b/src/backend/mk-livestatus.c index 0edbc3d..57fda52 100644 --- a/src/backend/mk-livestatus.c +++ b/src/backend/mk-livestatus.c @@ -1,5 +1,5 @@ /* - * syscollector - src/backend/mk-livestatus.c + * SysDB - src/backend/mk-livestatus.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,7 +25,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "syscollector.h" +#include "sysdb.h" #include "core/plugin.h" #include "core/store.h" #include "utils/string.h" @@ -41,26 +41,27 @@ #include #include -SC_PLUGIN_MAGIC; +SDB_PLUGIN_MAGIC; /* * private helper functions */ static int -sc_livestatus_get_host(sc_unixsock_client_t __attribute__((unused)) *client, - size_t n, sc_data_t *data, sc_object_t __attribute__((unused)) *user_data) +sdb_livestatus_get_host(sdb_unixsock_client_t __attribute__((unused)) *client, + size_t n, sdb_data_t *data, + sdb_object_t __attribute__((unused)) *user_data) { char *hostname = NULL; - sc_time_t timestamp = 0; + sdb_time_t timestamp = 0; - sc_host_t host = SC_HOST_INIT; + sdb_host_t host = SDB_HOST_INIT; int status; assert(n == 2); - assert((data[0].type == SC_TYPE_STRING) - && (data[1].type == SC_TYPE_DATETIME)); + assert((data[0].type == SDB_TYPE_STRING) + && (data[1].type == SDB_TYPE_DATETIME)); hostname = strdup(data[0].data.string); timestamp = data[1].data.datetime; @@ -68,7 +69,7 @@ sc_livestatus_get_host(sc_unixsock_client_t __attribute__((unused)) *client, host.host_name = hostname; host.host_last_update = timestamp; - status = sc_store_host(&host); + status = sdb_store_host(&host); if (status < 0) { fprintf(stderr, "MK Livestatus backend: Failed to store/update " @@ -84,24 +85,25 @@ sc_livestatus_get_host(sc_unixsock_client_t __attribute__((unused)) *client, hostname, timestamp); free(hostname); return 0; -} /* sc_livestatus_get_host */ +} /* sdb_livestatus_get_host */ static int -sc_livestatus_get_svc(sc_unixsock_client_t __attribute__((unused)) *client, - size_t n, sc_data_t *data, sc_object_t __attribute__((unused)) *user_data) +sdb_livestatus_get_svc(sdb_unixsock_client_t __attribute__((unused)) *client, + size_t n, sdb_data_t *data, + sdb_object_t __attribute__((unused)) *user_data) { char *hostname = NULL; char *svcname = NULL; - sc_time_t timestamp = 0; + sdb_time_t timestamp = 0; - sc_service_t svc = SC_SVC_INIT; + sdb_service_t svc = SDB_SVC_INIT; int status; assert(n == 3); - assert((data[0].type == SC_TYPE_STRING) - && (data[1].type == SC_TYPE_STRING) - && (data[2].type == SC_TYPE_DATETIME)); + assert((data[0].type == SDB_TYPE_STRING) + && (data[1].type == SDB_TYPE_STRING) + && (data[2].type == SDB_TYPE_DATETIME)); hostname = strdup(data[0].data.string); svcname = strdup(data[1].data.string); @@ -111,7 +113,7 @@ sc_livestatus_get_svc(sc_unixsock_client_t __attribute__((unused)) *client, svc.svc_name = svcname; svc.svc_last_update = timestamp; - status = sc_store_service(&svc); + status = sdb_store_service(&svc); if (status < 0) { fprintf(stderr, "MK Livestatus backend: Failed to store/update " @@ -129,119 +131,119 @@ sc_livestatus_get_svc(sc_unixsock_client_t __attribute__((unused)) *client, free(hostname); free(svcname); return 0; -} /* sc_livestatus_get_svc */ +} /* sdb_livestatus_get_svc */ /* * plugin API */ static int -sc_livestatus_init(sc_object_t *user_data) +sdb_livestatus_init(sdb_object_t *user_data) { - sc_unixsock_client_t *client; + sdb_unixsock_client_t *client; if (! user_data) return -1; - client = SC_OBJ_WRAPPER(user_data)->data; - if (sc_unixsock_client_connect(client)) { + client = SDB_OBJ_WRAPPER(user_data)->data; + if (sdb_unixsock_client_connect(client)) { fprintf(stderr, "MK Livestatus backend: " "Failed to connect to livestatus @ %s.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return -1; } fprintf(stderr, "MK Livestatus backend: Successfully " "connected to livestatus @ %s.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return 0; -} /* sc_livestatus_init */ +} /* sdb_livestatus_init */ static int -sc_livestatus_collect(sc_object_t *user_data) +sdb_livestatus_collect(sdb_object_t *user_data) { - sc_unixsock_client_t *client; + sdb_unixsock_client_t *client; int status; if (! user_data) return -1; - client = SC_OBJ_WRAPPER(user_data)->data; + client = SDB_OBJ_WRAPPER(user_data)->data; - status = sc_unixsock_client_send(client, "GET hosts\r\n" + status = sdb_unixsock_client_send(client, "GET hosts\r\n" "Columns: name last_check"); if (status <= 0) { fprintf(stderr, "MK Livestatus backend: Failed to send " "'GET hosts' command to livestatus @ %s.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return -1; } - sc_unixsock_client_shutdown(client, SHUT_WR); + sdb_unixsock_client_shutdown(client, SHUT_WR); - if (sc_unixsock_client_process_lines(client, sc_livestatus_get_host, + if (sdb_unixsock_client_process_lines(client, sdb_livestatus_get_host, /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";", - /* column count */ 2, SC_TYPE_STRING, SC_TYPE_DATETIME)) { + /* column count */ 2, SDB_TYPE_STRING, SDB_TYPE_DATETIME)) { fprintf(stderr, "MK Livestatus backend: Failed to read response " "from livestatus @ %s while reading hosts.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return -1; } - if ((! sc_unixsock_client_eof(client)) - || sc_unixsock_client_error(client)) { + if ((! sdb_unixsock_client_eof(client)) + || sdb_unixsock_client_error(client)) { char errbuf[1024]; fprintf(stderr, "MK Livestatus backend: Failed to read host " "from livestatus @ %s: %s\n", - sc_unixsock_client_path(client), - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_unixsock_client_path(client), + sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } - status = sc_unixsock_client_send(client, "GET services\r\n" + status = sdb_unixsock_client_send(client, "GET services\r\n" "Columns: host_name description last_check"); if (status <= 0) { fprintf(stderr, "MK Livestatus backend: Failed to send " "'GET services' command to livestatus @ %s.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return -1; } - sc_unixsock_client_shutdown(client, SHUT_WR); + sdb_unixsock_client_shutdown(client, SHUT_WR); - if (sc_unixsock_client_process_lines(client, sc_livestatus_get_svc, + if (sdb_unixsock_client_process_lines(client, sdb_livestatus_get_svc, /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";", - /* column count */ 3, SC_TYPE_STRING, SC_TYPE_STRING, - SC_TYPE_DATETIME)) { + /* column count */ 3, SDB_TYPE_STRING, SDB_TYPE_STRING, + SDB_TYPE_DATETIME)) { fprintf(stderr, "MK Livestatus backend: Failed to read response " "from livestatus @ %s while reading services.\n", - sc_unixsock_client_path(client)); + sdb_unixsock_client_path(client)); return -1; } - if ((! sc_unixsock_client_eof(client)) - || sc_unixsock_client_error(client)) { + if ((! sdb_unixsock_client_eof(client)) + || sdb_unixsock_client_error(client)) { char errbuf[1024]; fprintf(stderr, "MK Livestatus backend: Failed to read services " "from livestatus @ %s: %s\n", - sc_unixsock_client_path(client), - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_unixsock_client_path(client), + sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } return 0; -} /* sc_livestatus_collect */ +} /* sdb_livestatus_collect */ static int -sc_livestatus_config_instance(oconfig_item_t *ci) +sdb_livestatus_config_instance(oconfig_item_t *ci) { char *name = NULL; char *socket = NULL; char cb_name[1024]; - sc_object_t *user_data; - sc_unixsock_client_t *client; + sdb_object_t *user_data; + sdb_unixsock_client_t *client; int i; @@ -271,34 +273,34 @@ sc_livestatus_config_instance(oconfig_item_t *ci) snprintf(cb_name, sizeof(cb_name), "mk-livestatus-%s", name); cb_name[sizeof(cb_name) - 1] = '\0'; - client = sc_unixsock_client_create(socket); + client = sdb_unixsock_client_create(socket); if (! client) { char errbuf[1024]; fprintf(stderr, "MK Livestatus backend: Failed to create unixsock " - "client: %s\n", sc_strerror(errno, errbuf, sizeof(errbuf))); + "client: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } - user_data = sc_object_create_wrapper(client, - (void (*)(void *))sc_unixsock_client_destroy); + user_data = sdb_object_create_wrapper(client, + (void (*)(void *))sdb_unixsock_client_destroy); if (! user_data) { - sc_unixsock_client_destroy(client); + sdb_unixsock_client_destroy(client); fprintf(stderr, "MK Livestatus backend: Failed to " - "allocate sc_object_t\n"); + "allocate sdb_object_t\n"); return -1; } - sc_plugin_register_init(cb_name, sc_livestatus_init, user_data); - sc_plugin_register_collector(cb_name, sc_livestatus_collect, + sdb_plugin_register_init(cb_name, sdb_livestatus_init, user_data); + sdb_plugin_register_collector(cb_name, sdb_livestatus_collect, /* interval */ NULL, user_data); /* pass control to the list */ - sc_object_deref(user_data); + sdb_object_deref(user_data); return 0; -} /* sc_livestatus_config_instance */ +} /* sdb_livestatus_config_instance */ static int -sc_livestatus_config(oconfig_item_t *ci) +sdb_livestatus_config(oconfig_item_t *ci) { int i; @@ -306,29 +308,29 @@ sc_livestatus_config(oconfig_item_t *ci) oconfig_item_t *child = ci->children + i; if (! strcasecmp(child->key, "Instance")) - sc_livestatus_config_instance(child); + sdb_livestatus_config_instance(child); else fprintf(stderr, "MK Livestatus backend: Ignoring unknown config " "option '%s'.\n", child->key); } return 0; -} /* sc_livestatus_config */ +} /* sdb_livestatus_config */ int -sc_module_init(sc_plugin_info_t *info) +sdb_module_init(sdb_plugin_info_t *info) { - sc_plugin_set_info(info, SC_PLUGIN_INFO_NAME, "MK-Livestatus"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_DESC, + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "MK-Livestatus"); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC, "backend accessing Nagios/Icinga/Shinken using MK Livestatus"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_COPYRIGHT, + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT, "Copyright (C) 2012 Sebastian 'tokkee' Harl "); - sc_plugin_set_info(info, SC_PLUGIN_INFO_LICENSE, "BSD"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_VERSION, SC_VERSION); - sc_plugin_set_info(info, SC_PLUGIN_INFO_PLUGIN_VERSION, SC_VERSION); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_LICENSE, "BSD"); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION); - sc_plugin_register_config("mk-livestatus", sc_livestatus_config); + sdb_plugin_register_config("mk-livestatus", sdb_livestatus_config); return 0; -} /* sc_version_extra */ +} /* sdb_version_extra */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/backend/puppet-storeconfigs.c b/src/backend/puppet-storeconfigs.c index f9aadb9..1129a5a 100644 --- a/src/backend/puppet-storeconfigs.c +++ b/src/backend/puppet-storeconfigs.c @@ -1,5 +1,5 @@ /* - * syscollector - src/backend/puppet-storeconfigs.c + * SysDB - src/backend/puppet-storeconfigs.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,7 +25,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "syscollector.h" +#include "sysdb.h" #include "core/plugin.h" #include "core/store.h" #include "utils/dbi.h" @@ -41,29 +41,29 @@ #include #include -SC_PLUGIN_MAGIC; +SDB_PLUGIN_MAGIC; /* * private helper functions */ static int -sc_puppet_stcfg_get_hosts(sc_dbi_client_t __attribute__((unused)) *client, - size_t n, sc_data_t *data, - sc_object_t __attribute__((unused)) *user_data) +sdb_puppet_stcfg_get_hosts(sdb_dbi_client_t __attribute__((unused)) *client, + size_t n, sdb_data_t *data, + sdb_object_t __attribute__((unused)) *user_data) { - sc_host_t host = SC_HOST_INIT; + sdb_host_t host = SDB_HOST_INIT; int status; assert(n == 2); - assert((data[0].type == SC_TYPE_STRING) - && (data[1].type == SC_TYPE_DATETIME)); + assert((data[0].type == SDB_TYPE_STRING) + && (data[1].type == SDB_TYPE_DATETIME)); host.host_name = strdup(data[0].data.string); host.host_last_update = data[1].data.datetime; - status = sc_store_host(&host); + status = sdb_store_host(&host); if (status < 0) { fprintf(stderr, "puppet storeconfigs backend: Failed to store/update " @@ -77,29 +77,29 @@ sc_puppet_stcfg_get_hosts(sc_dbi_client_t __attribute__((unused)) *client, host.host_name, host.host_last_update); free(host.host_name); return 0; -} /* sc_puppet_stcfg_get_hosts */ +} /* sdb_puppet_stcfg_get_hosts */ static int -sc_puppet_stcfg_get_attrs(sc_dbi_client_t __attribute__((unused)) *client, - size_t n, sc_data_t *data, - sc_object_t __attribute__((unused)) *user_data) +sdb_puppet_stcfg_get_attrs(sdb_dbi_client_t __attribute__((unused)) *client, + size_t n, sdb_data_t *data, + sdb_object_t __attribute__((unused)) *user_data) { - sc_attribute_t attr = SC_ATTR_INIT; + sdb_attribute_t attr = SDB_ATTR_INIT; int status; assert(n == 4); - assert((data[0].type == SC_TYPE_STRING) - && (data[1].type == SC_TYPE_STRING) - && (data[2].type == SC_TYPE_STRING) - && (data[3].type == SC_TYPE_DATETIME)); + assert((data[0].type == SDB_TYPE_STRING) + && (data[1].type == SDB_TYPE_STRING) + && (data[2].type == SDB_TYPE_STRING) + && (data[3].type == SDB_TYPE_DATETIME)); attr.hostname = strdup(data[0].data.string); attr.attr_name = strdup(data[1].data.string); attr.attr_value = strdup(data[2].data.string); attr.attr_last_update = data[3].data.datetime; - status = sc_store_attribute(&attr); + status = sdb_store_attribute(&attr); if (status < 0) { fprintf(stderr, "puppet storeconfigs backend: Failed to store/update " @@ -115,22 +115,22 @@ sc_puppet_stcfg_get_attrs(sc_dbi_client_t __attribute__((unused)) *client, free(attr.attr_name); free(attr.attr_value); return 0; -} /* sc_puppet_stcfg_get_attrs */ +} /* sdb_puppet_stcfg_get_attrs */ /* * plugin API */ static int -sc_puppet_stcfg_init(sc_object_t *user_data) +sdb_puppet_stcfg_init(sdb_object_t *user_data) { - sc_dbi_client_t *client; + sdb_dbi_client_t *client; if (! user_data) return -1; - client = SC_OBJ_WRAPPER(user_data)->data; - if (sc_dbi_client_connect(client)) { + client = SDB_OBJ_WRAPPER(user_data)->data; + if (sdb_dbi_client_connect(client)) { fprintf(stderr, "puppet storeconfigs backend: " "Failed to connect to the storeconfigs DB.\n"); return -1; @@ -139,26 +139,26 @@ sc_puppet_stcfg_init(sc_object_t *user_data) fprintf(stderr, "puppet storeconfigs backend: Successfully " "connected to the storeconfigs DB.\n"); return 0; -} /* sc_collectd_init */ +} /* sdb_puppet_stcfg_init */ static int -sc_puppet_stcfg_collect(sc_object_t *user_data) +sdb_puppet_stcfg_collect(sdb_object_t *user_data) { - sc_dbi_client_t *client; + sdb_dbi_client_t *client; if (! user_data) return -1; - client = SC_OBJ_WRAPPER(user_data)->data; - if (sc_dbi_exec_query(client, "SELECT name, updated_at FROM hosts;", - sc_puppet_stcfg_get_hosts, NULL, /* #columns = */ 2, - /* col types = */ SC_TYPE_STRING, SC_TYPE_DATETIME)) { + client = SDB_OBJ_WRAPPER(user_data)->data; + if (sdb_dbi_exec_query(client, "SELECT name, updated_at FROM hosts;", + sdb_puppet_stcfg_get_hosts, NULL, /* #columns = */ 2, + /* col types = */ SDB_TYPE_STRING, SDB_TYPE_DATETIME)) { fprintf(stderr, "puppet storeconfigs backend: Failed to retrieve " "hosts from the storeconfigs DB.\n"); return -1; } - if (sc_dbi_exec_query(client, "SELECT " + if (sdb_dbi_exec_query(client, "SELECT " "hosts.name AS hostname, " "fact_names.name AS name, " "fact_values.value AS value, " @@ -168,25 +168,25 @@ sc_puppet_stcfg_collect(sc_object_t *user_data) "ON fact_values.host_id = hosts.id " "INNER JOIN fact_names " "ON fact_values.fact_name_id = fact_names.id;", - sc_puppet_stcfg_get_attrs, NULL, /* #columns = */ 4, - /* col types = */ SC_TYPE_STRING, SC_TYPE_STRING, - SC_TYPE_STRING, SC_TYPE_DATETIME)) { + sdb_puppet_stcfg_get_attrs, NULL, /* #columns = */ 4, + /* col types = */ SDB_TYPE_STRING, SDB_TYPE_STRING, + SDB_TYPE_STRING, SDB_TYPE_DATETIME)) { fprintf(stderr, "puppet storeconfigs backend: Failed to retrieve " "host attributes from the storeconfigs DB.\n"); return -1; } return 0; -} /* sc_collectd_collect */ +} /* sdb_collectd_collect */ static int -sc_puppet_stcfg_config_conn(oconfig_item_t *ci) +sdb_puppet_stcfg_config_conn(oconfig_item_t *ci) { char *name = NULL; char cb_name[1024]; - sc_object_t *user_data; - sc_dbi_client_t *client; - sc_dbi_options_t *options = NULL; + sdb_object_t *user_data; + sdb_dbi_client_t *client; + sdb_dbi_options_t *options = NULL; char *driver = NULL; char *database = NULL; @@ -272,20 +272,20 @@ sc_puppet_stcfg_config_conn(oconfig_item_t *ci) assert(key && value); if (! options) { - if (! (options = sc_dbi_options_create())) { + if (! (options = sdb_dbi_options_create())) { char errmsg[1024]; fprintf(stderr, "puppet storeconfigs backend: Failed to " "create DBI options object: %s\n", - sc_strerror(errno, errmsg, sizeof(errmsg))); + sdb_strerror(errno, errmsg, sizeof(errmsg))); continue; } } - if (sc_dbi_options_add(options, key, value)) { + if (sdb_dbi_options_add(options, key, value)) { char errmsg[1024]; fprintf(stderr, "puppet storeconfigs backend: Failed to add " "option '%s': %s\n", key, - sc_strerror(errno, errmsg, sizeof(errmsg))); + sdb_strerror(errno, errmsg, sizeof(errmsg))); continue; } } @@ -304,37 +304,37 @@ sc_puppet_stcfg_config_conn(oconfig_item_t *ci) snprintf(cb_name, sizeof(cb_name), "puppet-storeconfigs-%s", name); cb_name[sizeof(cb_name) - 1] = '\0'; - client = sc_dbi_client_create(driver, database); + client = sdb_dbi_client_create(driver, database); if (! client) { char errbuf[1024]; fprintf(stderr, "puppet storeconfigs backend: " "Failed to create DBI client: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } - sc_dbi_client_set_options(client, options); + sdb_dbi_client_set_options(client, options); - user_data = sc_object_create_wrapper(client, - (void (*)(void *))sc_dbi_client_destroy); + user_data = sdb_object_create_wrapper(client, + (void (*)(void *))sdb_dbi_client_destroy); if (! user_data) { - sc_dbi_client_destroy(client); + sdb_dbi_client_destroy(client); fprintf(stderr, "puppet storeconfigs backend: " - "Failed to allocate sc_object_t\n"); + "Failed to allocate sdb_object_t\n"); return -1; } - sc_plugin_register_init(cb_name, sc_puppet_stcfg_init, user_data); - sc_plugin_register_collector(cb_name, sc_puppet_stcfg_collect, + sdb_plugin_register_init(cb_name, sdb_puppet_stcfg_init, user_data); + sdb_plugin_register_collector(cb_name, sdb_puppet_stcfg_collect, /* interval */ NULL, user_data); /* pass control to the list */ - sc_object_deref(user_data); + sdb_object_deref(user_data); return 0; -} /* sc_puppet_stcfg_config_conn */ +} /* sdb_puppet_stcfg_config_conn */ static int -sc_puppet_stcfg_config(oconfig_item_t *ci) +sdb_puppet_stcfg_config(oconfig_item_t *ci) { int i; @@ -342,25 +342,25 @@ sc_puppet_stcfg_config(oconfig_item_t *ci) oconfig_item_t *child = ci->children + i; if (! strcasecmp(child->key, "Connection")) - sc_puppet_stcfg_config_conn(child); + sdb_puppet_stcfg_config_conn(child); else fprintf(stderr, "puppet storeconfigs backend: Ignoring unknown " "config option '%s'.\n", child->key); } return 0; -} /* sc_puppet_stcfg_config */ +} /* sdb_puppet_stcfg_config */ int -sc_module_init(sc_plugin_info_t *info) +sdb_module_init(sdb_plugin_info_t *info) { - sc_plugin_set_info(info, SC_PLUGIN_INFO_NAME, "puppet-storeconfigs"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_DESC, + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "puppet-storeconfigs"); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC, "backend accessing the Puppet stored configuration database"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_COPYRIGHT, + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT, "Copyright (C) 2012 Sebastian 'tokkee' Harl "); - sc_plugin_set_info(info, SC_PLUGIN_INFO_LICENSE, "BSD"); - sc_plugin_set_info(info, SC_PLUGIN_INFO_VERSION, SC_VERSION); - sc_plugin_set_info(info, SC_PLUGIN_INFO_PLUGIN_VERSION, SC_VERSION); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_LICENSE, "BSD"); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION); if (dbi_initialize(/* driver dir = */ NULL) < 0) { fprintf(stderr, "puppet storeconfigs backend: failed to initialize " @@ -368,9 +368,10 @@ sc_module_init(sc_plugin_info_t *info) return -1; } - sc_plugin_register_config("puppet-storeconfigs", sc_puppet_stcfg_config); + sdb_plugin_register_config("puppet-storeconfigs", + sdb_puppet_stcfg_config); return 0; -} /* sc_version_extra */ +} /* sdb_version_extra */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/core/object.c b/src/core/object.c index 711607a..5ebcff2 100644 --- a/src/core/object.c +++ b/src/core/object.c @@ -1,5 +1,5 @@ /* - * syscollector - src/core/object.c + * SysDB - src/core/object.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -37,40 +37,40 @@ */ static int -sc_object_wrapper_init(sc_object_t *obj, va_list ap) +sdb_object_wrapper_init(sdb_object_t *obj, va_list ap) { void *data = va_arg(ap, void *); void (*destructor)(void *) = va_arg(ap, void (*)(void *)); assert(obj); - SC_OBJ_WRAPPER(obj)->data = data; - SC_OBJ_WRAPPER(obj)->destructor = destructor; + SDB_OBJ_WRAPPER(obj)->data = data; + SDB_OBJ_WRAPPER(obj)->destructor = destructor; return 0; -} /* sc_object_wrapper_init */ +} /* sdb_object_wrapper_init */ static void -sc_object_wrapper_destroy(sc_object_t *obj) +sdb_object_wrapper_destroy(sdb_object_t *obj) { if (! obj) return; assert(obj->ref_cnt <= 0); - if (SC_OBJ_WRAPPER(obj)->destructor && SC_OBJ_WRAPPER(obj)->data) - SC_OBJ_WRAPPER(obj)->destructor(SC_OBJ_WRAPPER(obj)->data); - SC_OBJ_WRAPPER(obj)->data = NULL; -} /* sc_object_wrapper_destroy */ + if (SDB_OBJ_WRAPPER(obj)->destructor && SDB_OBJ_WRAPPER(obj)->data) + SDB_OBJ_WRAPPER(obj)->destructor(SDB_OBJ_WRAPPER(obj)->data); + SDB_OBJ_WRAPPER(obj)->data = NULL; +} /* sdb_object_wrapper_destroy */ /* * public API */ -sc_object_t * -sc_object_create(size_t size, int (*init)(sc_object_t *, va_list), - void (*destructor)(sc_object_t *), ...) +sdb_object_t * +sdb_object_create(size_t size, int (*init)(sdb_object_t *, va_list), + void (*destructor)(sdb_object_t *), ...) { - sc_object_t *obj; + sdb_object_t *obj; obj = malloc(size); if (! obj) @@ -83,7 +83,7 @@ sc_object_create(size_t size, int (*init)(sc_object_t *, va_list), if (init(obj, ap)) { obj->ref_cnt = 1; - sc_object_deref(obj); + sdb_object_deref(obj); va_end(ap); return NULL; } @@ -95,18 +95,18 @@ sc_object_create(size_t size, int (*init)(sc_object_t *, va_list), obj->destructor = destructor; obj->size = size; return obj; -} /* sc_object_create */ +} /* sdb_object_create */ -sc_object_t * -sc_object_create_wrapper(void *data, void (*destructor)(void *)) +sdb_object_t * +sdb_object_create_wrapper(void *data, void (*destructor)(void *)) { - return sc_object_create(sizeof(sc_object_wrapper_t), - sc_object_wrapper_init, sc_object_wrapper_destroy, + return sdb_object_create(sizeof(sdb_object_wrapper_t), + sdb_object_wrapper_init, sdb_object_wrapper_destroy, data, destructor); -} /* sc_object_create_wrapper */ +} /* sdb_object_create_wrapper */ void -sc_object_deref(sc_object_t *obj) +sdb_object_deref(sdb_object_t *obj) { if (! obj) return; @@ -119,16 +119,16 @@ sc_object_deref(sc_object_t *obj) obj->destructor(obj); free(obj); -} /* sc_object_deref */ +} /* sdb_object_deref */ void -sc_object_ref(sc_object_t *obj) +sdb_object_ref(sdb_object_t *obj) { if (! obj) return; assert(obj->ref_cnt > 0); ++obj->ref_cnt; -} /* sc_object_ref */ +} /* sdb_object_ref */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/core/plugin.c b/src/core/plugin.c index a4c8c2d..5c9a233 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -1,5 +1,5 @@ /* - * syscollector - src/core/plugin.c + * SysDB - src/core/plugin.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,7 +25,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "syscollector.h" +#include "sysdb.h" #include "core/plugin.h" #include "utils/llist.h" #include "utils/string.h" @@ -49,7 +49,7 @@ * private data types */ -struct sc_plugin_info { +struct sdb_plugin_info { char *name; char *description; @@ -59,72 +59,74 @@ struct sc_plugin_info { int version; int plugin_version; }; -#define SC_PLUGIN_INFO_INIT { "no name set", "no description set", \ +#define SDB_PLUGIN_INFO_INIT { "no name set", "no description set", \ /* copyright */ "", /* license */ "", \ /* version */ -1, /* plugin_version */ -1 } typedef struct { - sc_object_t super; + sdb_object_t super; char cb_name[64]; void *cb_callback; - sc_object_t *cb_user_data; - sc_plugin_ctx_t cb_ctx; -} sc_plugin_cb_t; -#define SC_PLUGIN_CB_INIT { SC_OBJECT_INIT, "", NULL, NULL, SC_PLUGIN_CTX_INIT } + sdb_object_t *cb_user_data; + sdb_plugin_ctx_t cb_ctx; +} sdb_plugin_cb_t; +#define SDB_PLUGIN_CB_INIT { SDB_OBJECT_INIT, /* name = */ "", \ + /* callback = */ NULL, /* user_data = */ NULL, \ + SDB_PLUGIN_CTX_INIT } typedef struct { - sc_plugin_cb_t super; + sdb_plugin_cb_t super; #define ccb_name super.cb_name #define ccb_callback super.cb_callback #define ccb_user_data super.cb_user_data #define ccb_ctx super.cb_ctx - sc_time_t ccb_interval; - sc_time_t ccb_next_update; -} sc_plugin_collector_cb_t; + sdb_time_t ccb_interval; + sdb_time_t ccb_next_update; +} sdb_plugin_collector_cb_t; -#define SC_PLUGIN_CB(obj) ((sc_plugin_cb_t *)(obj)) -#define SC_PLUGIN_CCB(obj) ((sc_plugin_collector_cb_t *)(obj)) +#define SDB_PLUGIN_CB(obj) ((sdb_plugin_cb_t *)(obj)) +#define SDB_PLUGIN_CCB(obj) ((sdb_plugin_collector_cb_t *)(obj)) /* * private variables */ -static sc_plugin_ctx_t plugin_default_ctx = SC_PLUGIN_CTX_INIT; +static sdb_plugin_ctx_t plugin_default_ctx = SDB_PLUGIN_CTX_INIT; static pthread_key_t plugin_ctx_key; static _Bool plugin_ctx_key_initialized = 0; -static sc_llist_t *config_list = NULL; -static sc_llist_t *init_list = NULL; -static sc_llist_t *collector_list = NULL; -static sc_llist_t *shutdown_list = NULL; +static sdb_llist_t *config_list = NULL; +static sdb_llist_t *init_list = NULL; +static sdb_llist_t *collector_list = NULL; +static sdb_llist_t *shutdown_list = NULL; /* * private helper functions */ static void -sc_plugin_ctx_destructor(void *ctx) +sdb_plugin_ctx_destructor(void *ctx) { if (! ctx) return; free(ctx); -} /* sc_plugin_ctx_destructor */ +} /* sdb_plugin_ctx_destructor */ static void -sc_plugin_ctx_init(void) +sdb_plugin_ctx_init(void) { if (plugin_ctx_key_initialized) return; - pthread_key_create(&plugin_ctx_key, sc_plugin_ctx_destructor); + pthread_key_create(&plugin_ctx_key, sdb_plugin_ctx_destructor); plugin_ctx_key_initialized = 1; -} /* sc_plugin_ctx_init */ +} /* sdb_plugin_ctx_init */ -static sc_plugin_ctx_t * -sc_plugin_ctx_create(void) +static sdb_plugin_ctx_t * +sdb_plugin_ctx_create(void) { - sc_plugin_ctx_t *ctx; + sdb_plugin_ctx_t *ctx; ctx = malloc(sizeof(*ctx)); if (! ctx) @@ -133,42 +135,42 @@ sc_plugin_ctx_create(void) *ctx = plugin_default_ctx; if (! plugin_ctx_key_initialized) - sc_plugin_ctx_init(); + sdb_plugin_ctx_init(); pthread_setspecific(plugin_ctx_key, ctx); return ctx; -} /* sc_plugin_ctx_create */ +} /* sdb_plugin_ctx_create */ static int -sc_plugin_cmp_name(const sc_object_t *a, const sc_object_t *b) +sdb_plugin_cmp_name(const sdb_object_t *a, const sdb_object_t *b) { - const sc_plugin_cb_t *cb1 = (const sc_plugin_cb_t *)a; - const sc_plugin_cb_t *cb2 = (const sc_plugin_cb_t *)b; + const sdb_plugin_cb_t *cb1 = (const sdb_plugin_cb_t *)a; + const sdb_plugin_cb_t *cb2 = (const sdb_plugin_cb_t *)b; assert(cb1 && cb2); return strcasecmp(cb1->cb_name, cb2->cb_name); -} /* sc_plugin_cmp_name */ +} /* sdb_plugin_cmp_name */ static int -sc_plugin_cmp_next_update(const sc_object_t *a, const sc_object_t *b) +sdb_plugin_cmp_next_update(const sdb_object_t *a, const sdb_object_t *b) { - const sc_plugin_collector_cb_t *ccb1 - = (const sc_plugin_collector_cb_t *)a; - const sc_plugin_collector_cb_t *ccb2 - = (const sc_plugin_collector_cb_t *)b; + const sdb_plugin_collector_cb_t *ccb1 + = (const sdb_plugin_collector_cb_t *)a; + const sdb_plugin_collector_cb_t *ccb2 + = (const sdb_plugin_collector_cb_t *)b; assert(ccb1 && ccb2); return (ccb1->ccb_next_update > ccb2->ccb_next_update) ? 1 : (ccb1->ccb_next_update < ccb2->ccb_next_update) ? -1 : 0; -} /* sc_plugin_cmp_next_update */ +} /* sdb_plugin_cmp_next_update */ -static sc_plugin_cb_t * -sc_plugin_find_by_name(sc_llist_t *list, const char *name) +static sdb_plugin_cb_t * +sdb_plugin_find_by_name(sdb_llist_t *list, const char *name) { - sc_plugin_cb_t tmp = SC_PLUGIN_CB_INIT; + sdb_plugin_cb_t tmp = SDB_PLUGIN_CB_INIT; - sc_object_t *obj; + sdb_object_t *obj; assert(name); if (! list) @@ -176,56 +178,56 @@ sc_plugin_find_by_name(sc_llist_t *list, const char *name) snprintf(tmp.cb_name, sizeof(tmp.cb_name), "%s", name); tmp.cb_name[sizeof(tmp.cb_name) - 1] = '\0'; - obj = sc_llist_search(list, SC_OBJ(&tmp), sc_plugin_cmp_name); + obj = sdb_llist_search(list, SDB_OBJ(&tmp), sdb_plugin_cmp_name); if (! obj) return NULL; - return SC_PLUGIN_CB(obj); -} /* sc_plugin_find_by_name */ + return SDB_PLUGIN_CB(obj); +} /* sdb_plugin_find_by_name */ static int -sc_plugin_cb_init(sc_object_t *obj, va_list ap) +sdb_plugin_cb_init(sdb_object_t *obj, va_list ap) { - sc_llist_t **list = va_arg(ap, sc_llist_t **); + sdb_llist_t **list = va_arg(ap, sdb_llist_t **); const char *type = va_arg(ap, const char *); const char *name = va_arg(ap, const char *); void *callback = va_arg(ap, void *); - sc_object_t *ud = va_arg(ap, sc_object_t *); + sdb_object_t *ud = va_arg(ap, sdb_object_t *); assert(list); assert(type); assert(obj); - if (sc_plugin_find_by_name(*list, name)) { + if (sdb_plugin_find_by_name(*list, name)) { fprintf(stderr, "plugin: %s callback '%s' has already been " "registered. Ignoring newly registered version.\n", type, name); return -1; } - snprintf(SC_PLUGIN_CB(obj)->cb_name, - sizeof(SC_PLUGIN_CB(obj)->cb_name), + snprintf(SDB_PLUGIN_CB(obj)->cb_name, + sizeof(SDB_PLUGIN_CB(obj)->cb_name), "%s", name); - SC_PLUGIN_CB(obj)->cb_name[sizeof(SC_PLUGIN_CB(obj)->cb_name) - 1] = '\0'; - SC_PLUGIN_CB(obj)->cb_callback = callback; - SC_PLUGIN_CB(obj)->cb_ctx = sc_plugin_get_ctx(); + SDB_PLUGIN_CB(obj)->cb_name[sizeof(SDB_PLUGIN_CB(obj)->cb_name) - 1] = '\0'; + SDB_PLUGIN_CB(obj)->cb_callback = callback; + SDB_PLUGIN_CB(obj)->cb_ctx = sdb_plugin_get_ctx(); - sc_object_ref(ud); - SC_PLUGIN_CB(obj)->cb_user_data = ud; + sdb_object_ref(ud); + SDB_PLUGIN_CB(obj)->cb_user_data = ud; return 0; -} /* sc_plugin_cb_init */ +} /* sdb_plugin_cb_init */ static void -sc_plugin_cb_destroy(sc_object_t *obj) +sdb_plugin_cb_destroy(sdb_object_t *obj) { assert(obj); - sc_object_deref(SC_PLUGIN_CB(obj)->cb_user_data); -} /* sc_plugin_cb_destroy */ + sdb_object_deref(SDB_PLUGIN_CB(obj)->cb_user_data); +} /* sdb_plugin_cb_destroy */ static int -sc_plugin_add_callback(sc_llist_t **list, const char *type, - const char *name, void *callback, sc_object_t *user_data) +sdb_plugin_add_callback(sdb_llist_t **list, const char *type, + const char *name, void *callback, sdb_object_t *user_data) { - sc_object_t *obj; + sdb_object_t *obj; if ((! name) || (! callback)) return -1; @@ -233,40 +235,40 @@ sc_plugin_add_callback(sc_llist_t **list, const char *type, assert(list); if (! *list) - *list = sc_llist_create(); + *list = sdb_llist_create(); if (! *list) return -1; - obj = sc_object_create(sizeof(sc_plugin_cb_t), sc_plugin_cb_init, - sc_plugin_cb_destroy, list, type, name, callback, user_data); + obj = sdb_object_create(sizeof(sdb_plugin_cb_t), sdb_plugin_cb_init, + sdb_plugin_cb_destroy, list, type, name, callback, user_data); if (! obj) return -1; - if (sc_llist_append(*list, obj)) { - sc_object_deref(obj); + if (sdb_llist_append(*list, obj)) { + sdb_object_deref(obj); return -1; } /* pass control to the list */ - sc_object_deref(obj); + sdb_object_deref(obj); fprintf(stderr, "plugin: Registered %s callback '%s'.\n", type, name); return 0; -} /* sc_plugin_add_callback */ +} /* sdb_plugin_add_callback */ /* * public API */ int -sc_plugin_load(const char *name) +sdb_plugin_load(const char *name) { char filename[1024]; lt_dlhandle lh; - int (*mod_init)(sc_plugin_info_t *); - sc_plugin_info_t plugin_info = SC_PLUGIN_INFO_INIT; + int (*mod_init)(sdb_plugin_info_t *); + sdb_plugin_info_t plugin_info = SDB_PLUGIN_INFO_INIT; int status; @@ -277,7 +279,7 @@ sc_plugin_load(const char *name) if (access(filename, R_OK)) { char errbuf[1024]; fprintf(stderr, "plugin: Failed to load plugin '%s': %s\n", - name, sc_strerror(errno, errbuf, sizeof(errbuf))); + name, sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } @@ -292,10 +294,10 @@ sc_plugin_load(const char *name) return -1; } - mod_init = (int (*)(sc_plugin_info_t *))lt_dlsym(lh, "sc_module_init"); + mod_init = (int (*)(sdb_plugin_info_t *))lt_dlsym(lh, "sdb_module_init"); if (! mod_init) { fprintf(stderr, "plugin: Failed to load plugin '%s': " - "could not find symbol 'sc_module_init'\n", name); + "could not find symbol 'sdb_module_init'\n", name); return -1; } @@ -307,22 +309,22 @@ sc_plugin_load(const char *name) /* compare minor version */ if ((plugin_info.version < 0) - || ((int)(plugin_info.version / 100) != (int)(SC_VERSION / 100))) + || ((int)(plugin_info.version / 100) != (int)(SDB_VERSION / 100))) fprintf(stderr, "plugin: WARNING: version of plugin '%s' (%i.%i.%i) " "does not match our version (%i.%i.%i); " "this might cause problems\n", - name, SC_VERSION_DECODE(plugin_info.version), - SC_VERSION_DECODE(SC_VERSION)); + name, SDB_VERSION_DECODE(plugin_info.version), + SDB_VERSION_DECODE(SDB_VERSION)); fprintf(stderr, "plugin: Successfully loaded " "plugin '%s' v%i (%s)\n\t%s\n", plugin_info.name, plugin_info.plugin_version, plugin_info.description, plugin_info.copyright); return 0; -} /* sc_plugin_load */ +} /* sdb_plugin_load */ int -sc_plugin_set_info(sc_plugin_info_t *info, int type, ...) +sdb_plugin_set_info(sdb_plugin_info_t *info, int type, ...) { va_list ap; @@ -332,37 +334,37 @@ sc_plugin_set_info(sc_plugin_info_t *info, int type, ...) va_start(ap, type); switch (type) { - case SC_PLUGIN_INFO_NAME: + case SDB_PLUGIN_INFO_NAME: { char *name = va_arg(ap, char *); info->name = name; } break; - case SC_PLUGIN_INFO_DESC: + case SDB_PLUGIN_INFO_DESC: { char *desc = va_arg(ap, char *); info->description = desc; } break; - case SC_PLUGIN_INFO_COPYRIGHT: + case SDB_PLUGIN_INFO_COPYRIGHT: { char *copyright = va_arg(ap, char *); info->copyright = copyright; } break; - case SC_PLUGIN_INFO_LICENSE: + case SDB_PLUGIN_INFO_LICENSE: { char *license = va_arg(ap, char *); info->license = license; } break; - case SC_PLUGIN_INFO_VERSION: + case SDB_PLUGIN_INFO_VERSION: { int version = va_arg(ap, int); info->version = version; } break; - case SC_PLUGIN_INFO_PLUGIN_VERSION: + case SDB_PLUGIN_INFO_PLUGIN_VERSION: { int version = va_arg(ap, int); info->plugin_version = version; @@ -375,135 +377,135 @@ sc_plugin_set_info(sc_plugin_info_t *info, int type, ...) va_end(ap); return 0; -} /* sc_plugin_set_info */ +} /* sdb_plugin_set_info */ int -sc_plugin_register_config(const char *name, sc_plugin_config_cb callback) +sdb_plugin_register_config(const char *name, sdb_plugin_config_cb callback) { - return sc_plugin_add_callback(&config_list, "init", name, + return sdb_plugin_add_callback(&config_list, "init", name, callback, NULL); -} /* sc_plugin_register_config */ +} /* sdb_plugin_register_config */ int -sc_plugin_register_init(const char *name, sc_plugin_init_cb callback, - sc_object_t *user_data) +sdb_plugin_register_init(const char *name, sdb_plugin_init_cb callback, + sdb_object_t *user_data) { - return sc_plugin_add_callback(&init_list, "init", name, + return sdb_plugin_add_callback(&init_list, "init", name, callback, user_data); -} /* sc_plugin_register_init */ +} /* sdb_plugin_register_init */ int -sc_plugin_register_shutdown(const char *name, sc_plugin_shutdown_cb callback, - sc_object_t *user_data) +sdb_plugin_register_shutdown(const char *name, sdb_plugin_shutdown_cb callback, + sdb_object_t *user_data) { - return sc_plugin_add_callback(&shutdown_list, "shutdown", name, + return sdb_plugin_add_callback(&shutdown_list, "shutdown", name, callback, user_data); -} /* sc_plugin_register_shutdown */ +} /* sdb_plugin_register_shutdown */ int -sc_plugin_register_collector(const char *name, sc_plugin_collector_cb callback, - const sc_time_t *interval, sc_object_t *user_data) +sdb_plugin_register_collector(const char *name, sdb_plugin_collector_cb callback, + const sdb_time_t *interval, sdb_object_t *user_data) { - sc_object_t *obj; + sdb_object_t *obj; if ((! name) || (! callback)) return -1; if (! collector_list) - collector_list = sc_llist_create(); + collector_list = sdb_llist_create(); if (! collector_list) return -1; - obj = sc_object_create(sizeof(sc_plugin_collector_cb_t), - sc_plugin_cb_init, sc_plugin_cb_destroy, + obj = sdb_object_create(sizeof(sdb_plugin_collector_cb_t), + sdb_plugin_cb_init, sdb_plugin_cb_destroy, &collector_list, "collector", name, callback, user_data); if (! obj) return -1; if (interval) - SC_PLUGIN_CCB(obj)->ccb_interval = *interval; + SDB_PLUGIN_CCB(obj)->ccb_interval = *interval; else { - sc_time_t tmp = sc_plugin_get_ctx().interval; + sdb_time_t tmp = sdb_plugin_get_ctx().interval; if (tmp > 0) - SC_PLUGIN_CCB(obj)->ccb_interval = tmp; + SDB_PLUGIN_CCB(obj)->ccb_interval = tmp; else - SC_PLUGIN_CCB(obj)->ccb_interval = 0; + SDB_PLUGIN_CCB(obj)->ccb_interval = 0; } - if (! (SC_PLUGIN_CCB(obj)->ccb_next_update = sc_gettime())) { + if (! (SDB_PLUGIN_CCB(obj)->ccb_next_update = sdb_gettime())) { char errbuf[1024]; fprintf(stderr, "plugin: Failed to determine current time: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - sc_object_deref(obj); + sdb_strerror(errno, errbuf, sizeof(errbuf))); + sdb_object_deref(obj); return -1; } - if (sc_llist_insert_sorted(collector_list, obj, - sc_plugin_cmp_next_update)) { - sc_object_deref(obj); + if (sdb_llist_insert_sorted(collector_list, obj, + sdb_plugin_cmp_next_update)) { + sdb_object_deref(obj); return -1; } /* pass control to the list */ - sc_object_deref(obj); + sdb_object_deref(obj); fprintf(stderr, "plugin: Registered collector callback '%s' " "(interval = %.3fs).\n", name, - SC_TIME_TO_DOUBLE(SC_PLUGIN_CCB(obj)->ccb_interval)); + SDB_TIME_TO_DOUBLE(SDB_PLUGIN_CCB(obj)->ccb_interval)); return 0; -} /* sc_plugin_register_collector */ +} /* sdb_plugin_register_collector */ -sc_plugin_ctx_t -sc_plugin_get_ctx(void) +sdb_plugin_ctx_t +sdb_plugin_get_ctx(void) { - sc_plugin_ctx_t *ctx; + sdb_plugin_ctx_t *ctx; if (! plugin_ctx_key_initialized) - sc_plugin_ctx_init(); + sdb_plugin_ctx_init(); ctx = pthread_getspecific(plugin_ctx_key); if (! ctx) - ctx = sc_plugin_ctx_create(); + ctx = sdb_plugin_ctx_create(); if (! ctx) return plugin_default_ctx; return *ctx; -} /* sc_plugin_get_ctx */ +} /* sdb_plugin_get_ctx */ -sc_plugin_ctx_t -sc_plugin_set_ctx(sc_plugin_ctx_t ctx) +sdb_plugin_ctx_t +sdb_plugin_set_ctx(sdb_plugin_ctx_t ctx) { - sc_plugin_ctx_t *tmp; - sc_plugin_ctx_t old; + sdb_plugin_ctx_t *tmp; + sdb_plugin_ctx_t old; if (! plugin_ctx_key_initialized) - sc_plugin_ctx_init(); + sdb_plugin_ctx_init(); tmp = pthread_getspecific(plugin_ctx_key); if (! tmp) - tmp = sc_plugin_ctx_create(); + tmp = sdb_plugin_ctx_create(); if (! tmp) return plugin_default_ctx; old = *tmp; *tmp = ctx; return old; -} /* sc_plugin_set_ctx */ +} /* sdb_plugin_set_ctx */ int -sc_plugin_configure(const char *name, oconfig_item_t *ci) +sdb_plugin_configure(const char *name, oconfig_item_t *ci) { - sc_plugin_cb_t *plugin; - sc_plugin_config_cb callback; + sdb_plugin_cb_t *plugin; + sdb_plugin_config_cb callback; - sc_plugin_ctx_t old_ctx; + sdb_plugin_ctx_t old_ctx; int status; if ((! name) || (! ci)) return -1; - plugin = sc_plugin_find_by_name(config_list, name); + plugin = sdb_plugin_find_by_name(config_list, name); if (! plugin) { fprintf(stderr, "plugin: Plugin '%s' did not register " "a config callback.\n", name); @@ -511,71 +513,71 @@ sc_plugin_configure(const char *name, oconfig_item_t *ci) return -1; } - old_ctx = sc_plugin_set_ctx(plugin->cb_ctx); + old_ctx = sdb_plugin_set_ctx(plugin->cb_ctx); callback = plugin->cb_callback; status = callback(ci); - sc_plugin_set_ctx(old_ctx); + sdb_plugin_set_ctx(old_ctx); return status; -} /* sc_plugin_configure */ +} /* sdb_plugin_configure */ int -sc_plugin_init_all(void) +sdb_plugin_init_all(void) { - sc_llist_iter_t *iter; + sdb_llist_iter_t *iter; - iter = sc_llist_get_iter(init_list); - while (sc_llist_iter_has_next(iter)) { - sc_plugin_init_cb callback; - sc_plugin_ctx_t old_ctx; + iter = sdb_llist_get_iter(init_list); + while (sdb_llist_iter_has_next(iter)) { + sdb_plugin_init_cb callback; + sdb_plugin_ctx_t old_ctx; - sc_object_t *obj = sc_llist_iter_get_next(iter); + sdb_object_t *obj = sdb_llist_iter_get_next(iter); assert(obj); - callback = SC_PLUGIN_CB(obj)->cb_callback; + callback = SDB_PLUGIN_CB(obj)->cb_callback; - old_ctx = sc_plugin_set_ctx(SC_PLUGIN_CB(obj)->cb_ctx); - if (callback(SC_PLUGIN_CB(obj)->cb_user_data)) { + old_ctx = sdb_plugin_set_ctx(SDB_PLUGIN_CB(obj)->cb_ctx); + if (callback(SDB_PLUGIN_CB(obj)->cb_user_data)) { /* XXX: unload plugin */ } - sc_plugin_set_ctx(old_ctx); + sdb_plugin_set_ctx(old_ctx); } return 0; -} /* sc_plugin_init_all */ +} /* sdb_plugin_init_all */ int -sc_plugin_collector_loop(sc_plugin_loop_t *loop) +sdb_plugin_collector_loop(sdb_plugin_loop_t *loop) { if ((! collector_list) || (! loop)) return -1; while (loop->do_loop) { - sc_plugin_collector_cb callback; - sc_plugin_ctx_t old_ctx; + sdb_plugin_collector_cb callback; + sdb_plugin_ctx_t old_ctx; - sc_time_t interval, now; + sdb_time_t interval, now; - sc_object_t *obj = sc_llist_shift(collector_list); + sdb_object_t *obj = sdb_llist_shift(collector_list); if (! obj) return -1; - callback = SC_PLUGIN_CCB(obj)->ccb_callback; + callback = SDB_PLUGIN_CCB(obj)->ccb_callback; - if (! (now = sc_gettime())) { + if (! (now = sdb_gettime())) { char errbuf[1024]; fprintf(stderr, "plugin: Failed to determine current time: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - now = SC_PLUGIN_CCB(obj)->ccb_next_update; + sdb_strerror(errno, errbuf, sizeof(errbuf))); + now = SDB_PLUGIN_CCB(obj)->ccb_next_update; } - if (now < SC_PLUGIN_CCB(obj)->ccb_next_update) { - interval = SC_PLUGIN_CCB(obj)->ccb_next_update - now; + if (now < SDB_PLUGIN_CCB(obj)->ccb_next_update) { + interval = SDB_PLUGIN_CCB(obj)->ccb_next_update - now; errno = 0; - while (loop->do_loop && sc_sleep(interval, &interval)) { + while (loop->do_loop && sdb_sleep(interval, &interval)) { if (errno != EINTR) { char errbuf[1024]; fprintf(stderr, "plugin: Failed to sleep: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } errno = 0; @@ -585,53 +587,53 @@ sc_plugin_collector_loop(sc_plugin_loop_t *loop) return 0; } - old_ctx = sc_plugin_set_ctx(SC_PLUGIN_CCB(obj)->ccb_ctx); - if (callback(SC_PLUGIN_CCB(obj)->ccb_user_data)) { + old_ctx = sdb_plugin_set_ctx(SDB_PLUGIN_CCB(obj)->ccb_ctx); + if (callback(SDB_PLUGIN_CCB(obj)->ccb_user_data)) { /* XXX */ } - sc_plugin_set_ctx(old_ctx); + sdb_plugin_set_ctx(old_ctx); - interval = SC_PLUGIN_CCB(obj)->ccb_interval; + interval = SDB_PLUGIN_CCB(obj)->ccb_interval; if (! interval) interval = loop->default_interval; if (! interval) { fprintf(stderr, "plugin: No interval configured " "for plugin '%s'; skipping any further " - "iterations.\n", SC_PLUGIN_CCB(obj)->ccb_name); - sc_object_deref(obj); + "iterations.\n", SDB_PLUGIN_CCB(obj)->ccb_name); + sdb_object_deref(obj); continue; } - SC_PLUGIN_CCB(obj)->ccb_next_update += interval; + SDB_PLUGIN_CCB(obj)->ccb_next_update += interval; - if (! (now = sc_gettime())) { + if (! (now = sdb_gettime())) { char errbuf[1024]; fprintf(stderr, "plugin: Failed to determine current time: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - now = SC_PLUGIN_CCB(obj)->ccb_next_update; + sdb_strerror(errno, errbuf, sizeof(errbuf))); + now = SDB_PLUGIN_CCB(obj)->ccb_next_update; } - if (now > SC_PLUGIN_CCB(obj)->ccb_next_update) { + if (now > SDB_PLUGIN_CCB(obj)->ccb_next_update) { fprintf(stderr, "plugin: Plugin '%s' took too long; " "skipping iterations to keep up.\n", - SC_PLUGIN_CCB(obj)->ccb_name); - SC_PLUGIN_CCB(obj)->ccb_next_update = now; + SDB_PLUGIN_CCB(obj)->ccb_name); + SDB_PLUGIN_CCB(obj)->ccb_next_update = now; } - if (sc_llist_insert_sorted(collector_list, obj, - sc_plugin_cmp_next_update)) { + if (sdb_llist_insert_sorted(collector_list, obj, + sdb_plugin_cmp_next_update)) { fprintf(stderr, "plugin: Failed to re-insert " "plugin '%s' into collector list.\n", - SC_PLUGIN_CCB(obj)->ccb_name); - sc_object_deref(obj); + SDB_PLUGIN_CCB(obj)->ccb_name); + sdb_object_deref(obj); return -1; } /* pass control back to the list */ - sc_object_deref(obj); + sdb_object_deref(obj); } return 0; -} /* sc_plugin_read_loop */ +} /* sdb_plugin_read_loop */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/core/store.c b/src/core/store.c index 8dc256e..e5cd886 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -1,5 +1,5 @@ /* - * syscollector - src/core/store.c + * SysDB - src/core/store.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,7 +25,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "syscollector.h" +#include "sysdb.h" #include "core/store.h" #include "utils/llist.h" #include "utils/string.h" @@ -46,16 +46,16 @@ /* type used for looking up named objects */ typedef struct { - sc_object_t parent; + sdb_object_t parent; const char *obj_name; -} sc_store_lookup_obj_t; -#define SC_STORE_LOOKUP_OBJ_INIT { SC_OBJECT_INIT, NULL } +} sdb_store_lookup_obj_t; +#define SDB_STORE_LOOKUP_OBJ_INIT { SDB_OBJECT_INIT, NULL } /* * private variables */ -static sc_llist_t *host_list = NULL; +static sdb_llist_t *host_list = NULL; static pthread_rwlock_t host_lock = PTHREAD_RWLOCK_INITIALIZER; /* @@ -63,176 +63,176 @@ static pthread_rwlock_t host_lock = PTHREAD_RWLOCK_INITIALIZER; */ static int -sc_store_obj_cmp_by_name(const sc_object_t *a, const sc_object_t *b) +sdb_store_obj_cmp_by_name(const sdb_object_t *a, const sdb_object_t *b) { - const sc_store_obj_t *h1 = (const sc_store_obj_t *)a; - const sc_store_obj_t *h2 = (const sc_store_obj_t *)b; + const sdb_store_obj_t *h1 = (const sdb_store_obj_t *)a; + const sdb_store_obj_t *h2 = (const sdb_store_obj_t *)b; assert(h1 && h2); return strcasecmp(h1->name, h2->name); -} /* sc_store_obj_cmp_by_name */ +} /* sdb_store_obj_cmp_by_name */ static int -sc_cmp_store_obj_with_name(const sc_object_t *a, const sc_object_t *b) +sdb_cmp_store_obj_with_name(const sdb_object_t *a, const sdb_object_t *b) { - const sc_store_obj_t *obj = (const sc_store_obj_t *)a; - const sc_store_lookup_obj_t *lookup = (const sc_store_lookup_obj_t *)b; + const sdb_store_obj_t *obj = (const sdb_store_obj_t *)a; + const sdb_store_lookup_obj_t *lookup = (const sdb_store_lookup_obj_t *)b; assert(obj && lookup); return strcasecmp(obj->name, lookup->obj_name); -} /* sc_cmp_store_obj_with_name */ +} /* sdb_cmp_store_obj_with_name */ static int -sc_host_init(sc_object_t *obj, va_list ap) +sdb_host_init(sdb_object_t *obj, va_list ap) { const char *name = va_arg(ap, const char *); - SC_HOST(obj)->host_name = strdup(name); - if (! SC_HOST(obj)->host_name) + SDB_HOST(obj)->host_name = strdup(name); + if (! SDB_HOST(obj)->host_name) return -1; - SC_HOST(obj)->host_last_update = sc_gettime(); + SDB_HOST(obj)->host_last_update = sdb_gettime(); /* ignore errors -> last_update will be updated later */ - SC_HOST(obj)->attributes = sc_llist_create(); - if (! SC_HOST(obj)->attributes) + SDB_HOST(obj)->attributes = sdb_llist_create(); + if (! SDB_HOST(obj)->attributes) return -1; - SC_HOST(obj)->services = sc_llist_create(); - if (! SC_HOST(obj)->services) + SDB_HOST(obj)->services = sdb_llist_create(); + if (! SDB_HOST(obj)->services) return -1; return 0; -} /* sc_host_init */ +} /* sdb_host_init */ static void -sc_host_destroy(sc_object_t *obj) +sdb_host_destroy(sdb_object_t *obj) { assert(obj); - if (SC_HOST(obj)->host_name) - free(SC_HOST(obj)->host_name); + if (SDB_HOST(obj)->host_name) + free(SDB_HOST(obj)->host_name); - if (SC_HOST(obj)->attributes) - sc_llist_destroy(SC_HOST(obj)->attributes); - if (SC_HOST(obj)->services) - sc_llist_destroy(SC_HOST(obj)->services); -} /* sc_host_destroy */ + if (SDB_HOST(obj)->attributes) + sdb_llist_destroy(SDB_HOST(obj)->attributes); + if (SDB_HOST(obj)->services) + sdb_llist_destroy(SDB_HOST(obj)->services); +} /* sdb_host_destroy */ static int -sc_attr_init(sc_object_t *obj, va_list ap) +sdb_attr_init(sdb_object_t *obj, va_list ap) { const char *hostname = va_arg(ap, const char *); const char *name = va_arg(ap, const char *); const char *value = va_arg(ap, const char *); - SC_ATTR(obj)->hostname = strdup(hostname); - SC_ATTR(obj)->attr_name = strdup(name); - SC_ATTR(obj)->attr_value = strdup(value); - if ((! SC_ATTR(obj)->hostname) - || (! SC_ATTR(obj)->attr_name) || (! SC_ATTR(obj)->attr_value)) + SDB_ATTR(obj)->hostname = strdup(hostname); + SDB_ATTR(obj)->attr_name = strdup(name); + SDB_ATTR(obj)->attr_value = strdup(value); + if ((! SDB_ATTR(obj)->hostname) + || (! SDB_ATTR(obj)->attr_name) || (! SDB_ATTR(obj)->attr_value)) return -1; - SC_ATTR(obj)->attr_last_update = sc_gettime(); + SDB_ATTR(obj)->attr_last_update = sdb_gettime(); return 0; -} /* sc_attr_init */ +} /* sdb_attr_init */ static void -sc_attr_destroy(sc_object_t *obj) +sdb_attr_destroy(sdb_object_t *obj) { assert(obj); - if (SC_ATTR(obj)->hostname) - free(SC_ATTR(obj)->hostname); - if (SC_ATTR(obj)->attr_name) - free(SC_ATTR(obj)->attr_name); - if (SC_ATTR(obj)->attr_value) - free(SC_ATTR(obj)->attr_value); -} /* sc_attr_destroy */ + if (SDB_ATTR(obj)->hostname) + free(SDB_ATTR(obj)->hostname); + if (SDB_ATTR(obj)->attr_name) + free(SDB_ATTR(obj)->attr_name); + if (SDB_ATTR(obj)->attr_value) + free(SDB_ATTR(obj)->attr_value); +} /* sdb_attr_destroy */ static int -sc_svc_init(sc_object_t *obj, va_list ap) +sdb_svc_init(sdb_object_t *obj, va_list ap) { const char *hostname = va_arg(ap, const char *); const char *name = va_arg(ap, const char *); - SC_SVC(obj)->hostname = strdup(hostname); - SC_SVC(obj)->svc_name = strdup(name); - if ((! SC_SVC(obj)->hostname) || (! SC_SVC(obj)->svc_name)) + SDB_SVC(obj)->hostname = strdup(hostname); + SDB_SVC(obj)->svc_name = strdup(name); + if ((! SDB_SVC(obj)->hostname) || (! SDB_SVC(obj)->svc_name)) return -1; - SC_SVC(obj)->svc_last_update = sc_gettime(); + SDB_SVC(obj)->svc_last_update = sdb_gettime(); /* ignore errors -> last_update will be updated later */ return 0; -} /* sc_svc_init */ +} /* sdb_svc_init */ static void -sc_svc_destroy(sc_object_t *obj) +sdb_svc_destroy(sdb_object_t *obj) { assert(obj); - if (SC_SVC(obj)->hostname) - free(SC_SVC(obj)->hostname); - if (SC_SVC(obj)->svc_name) - free(SC_SVC(obj)->svc_name); -} /* sc_svc_destroy */ + if (SDB_SVC(obj)->hostname) + free(SDB_SVC(obj)->hostname); + if (SDB_SVC(obj)->svc_name) + free(SDB_SVC(obj)->svc_name); +} /* sdb_svc_destroy */ /* * public API */ -sc_host_t * -sc_host_create(const char *name) +sdb_host_t * +sdb_host_create(const char *name) { - sc_object_t *obj; + sdb_object_t *obj; if (! name) return NULL; - obj = sc_object_create(sizeof(sc_host_t), sc_host_init, - sc_host_destroy, name); + obj = sdb_object_create(sizeof(sdb_host_t), sdb_host_init, + sdb_host_destroy, name); if (! obj) return NULL; - return SC_HOST(obj); -} /* sc_host_create */ + return SDB_HOST(obj); +} /* sdb_host_create */ -sc_host_t * -sc_host_clone(const sc_host_t *host) +sdb_host_t * +sdb_host_clone(const sdb_host_t *host) { - sc_host_t *clone; + sdb_host_t *clone; - clone = sc_host_create(host->host_name); + clone = sdb_host_create(host->host_name); if (! clone) return NULL; - /* make sure these are initialized; else sc_object_deref() might access + /* make sure these are initialized; else sdb_object_deref() might access * arbitrary memory in case of an error */ clone->services = clone->attributes = NULL; if (host->attributes) { - clone->attributes = sc_llist_clone(host->attributes); + clone->attributes = sdb_llist_clone(host->attributes); if (! clone->attributes) { - sc_object_deref(SC_OBJ(clone)); + sdb_object_deref(SDB_OBJ(clone)); return NULL; } } clone->host_last_update = host->host_last_update; if (host->services) { - clone->services = sc_llist_clone(host->services); + clone->services = sdb_llist_clone(host->services); if (! clone->services) { - sc_object_deref(SC_OBJ(clone)); + sdb_object_deref(SDB_OBJ(clone)); return NULL; } } return clone; -} /* sc_host_clone */ +} /* sdb_host_clone */ int -sc_store_host(const sc_host_t *host) +sdb_store_host(const sdb_host_t *host) { - sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT; - sc_time_t last_update; + sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT; + sdb_time_t last_update; - sc_host_t *old; + sdb_host_t *old; int status = 0; if ((! host) || (! host->host_name)) @@ -240,20 +240,20 @@ sc_store_host(const sc_host_t *host) last_update = host->host_last_update; if (last_update <= 0) - last_update = sc_gettime(); + last_update = sdb_gettime(); pthread_rwlock_wrlock(&host_lock); if (! host_list) { - if (! (host_list = sc_llist_create())) { + if (! (host_list = sdb_llist_create())) { pthread_rwlock_unlock(&host_lock); return -1; } } lookup.obj_name = host->host_name; - old = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup, - sc_cmp_store_obj_with_name)); + old = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup, + sdb_cmp_store_obj_with_name)); if (old) { if (old->host_last_update > last_update) { @@ -269,107 +269,107 @@ sc_store_host(const sc_host_t *host) } } else { - sc_host_t *new = sc_host_clone(host); + sdb_host_t *new = sdb_host_clone(host); if (! new) { char errbuf[1024]; fprintf(stderr, "store: Failed to clone host object: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); pthread_rwlock_unlock(&host_lock); return -1; } if (! new->attributes) { - if (! (new->attributes = sc_llist_create())) { + if (! (new->attributes = sdb_llist_create())) { char errbuf[1024]; fprintf(stderr, "store: Failed to initialize " "host object '%s': %s\n", host->host_name, - sc_strerror(errno, errbuf, sizeof(errbuf))); - sc_object_deref(SC_OBJ(new)); + sdb_strerror(errno, errbuf, sizeof(errbuf))); + sdb_object_deref(SDB_OBJ(new)); pthread_rwlock_unlock(&host_lock); return -1; } } if (! new->services) { - if (! (new->services = sc_llist_create())) { + if (! (new->services = sdb_llist_create())) { char errbuf[1024]; fprintf(stderr, "store: Failed to initialize " "host object '%s': %s\n", host->host_name, - sc_strerror(errno, errbuf, sizeof(errbuf))); - sc_object_deref(SC_OBJ(new)); + sdb_strerror(errno, errbuf, sizeof(errbuf))); + sdb_object_deref(SDB_OBJ(new)); pthread_rwlock_unlock(&host_lock); return -1; } } - status = sc_llist_insert_sorted(host_list, SC_OBJ(new), - sc_store_obj_cmp_by_name); + status = sdb_llist_insert_sorted(host_list, SDB_OBJ(new), + sdb_store_obj_cmp_by_name); /* pass control to the list or destroy in case of an error */ - sc_object_deref(SC_OBJ(new)); + sdb_object_deref(SDB_OBJ(new)); } pthread_rwlock_unlock(&host_lock); return status; -} /* sc_store_host */ +} /* sdb_store_host */ -const sc_host_t * -sc_store_get_host(const char *name) +const sdb_host_t * +sdb_store_get_host(const char *name) { - sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT; - sc_host_t *host; + sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT; + sdb_host_t *host; if (! name) return NULL; lookup.obj_name = name; - host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup, - sc_cmp_store_obj_with_name)); + host = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup, + sdb_cmp_store_obj_with_name)); if (! host) return NULL; return host; -} /* sc_store_get_host */ +} /* sdb_store_get_host */ -sc_attribute_t * -sc_attribute_create(const char *hostname, +sdb_attribute_t * +sdb_attribute_create(const char *hostname, const char *name, const char *value) { - sc_object_t *obj; + sdb_object_t *obj; if ((! hostname) || (! name) || (! value)) return NULL; - obj = sc_object_create(sizeof(sc_attribute_t), sc_attr_init, - sc_attr_destroy, hostname, name, value); + obj = sdb_object_create(sizeof(sdb_attribute_t), sdb_attr_init, + sdb_attr_destroy, hostname, name, value); if (! obj) return NULL; - return SC_ATTR(obj); -} /* sc_attribute_create */ + return SDB_ATTR(obj); +} /* sdb_attribute_create */ -sc_attribute_t * -sc_attribute_clone(const sc_attribute_t *attr) +sdb_attribute_t * +sdb_attribute_clone(const sdb_attribute_t *attr) { - sc_attribute_t *clone; + sdb_attribute_t *clone; - clone = sc_attribute_create(attr->hostname, + clone = sdb_attribute_create(attr->hostname, attr->attr_name, attr->attr_value); if (! clone) return NULL; clone->attr_last_update = attr->attr_last_update; return clone; -} /* sc_attribute_clone */ +} /* sdb_attribute_clone */ int -sc_store_attribute(const sc_attribute_t *attr) +sdb_store_attribute(const sdb_attribute_t *attr) { - sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT; - sc_host_t *host; + sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT; + sdb_host_t *host; - sc_attribute_t *old; + sdb_attribute_t *old; - sc_time_t last_update; + sdb_time_t last_update; int status = 0; @@ -378,7 +378,7 @@ sc_store_attribute(const sc_attribute_t *attr) last_update = attr->attr_last_update; if (last_update <= 0) - last_update = sc_gettime(); + last_update = sdb_gettime(); if (! host_list) return -1; @@ -386,8 +386,8 @@ sc_store_attribute(const sc_attribute_t *attr) pthread_rwlock_wrlock(&host_lock); lookup.obj_name = attr->hostname; - host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup, - sc_cmp_store_obj_with_name)); + host = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup, + sdb_cmp_store_obj_with_name)); if (! host) { pthread_rwlock_unlock(&host_lock); @@ -395,9 +395,9 @@ sc_store_attribute(const sc_attribute_t *attr) } lookup.obj_name = attr->attr_name; - old = SC_ATTR(sc_llist_search(host->attributes, - (const sc_object_t *)&lookup, - sc_cmp_store_obj_with_name)); + old = SDB_ATTR(sdb_llist_search(host->attributes, + (const sdb_object_t *)&lookup, + sdb_cmp_store_obj_with_name)); if (old) { if (old->host_last_update > last_update) { @@ -412,63 +412,63 @@ sc_store_attribute(const sc_attribute_t *attr) } } else { - sc_attribute_t *new = sc_attribute_clone(attr); + sdb_attribute_t *new = sdb_attribute_clone(attr); if (! new) { char errbuf[1024]; fprintf(stderr, "store: Failed to clone attribute object: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); pthread_rwlock_unlock(&host_lock); return -1; } - status = sc_llist_insert_sorted(host->attributes, SC_OBJ(new), - sc_store_obj_cmp_by_name); + status = sdb_llist_insert_sorted(host->attributes, SDB_OBJ(new), + sdb_store_obj_cmp_by_name); /* pass control to the list or destroy in case of an error */ - sc_object_deref(SC_OBJ(new)); + sdb_object_deref(SDB_OBJ(new)); } pthread_rwlock_unlock(&host_lock); return status; -} /* sc_store_attribute */ +} /* sdb_store_attribute */ -sc_service_t * -sc_service_create(const char *hostname, const char *name) +sdb_service_t * +sdb_service_create(const char *hostname, const char *name) { - sc_object_t *obj; + sdb_object_t *obj; if ((! hostname) || (! name)) return NULL; - obj = sc_object_create(sizeof(sc_service_t), sc_svc_init, - sc_svc_destroy, hostname, name); + obj = sdb_object_create(sizeof(sdb_service_t), sdb_svc_init, + sdb_svc_destroy, hostname, name); if (! obj) return NULL; - return SC_SVC(obj); -} /* sc_service_create */ + return SDB_SVC(obj); +} /* sdb_service_create */ -sc_service_t * -sc_service_clone(const sc_service_t *svc) +sdb_service_t * +sdb_service_clone(const sdb_service_t *svc) { - sc_service_t *clone; + sdb_service_t *clone; - clone = sc_service_create(svc->hostname, svc->svc_name); + clone = sdb_service_create(svc->hostname, svc->svc_name); if (! clone) return NULL; clone->svc_last_update = svc->svc_last_update; return clone; -} /* sc_service_clone */ +} /* sdb_service_clone */ int -sc_store_service(const sc_service_t *svc) +sdb_store_service(const sdb_service_t *svc) { - sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT; - sc_host_t *host; + sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT; + sdb_host_t *host; - sc_service_t *old; + sdb_service_t *old; - sc_time_t last_update; + sdb_time_t last_update; int status = 0; @@ -477,7 +477,7 @@ sc_store_service(const sc_service_t *svc) last_update = svc->svc_last_update; if (last_update <= 0) - last_update = sc_gettime(); + last_update = sdb_gettime(); if (! host_list) return -1; @@ -485,8 +485,8 @@ sc_store_service(const sc_service_t *svc) pthread_rwlock_wrlock(&host_lock); lookup.obj_name = svc->hostname; - host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup, - sc_cmp_store_obj_with_name)); + host = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup, + sdb_cmp_store_obj_with_name)); if (! host) { pthread_rwlock_unlock(&host_lock); @@ -494,8 +494,8 @@ sc_store_service(const sc_service_t *svc) } lookup.obj_name = svc->svc_name; - old = SC_SVC(sc_llist_search(host->services, (const sc_object_t *)&lookup, - sc_cmp_store_obj_with_name)); + old = SDB_SVC(sdb_llist_search(host->services, (const sdb_object_t *)&lookup, + sdb_cmp_store_obj_with_name)); if (old) { if (old->host_last_update > last_update) { @@ -510,70 +510,71 @@ sc_store_service(const sc_service_t *svc) } } else { - sc_service_t *new = sc_service_clone(svc); + sdb_service_t *new = sdb_service_clone(svc); if (! new) { char errbuf[1024]; fprintf(stderr, "store: Failed to clone service object: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); pthread_rwlock_unlock(&host_lock); return -1; } - status = sc_llist_insert_sorted(host->services, SC_OBJ(new), - sc_store_obj_cmp_by_name); + status = sdb_llist_insert_sorted(host->services, SDB_OBJ(new), + sdb_store_obj_cmp_by_name); /* pass control to the list or destroy in case of an error */ - sc_object_deref(SC_OBJ(new)); + sdb_object_deref(SDB_OBJ(new)); } pthread_rwlock_unlock(&host_lock); return status; -} /* sc_store_service */ +} /* sdb_store_service */ -const sc_service_t * -sc_store_get_service(const sc_host_t *host, const char *name) +const sdb_service_t * +sdb_store_get_service(const sdb_host_t *host, const char *name) { - sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT; - sc_service_t *svc; + sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT; + sdb_service_t *svc; if ((! host) || (! name)) return NULL; lookup.obj_name = name; - svc = SC_SVC(sc_llist_search(host->services, (const sc_object_t *)&lookup, - sc_cmp_store_obj_with_name)); + svc = SDB_SVC(sdb_llist_search(host->services, + (const sdb_object_t *)&lookup, + sdb_cmp_store_obj_with_name)); if (! svc) return NULL; return svc; -} /* sc_store_get_service */ +} /* sdb_store_get_service */ int -sc_store_dump(FILE *fh) +sdb_store_dump(FILE *fh) { - sc_llist_iter_t *host_iter; + sdb_llist_iter_t *host_iter; if (! fh) return -1; pthread_rwlock_rdlock(&host_lock); - host_iter = sc_llist_get_iter(host_list); + host_iter = sdb_llist_get_iter(host_list); if (! host_iter) { pthread_rwlock_unlock(&host_lock); return -1; } - while (sc_llist_iter_has_next(host_iter)) { - sc_host_t *host = SC_HOST(sc_llist_iter_get_next(host_iter)); - sc_llist_iter_t *svc_iter; - sc_llist_iter_t *attr_iter; + while (sdb_llist_iter_has_next(host_iter)) { + sdb_host_t *host = SDB_HOST(sdb_llist_iter_get_next(host_iter)); + sdb_llist_iter_t *svc_iter; + sdb_llist_iter_t *attr_iter; char time_str[64]; assert(host); - if (! sc_strftime(time_str, sizeof(time_str), + if (! sdb_strftime(time_str, sizeof(time_str), "%F %T %z", host->host_last_update)) snprintf(time_str, sizeof(time_str), ""); time_str[sizeof(time_str) - 1] = '\0'; @@ -581,19 +582,19 @@ sc_store_dump(FILE *fh) fprintf(fh, "Host '%s' (last updated: %s):\n", host->host_name, time_str); - attr_iter = sc_llist_get_iter(host->attributes); + attr_iter = sdb_llist_get_iter(host->attributes); if (! attr_iter) { char errbuf[1024]; fprintf(fh, "Failed to retrieve attributes: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); continue; } - while (sc_llist_iter_has_next(attr_iter)) { - sc_attribute_t *attr = SC_ATTR(sc_llist_iter_get_next(attr_iter)); + while (sdb_llist_iter_has_next(attr_iter)) { + sdb_attribute_t *attr = SDB_ATTR(sdb_llist_iter_get_next(attr_iter)); assert(attr); - if (! sc_strftime(time_str, sizeof(time_str), + if (! sdb_strftime(time_str, sizeof(time_str), "%F %T %z", attr->attr_last_update)) snprintf(time_str, sizeof(time_str), ""); time_str[sizeof(time_str) - 1] = '\0'; @@ -602,21 +603,21 @@ sc_store_dump(FILE *fh) attr->attr_name, attr->attr_value, time_str); } - sc_llist_iter_destroy(attr_iter); + sdb_llist_iter_destroy(attr_iter); - svc_iter = sc_llist_get_iter(host->services); + svc_iter = sdb_llist_get_iter(host->services); if (! svc_iter) { char errbuf[1024]; fprintf(fh, "Failed to retrieve services: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); continue; } - while (sc_llist_iter_has_next(svc_iter)) { - sc_service_t *svc = SC_SVC(sc_llist_iter_get_next(svc_iter)); + while (sdb_llist_iter_has_next(svc_iter)) { + sdb_service_t *svc = SDB_SVC(sdb_llist_iter_get_next(svc_iter)); assert(svc); - if (! sc_strftime(time_str, sizeof(time_str), + if (! sdb_strftime(time_str, sizeof(time_str), "%F %T %z", svc->svc_last_update)) snprintf(time_str, sizeof(time_str), ""); time_str[sizeof(time_str) - 1] = '\0'; @@ -625,13 +626,13 @@ sc_store_dump(FILE *fh) svc->svc_name, time_str); } - sc_llist_iter_destroy(svc_iter); + sdb_llist_iter_destroy(svc_iter); } - sc_llist_iter_destroy(host_iter); + sdb_llist_iter_destroy(host_iter); pthread_rwlock_unlock(&host_lock); return 0; -} /* sc_store_dump */ +} /* sdb_store_dump */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/daemon/config.c b/src/daemon/config.c index 0b7cc77..aa5cb99 100644 --- a/src/daemon/config.c +++ b/src/daemon/config.c @@ -1,5 +1,5 @@ /* - * syscollector - src/daemon_config.c + * SysDB - src/daemon/config.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,7 +25,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "syscollector.h" +#include "sysdb.h" #include "core/plugin.h" #include "utils/time.h" @@ -41,14 +41,14 @@ * private variables */ -static sc_time_t default_interval = 0; +static sdb_time_t default_interval = 0; /* * private helper functions */ static int -config_get_interval(oconfig_item_t *ci, sc_time_t *interval) +config_get_interval(oconfig_item_t *ci, sdb_time_t *interval) { double interval_dbl = 0.0; @@ -68,7 +68,7 @@ config_get_interval(oconfig_item_t *ci, sc_time_t *interval) return -1; } - *interval = DOUBLE_TO_SC_TIME(interval_dbl); + *interval = DOUBLE_TO_SDB_TIME(interval_dbl); return 0; } /* config_get_interval */ @@ -93,8 +93,8 @@ daemon_load_backend(oconfig_item_t *ci) char plugin_name[1024]; char *name; - sc_plugin_ctx_t ctx = SC_PLUGIN_CTX_INIT; - sc_plugin_ctx_t old_ctx; + sdb_plugin_ctx_t ctx = SDB_PLUGIN_CTX_INIT; + sdb_plugin_ctx_t old_ctx; int status, i; @@ -123,9 +123,9 @@ daemon_load_backend(oconfig_item_t *ci) } } - old_ctx = sc_plugin_set_ctx(ctx); - status = sc_plugin_load(plugin_name); - sc_plugin_set_ctx(old_ctx); + old_ctx = sdb_plugin_set_ctx(ctx); + status = sdb_plugin_load(plugin_name); + sdb_plugin_set_ctx(old_ctx); return status; } /* daemon_load_backend */ @@ -144,7 +144,7 @@ daemon_configure_plugin(oconfig_item_t *ci) return -1; } - return sc_plugin_configure(name, ci); + return sdb_plugin_configure(name, ci); } /* daemon_configure_backend */ static token_parser_t token_parser_list[] = { diff --git a/src/daemon/syscollectord.c b/src/daemon/syscollectord.c deleted file mode 100644 index 86cbd2a..0000000 --- a/src/daemon/syscollectord.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * syscollector - src/syscollecord.c - * Copyright (C) 2012 Sebastian 'tokkee' Harl - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if HAVE_CONFIG_H -# include "config.h" -#endif /* HAVE_CONFIG_H */ - -#include "syscollector.h" -#include "core/plugin.h" -#include "core/store.h" -#include "utils/string.h" - -#include "daemon/config.h" - -#if HAVE_LIBGEN_H -# include -#else /* HAVE_LIBGEN_H */ -# define basename(path) (path) -#endif /* ! HAVE_LIBGEN_H */ - -#include - -#include -#include - -#include - -#include -#include -#include - -#include - -#ifndef CONFIGFILE -# define CONFIGFILE SYSCONFDIR"/syscollector/syscollectord.conf" -#endif - -static sc_plugin_loop_t plugin_main_loop = SC_PLUGIN_LOOP_INIT; - -static void -sigintterm_handler(int __attribute__((unused)) signo) -{ - plugin_main_loop.do_loop = 0; -} /* sigintterm_handler */ - -static void -exit_usage(char *name, int status) -{ - printf( -"Usage: %s \n" - -"\nOptions:\n" -" -C FILE the main configuration file\n" -" default: "CONFIGFILE"\n" -" -d run in background (daemonize)\n" -"\n" -" -h display this help and exit\n" -" -V display the version number and copyright\n" - -"\nsyscollectord "SC_VERSION_STRING SC_VERSION_EXTRA", "PACKAGE_URL"\n", -basename(name)); - exit(status); -} /* exit_usage */ - -static void -exit_version(void) -{ - printf("syscollectord version "SC_VERSION_STRING SC_VERSION_EXTRA", " - "built "BUILD_DATE"\n" - "using libsyscollection verion %s%s\n" - "Copyright (C) 2012 "PACKAGE_MAINTAINER"\n" - - "\nThis is free software under the terms of the BSD license, see " - "the source for\ncopying conditions. There is NO WARRANTY; not " - "even for MERCHANTABILITY or\nFITNESS FOR A PARTICULAR " - "PURPOSE.\n", sc_version_string(), sc_version_extra()); - exit(0); -} /* exit_version */ - -static int -daemonize(void) -{ - pid_t pid; - - if ((pid = fork()) < 0) { - char errbuf[1024]; - fprintf(stderr, "Failed to fork to background: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - return errno; - } - else if (pid != 0) { - /* parent */ - exit(0); - } - - if (chdir("/")) { - char errbuf[1024]; - fprintf(stderr, "Failed to change working directory to /: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - return errno; - } - - /* detach from session */ - setsid(); - - close(0); - if (open("/dev/null", O_RDWR)) { - char errbuf[1024]; - fprintf(stderr, "Failed to connect stdin to '/dev/null': %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - return errno; - } - - close(1); - if (dup(0) != 1) { - char errbuf[1024]; - fprintf(stderr, "Could not connect stdout to '/dev/null': %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - return errno; - } - - close(2); - if (dup(0) != 2) { - char errbuf[1024]; - fprintf(stdout, "Could not connect stderr to '/dev/null': %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - return errno; - } - return 0; -} /* daemonize */ - -int -main(int argc, char **argv) -{ - char *config_filename = NULL; - _Bool daemon = 0; - - struct sigaction sa_intterm; - - while (42) { - int opt = getopt(argc, argv, "C:dhV"); - - if (-1 == opt) - break; - - switch (opt) { - case 'C': - config_filename = optarg; - break; - case 'd': - daemon = 1; - break; - - case 'h': - exit_usage(argv[0], 0); - break; - case 'V': - exit_version(); - break; - default: - exit_usage(argv[0], 1); - } - } - - if (optind < argc) - exit_usage(argv[0], 1); - - if (! config_filename) - config_filename = CONFIGFILE; - - if (daemon_parse_config(config_filename)) { - fprintf(stderr, "Failed to parse configuration file.\n"); - exit(1); - } - - memset(&sa_intterm, 0, sizeof(sa_intterm)); - sa_intterm.sa_handler = sigintterm_handler; - sa_intterm.sa_flags = 0; - - if (sigaction(SIGINT, &sa_intterm, /* old action */ NULL)) { - char errbuf[1024]; - fprintf(stderr, "Failed to install signal handler for SIGINT: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - exit(1); - } - if (sigaction(SIGTERM, &sa_intterm, /* old action */ NULL)) { - char errbuf[1024]; - fprintf(stderr, "Failed to install signal handler for SIGTERM: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); - exit(1); - } - - if (daemon) - if (daemonize()) - exit(1); - - fprintf(stderr, "syscollectord "SC_VERSION_STRING SC_VERSION_EXTRA - " (pid %i) initialized successfully\n", (int)getpid()); - - sc_plugin_init_all(); - sc_plugin_collector_loop(&plugin_main_loop); - - fprintf(stderr, "Shutting down syscollector "SC_VERSION_STRING - SC_VERSION_EXTRA" (pid %i)\n", (int)getpid()); - - fprintf(stderr, "Store dump:\n"); - sc_store_dump(stderr); - return 0; -} /* main */ - -/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ - diff --git a/src/daemon/syscollectord.conf b/src/daemon/syscollectord.conf deleted file mode 100644 index 4fa379e..0000000 --- a/src/daemon/syscollectord.conf +++ /dev/null @@ -1,2 +0,0 @@ -LoadBackend "collectd" - diff --git a/src/daemon/sysdbd.c b/src/daemon/sysdbd.c new file mode 100644 index 0000000..8b7ebd4 --- /dev/null +++ b/src/daemon/sysdbd.c @@ -0,0 +1,236 @@ +/* + * SysDB - src/sysdbd.c + * Copyright (C) 2012 Sebastian 'tokkee' Harl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include "sysdb.h" +#include "core/plugin.h" +#include "core/store.h" +#include "utils/string.h" + +#include "daemon/config.h" + +#if HAVE_LIBGEN_H +# include +#else /* HAVE_LIBGEN_H */ +# define basename(path) (path) +#endif /* ! HAVE_LIBGEN_H */ + +#include + +#include +#include + +#include + +#include +#include +#include + +#include + +#ifndef CONFIGFILE +# define CONFIGFILE SYSCONFDIR"/sysdb/sysdbd.conf" +#endif + +static sdb_plugin_loop_t plugin_main_loop = SDB_PLUGIN_LOOP_INIT; + +static void +sigintterm_handler(int __attribute__((unused)) signo) +{ + plugin_main_loop.do_loop = 0; +} /* sigintterm_handler */ + +static void +exit_usage(char *name, int status) +{ + printf( +"Usage: %s \n" + +"\nOptions:\n" +" -C FILE the main configuration file\n" +" default: "CONFIGFILE"\n" +" -d run in background (daemonize)\n" +"\n" +" -h display this help and exit\n" +" -V display the version number and copyright\n" + +"\nSysDB daemon "SDB_VERSION_STRING SDB_VERSION_EXTRA", "PACKAGE_URL"\n", +basename(name)); + exit(status); +} /* exit_usage */ + +static void +exit_version(void) +{ + printf("SysDBd version "SDB_VERSION_STRING SDB_VERSION_EXTRA", " + "built "BUILD_DATE"\n" + "using libsysdb verion %s%s\n" + "Copyright (C) 2012 "PACKAGE_MAINTAINER"\n" + + "\nThis is free software under the terms of the BSD license, see " + "the source for\ncopying conditions. There is NO WARRANTY; not " + "even for MERCHANTABILITY or\nFITNESS FOR A PARTICULAR " + "PURPOSE.\n", sdb_version_string(), sdb_version_extra()); + exit(0); +} /* exit_version */ + +static int +daemonize(void) +{ + pid_t pid; + + if ((pid = fork()) < 0) { + char errbuf[1024]; + fprintf(stderr, "Failed to fork to background: %s\n", + sdb_strerror(errno, errbuf, sizeof(errbuf))); + return errno; + } + else if (pid != 0) { + /* parent */ + exit(0); + } + + if (chdir("/")) { + char errbuf[1024]; + fprintf(stderr, "Failed to change working directory to /: %s\n", + sdb_strerror(errno, errbuf, sizeof(errbuf))); + return errno; + } + + /* detach from session */ + setsid(); + + close(0); + if (open("/dev/null", O_RDWR)) { + char errbuf[1024]; + fprintf(stderr, "Failed to connect stdin to '/dev/null': %s\n", + sdb_strerror(errno, errbuf, sizeof(errbuf))); + return errno; + } + + close(1); + if (dup(0) != 1) { + char errbuf[1024]; + fprintf(stderr, "Could not connect stdout to '/dev/null': %s\n", + sdb_strerror(errno, errbuf, sizeof(errbuf))); + return errno; + } + + close(2); + if (dup(0) != 2) { + char errbuf[1024]; + fprintf(stdout, "Could not connect stderr to '/dev/null': %s\n", + sdb_strerror(errno, errbuf, sizeof(errbuf))); + return errno; + } + return 0; +} /* daemonize */ + +int +main(int argc, char **argv) +{ + char *config_filename = NULL; + _Bool daemon = 0; + + struct sigaction sa_intterm; + + while (42) { + int opt = getopt(argc, argv, "C:dhV"); + + if (-1 == opt) + break; + + switch (opt) { + case 'C': + config_filename = optarg; + break; + case 'd': + daemon = 1; + break; + + case 'h': + exit_usage(argv[0], 0); + break; + case 'V': + exit_version(); + break; + default: + exit_usage(argv[0], 1); + } + } + + if (optind < argc) + exit_usage(argv[0], 1); + + if (! config_filename) + config_filename = CONFIGFILE; + + if (daemon_parse_config(config_filename)) { + fprintf(stderr, "Failed to parse configuration file.\n"); + exit(1); + } + + memset(&sa_intterm, 0, sizeof(sa_intterm)); + sa_intterm.sa_handler = sigintterm_handler; + sa_intterm.sa_flags = 0; + + if (sigaction(SIGINT, &sa_intterm, /* old action */ NULL)) { + char errbuf[1024]; + fprintf(stderr, "Failed to install signal handler for SIGINT: %s\n", + sdb_strerror(errno, errbuf, sizeof(errbuf))); + exit(1); + } + if (sigaction(SIGTERM, &sa_intterm, /* old action */ NULL)) { + char errbuf[1024]; + fprintf(stderr, "Failed to install signal handler for SIGTERM: %s\n", + sdb_strerror(errno, errbuf, sizeof(errbuf))); + exit(1); + } + + if (daemon) + if (daemonize()) + exit(1); + + fprintf(stderr, "SysDB daemon "SDB_VERSION_STRING SDB_VERSION_EXTRA + " (pid %i) initialized successfully\n", (int)getpid()); + + sdb_plugin_init_all(); + sdb_plugin_collector_loop(&plugin_main_loop); + + fprintf(stderr, "Shutting down SysDB daemon "SDB_VERSION_STRING + SDB_VERSION_EXTRA" (pid %i)\n", (int)getpid()); + + fprintf(stderr, "Store dump:\n"); + sdb_store_dump(stderr); + return 0; +} /* main */ + +/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ + diff --git a/src/daemon/sysdbd.conf b/src/daemon/sysdbd.conf new file mode 100644 index 0000000..4fa379e --- /dev/null +++ b/src/daemon/sysdbd.conf @@ -0,0 +1,2 @@ +LoadBackend "collectd" + diff --git a/src/include/core/object.h b/src/include/core/object.h index 71d0297..f2992c7 100644 --- a/src/include/core/object.h +++ b/src/include/core/object.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/core/object.h + * SysDB - src/include/core/object.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,8 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_CORE_OBJECT_H -#define SC_CORE_OBJECT_H 1 +#ifndef SDB_CORE_OBJECT_H +#define SDB_CORE_OBJECT_H 1 #include #include @@ -35,28 +35,28 @@ extern "C" { #endif -struct sc_object; -typedef struct sc_object sc_object_t; +struct sdb_object; +typedef struct sdb_object sdb_object_t; -struct sc_object { +struct sdb_object { int ref_cnt; - void (*destructor)(sc_object_t *); + void (*destructor)(sdb_object_t *); size_t size; }; -#define SC_OBJECT_INIT { 1, NULL, 0 } +#define SDB_OBJECT_INIT { 1, NULL, 0 } typedef struct { - sc_object_t super; + sdb_object_t super; void *data; void (*destructor)(void *); -} sc_object_wrapper_t; +} sdb_object_wrapper_t; -#define SC_OBJ(obj) ((sc_object_t *)(obj)) -#define SC_OBJ_WRAPPER(obj) ((sc_object_wrapper_t *)(obj)) +#define SDB_OBJ(obj) ((sdb_object_t *)(obj)) +#define SDB_OBJ_WRAPPER(obj) ((sdb_object_wrapper_t *)(obj)) /* - * sc_object_create: - * Allocates a new sc_object_t of the specified 'size'. The object will be + * sdb_object_create: + * Allocates a new sdb_object_t of the specified 'size'. The object will be * initialized to zero and then passed on to the 'init' function (if * specified). If specified, the 'destructor' will be called, when the * reference count drops to zero and before freeing the memory allocated by @@ -71,42 +71,42 @@ typedef struct { * - the newly allocated object * - NULL on error */ -sc_object_t * -sc_object_create(size_t size, int (*init)(sc_object_t *, va_list), - void (*destructor)(sc_object_t *), ...); +sdb_object_t * +sdb_object_create(size_t size, int (*init)(sdb_object_t *, va_list), + void (*destructor)(sdb_object_t *), ...); /* - * sc_object_create_wrapper: - * Create a new sc_object_t wrapping some arbitrary other object. + * sdb_object_create_wrapper: + * Create a new sdb_object_t wrapping some arbitrary other object. */ -sc_object_t * -sc_object_create_wrapper(void *data, void (*destructor)(void *)); +sdb_object_t * +sdb_object_create_wrapper(void *data, void (*destructor)(void *)); -#define SC_OBJECT_WRAPPER_STATIC(obj, destructor) \ - { SC_OBJECT_INIT, (obj), (destructor) } +#define SDB_OBJECT_WRAPPER_STATIC(obj, destructor) \ + { SDB_OBJECT_INIT, (obj), (destructor) } /* - * sc_object_deref: + * sdb_object_deref: * Dereference the object and free the allocated memory in case the ref-count * drops to zero. In case a 'destructor' had been registered with the object, * it will be called before freeing the memory. */ void -sc_object_deref(sc_object_t *obj); +sdb_object_deref(sdb_object_t *obj); /* - * sc_object_ref: + * sdb_object_ref: * Take ownership of the specified object, that is, increment the reference * count by one. */ void -sc_object_ref(sc_object_t *obj); +sdb_object_ref(sdb_object_t *obj); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_CORE_OBJECT_H */ +#endif /* ! SDB_CORE_OBJECT_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/core/plugin.h b/src/include/core/plugin.h index 8d54089..1ac243a 100644 --- a/src/include/core/plugin.h +++ b/src/include/core/plugin.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/core/plugin.h + * SysDB - src/include/core/plugin.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,10 +25,10 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_CORE_PLUGIN_H -#define SC_CORE_PLUGIN_H 1 +#ifndef SDB_CORE_PLUGIN_H +#define SDB_CORE_PLUGIN_H 1 -#include "syscollector.h" +#include "sysdb.h" #include "core/object.h" #include "utils/time.h" @@ -39,62 +39,62 @@ extern "C" { #endif typedef struct { - sc_time_t interval; -} sc_plugin_ctx_t; -#define SC_PLUGIN_CTX_INIT { 0 } + sdb_time_t interval; +} sdb_plugin_ctx_t; +#define SDB_PLUGIN_CTX_INIT { 0 } -struct sc_plugin_info; -typedef struct sc_plugin_info sc_plugin_info_t; +struct sdb_plugin_info; +typedef struct sdb_plugin_info sdb_plugin_info_t; /* this should be used in the header of a plugin to avoid * missing prototype warnings/errors for the plugin init * function */ -#define SC_PLUGIN_MAGIC \ - int sc_module_init(sc_plugin_info_t *info); +#define SDB_PLUGIN_MAGIC \ + int sdb_module_init(sdb_plugin_info_t *info); typedef struct { _Bool do_loop; - sc_time_t default_interval; -} sc_plugin_loop_t; -#define SC_PLUGIN_LOOP_INIT { 1, 0 } + sdb_time_t default_interval; +} sdb_plugin_loop_t; +#define SDB_PLUGIN_LOOP_INIT { 1, 0 } /* - * sc_plugin_load: + * sdb_plugin_load: * Load (any type of) plugin by loading the shared object file and calling the - * sc_module_init function. + * sdb_module_init function. */ int -sc_plugin_load(const char *name); +sdb_plugin_load(const char *name); /* - * sc_plugin_set_info: - * Fill in the fields of the sc_plugin_info_t object passed to the - * sc_module_init function. This information is used to identify the plugin + * sdb_plugin_set_info: + * Fill in the fields of the sdb_plugin_info_t object passed to the + * sdb_module_init function. This information is used to identify the plugin * and also to provide additional information to the user. */ enum { - SC_PLUGIN_INFO_NAME, /* plugin name: string */ - SC_PLUGIN_INFO_DESC, /* plugin description: string */ - SC_PLUGIN_INFO_COPYRIGHT, /* plugin copyright: string */ - SC_PLUGIN_INFO_LICENSE, /* plugin license: string */ - SC_PLUGIN_INFO_VERSION, /* libsyscollector version: integer */ - SC_PLUGIN_INFO_PLUGIN_VERSION /* plugin version: integer */ + SDB_PLUGIN_INFO_NAME, /* plugin name: string */ + SDB_PLUGIN_INFO_DESC, /* plugin description: string */ + SDB_PLUGIN_INFO_COPYRIGHT, /* plugin copyright: string */ + SDB_PLUGIN_INFO_LICENSE, /* plugin license: string */ + SDB_PLUGIN_INFO_VERSION, /* libsysdb version: integer */ + SDB_PLUGIN_INFO_PLUGIN_VERSION /* plugin version: integer */ }; int -sc_plugin_set_info(sc_plugin_info_t *info, int type, ...); +sdb_plugin_set_info(sdb_plugin_info_t *info, int type, ...); /* * plugin callback functions */ -typedef int (*sc_plugin_config_cb)(oconfig_item_t *ci); -typedef int (*sc_plugin_init_cb)(sc_object_t *user_data); -typedef int (*sc_plugin_collector_cb)(sc_object_t *user_data); -typedef int (*sc_plugin_shutdown_cb)(sc_object_t *user_data); +typedef int (*sdb_plugin_config_cb)(oconfig_item_t *ci); +typedef int (*sdb_plugin_init_cb)(sdb_object_t *user_data); +typedef int (*sdb_plugin_collector_cb)(sdb_object_t *user_data); +typedef int (*sdb_plugin_shutdown_cb)(sdb_object_t *user_data); /* - * sc_plugin_register_config: + * sdb_plugin_register_config: * Register a "config" function. This will be used to pass on the * configuration for a plugin. The plugin has to make sure that the function * can be called multiple times in order to process multiple blocks @@ -105,10 +105,10 @@ typedef int (*sc_plugin_shutdown_cb)(sc_object_t *user_data); * - a negative value else */ int -sc_plugin_register_config(const char *name, sc_plugin_config_cb callback); +sdb_plugin_register_config(const char *name, sdb_plugin_config_cb callback); /* - * sc_plugin_register_init: + * sdb_plugin_register_init: * Register an "init" function. All "init" functions will be called after * finishing the config parsing and before starting any other work. The * functions will be called in the same order as they have been registered, @@ -129,11 +129,11 @@ sc_plugin_register_config(const char *name, sc_plugin_config_cb callback); * - a negative value else */ int -sc_plugin_register_init(const char *name, sc_plugin_init_cb callback, - sc_object_t *user_data); +sdb_plugin_register_init(const char *name, sdb_plugin_init_cb callback, + sdb_object_t *user_data); /* - * sc_plugin_register_collector: + * sdb_plugin_register_collector: * Register a "collector" function. This is where a backend is doing its main * work. This function will be called whenever an update of a backend has been * requested (either by regular interval or by user request). The backend @@ -153,11 +153,12 @@ sc_plugin_register_init(const char *name, sc_plugin_init_cb callback, * - a negative value else */ int -sc_plugin_register_collector(const char *name, sc_plugin_collector_cb callback, - const sc_time_t *interval, sc_object_t *user_data); +sdb_plugin_register_collector(const char *name, + sdb_plugin_collector_cb callback, + const sdb_time_t *interval, sdb_object_t *user_data); /* - * sc_plugin_register_shutdown: + * sdb_plugin_register_shutdown: * Register a "shutdown" function to be called after stopping all update * processes and before shutting down the daemon. * @@ -168,23 +169,24 @@ sc_plugin_register_collector(const char *name, sc_plugin_collector_cb callback, * use the object for other purposes, it should thus deref it. */ int -sc_plugin_register_shutdown(const char *name, sc_plugin_shutdown_cb callback, - sc_object_t *user_data); +sdb_plugin_register_shutdown(const char *name, + sdb_plugin_shutdown_cb callback, + sdb_object_t *user_data); /* - * sc_plugin_get_ctx, sc_plugin_set_ctx: + * sdb_plugin_get_ctx, sdb_plugin_set_ctx: * The plugin context defines a set of settings that are available whenever a * plugin has been called. It may be used to pass around various information * between the different component of the library without having each and * every plugin care about it. */ -sc_plugin_ctx_t -sc_plugin_get_ctx(void); -sc_plugin_ctx_t -sc_plugin_set_ctx(sc_plugin_ctx_t ctx); +sdb_plugin_ctx_t +sdb_plugin_get_ctx(void); +sdb_plugin_ctx_t +sdb_plugin_set_ctx(sdb_plugin_ctx_t ctx); /* - * sc_plugin_configure: + * sdb_plugin_configure: * Configure the plugin called 'name' (according to the registered config * callback) using the config tree 'ci'. * @@ -193,17 +195,17 @@ sc_plugin_set_ctx(sc_plugin_ctx_t ctx); * - a negative value else */ int -sc_plugin_configure(const char *name, oconfig_item_t *ci); +sdb_plugin_configure(const char *name, oconfig_item_t *ci); /* - * sc_plugin_init_all: + * sdb_plugin_init_all: * Initialize all plugins using their registered "init" function. */ int -sc_plugin_init_all(void); +sdb_plugin_init_all(void); /* - * sc_plugin_collector_loop: + * sdb_plugin_collector_loop: * Loop until loop->do_loop is false, calling the next collector function on * each iteration and once its next update interval is passed. * @@ -212,13 +214,13 @@ sc_plugin_init_all(void); * - a negative value else */ int -sc_plugin_collector_loop(sc_plugin_loop_t *loop); +sdb_plugin_collector_loop(sdb_plugin_loop_t *loop); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_CORE_PLUGIN_H */ +#endif /* ! SDB_CORE_PLUGIN_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/core/store.h b/src/include/core/store.h index cadbfe4..3c2b7a8 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/core/store.h + * SysDB - src/include/core/store.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,10 +25,10 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_CORE_STORE_H -#define SC_CORE_STORE_H 1 +#ifndef SDB_CORE_STORE_H +#define SDB_CORE_STORE_H 1 -#include "syscollector.h" +#include "sysdb.h" #include "core/object.h" #include "utils/time.h" #include "utils/llist.h" @@ -40,54 +40,54 @@ extern "C" { #endif typedef struct { - sc_object_t parent; + sdb_object_t parent; - sc_time_t last_update; + sdb_time_t last_update; char *name; -} sc_store_obj_t; -#define SC_STORE_OBJ_INIT { SC_OBJECT_INIT, 0, NULL } -#define SC_STORE_OBJ(obj) ((sc_store_obj_t *)(obj)) +} sdb_store_obj_t; +#define SDB_STORE_OBJ_INIT { SDB_OBJECT_INIT, 0, NULL } +#define SDB_STORE_OBJ(obj) ((sdb_store_obj_t *)(obj)) typedef struct { - sc_store_obj_t parent; + sdb_store_obj_t parent; #define svc_last_update parent.last_update #define svc_name parent.name char *hostname; -} sc_service_t; -#define SC_SVC_INIT { SC_STORE_OBJ_INIT, NULL } -#define SC_SVC(obj) ((sc_service_t *)(obj)) +} sdb_service_t; +#define SDB_SVC_INIT { SDB_STORE_OBJ_INIT, NULL } +#define SDB_SVC(obj) ((sdb_service_t *)(obj)) typedef struct { - sc_store_obj_t parent; + sdb_store_obj_t parent; #define attr_last_update parent.last_update #define attr_name parent.name char *attr_value; char *hostname; -} sc_attribute_t; -#define SC_ATTR_INIT { SC_STORE_OBJ_INIT, NULL, NULL } -#define SC_ATTR(obj) ((sc_attribute_t *)(obj)) +} sdb_attribute_t; +#define SDB_ATTR_INIT { SDB_STORE_OBJ_INIT, NULL, NULL } +#define SDB_ATTR(obj) ((sdb_attribute_t *)(obj)) typedef struct { - sc_store_obj_t parent; + sdb_store_obj_t parent; #define host_last_update parent.last_update #define host_name parent.name - sc_llist_t *attributes; - sc_llist_t *services; -} sc_host_t; -#define SC_HOST_INIT { SC_STORE_OBJ_INIT, NULL, NULL } -#define SC_HOST(obj) ((sc_host_t *)(obj)) + sdb_llist_t *attributes; + sdb_llist_t *services; +} sdb_host_t; +#define SDB_HOST_INIT { SDB_STORE_OBJ_INIT, NULL, NULL } +#define SDB_HOST(obj) ((sdb_host_t *)(obj)) -sc_host_t * -sc_host_create(const char *name); +sdb_host_t * +sdb_host_create(const char *name); -sc_host_t * -sc_host_clone(const sc_host_t *host); +sdb_host_t * +sdb_host_clone(const sdb_host_t *host); /* - * sc_store_host: + * sdb_store_host: * Add/update a host in the store. If the host, identified by its name, * already exists, it will be updated according to the specified 'host' * object. Else, a new entry will be created in the store. Any memory required @@ -101,20 +101,20 @@ sc_host_clone(const sc_host_t *host); * - a negative value on error */ int -sc_store_host(const sc_host_t *host); +sdb_store_host(const sdb_host_t *host); -const sc_host_t * -sc_store_get_host(const char *name); +const sdb_host_t * +sdb_store_get_host(const char *name); -sc_attribute_t * -sc_attribute_create(const char *hostname, +sdb_attribute_t * +sdb_attribute_create(const char *hostname, const char *name, const char *value); -sc_attribute_t * -sc_attribute_clone(const sc_attribute_t *attr); +sdb_attribute_t * +sdb_attribute_clone(const sdb_attribute_t *attr); /* - * sc_store_attribute: + * sdb_store_attribute: * Add/update a host's attribute in the store. If the attribute, identified by * its name, already exists for the specified host, it will be updated * according to the specified 'attr' object. If the referenced host does not @@ -130,16 +130,16 @@ sc_attribute_clone(const sc_attribute_t *attr); * - a negative value on error */ int -sc_store_attribute(const sc_attribute_t *attr); +sdb_store_attribute(const sdb_attribute_t *attr); -sc_service_t * -sc_service_create(const char *hostname, const char *name); +sdb_service_t * +sdb_service_create(const char *hostname, const char *name); -sc_service_t * -sc_service_clone(const sc_service_t *svc); +sdb_service_t * +sdb_service_clone(const sdb_service_t *svc); /* - * sc_store_service: + * sdb_store_service: * Add/update a store in the store. If the service, identified by its name, * already exists for the specified host, it will be updated according to the * specified 'service' object. If the referenced host does not exist, an error @@ -155,19 +155,19 @@ sc_service_clone(const sc_service_t *svc); * - a negative value on error */ int -sc_store_service(const sc_service_t *svc); +sdb_store_service(const sdb_service_t *svc); -const sc_service_t * -sc_store_get_service(const sc_host_t *host, const char *name); +const sdb_service_t * +sdb_store_get_service(const sdb_host_t *host, const char *name); int -sc_store_dump(FILE *fh); +sdb_store_dump(FILE *fh); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_CORE_STORE_H */ +#endif /* ! SDB_CORE_STORE_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/daemon/config.h b/src/include/daemon/config.h index 716c105..6d4b0d3 100644 --- a/src/include/daemon/config.h +++ b/src/include/daemon/config.h @@ -1,5 +1,5 @@ /* - * syscollector - src/daemon/config.h + * SysDB - src/daemon/config.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * diff --git a/src/include/syscollector.h.in b/src/include/syscollector.h.in deleted file mode 100644 index ff35fa5..0000000 --- a/src/include/syscollector.h.in +++ /dev/null @@ -1,69 +0,0 @@ -/* - * syscollector - src/include/syscollector.h - * Copyright (C) 2012 Sebastian 'tokkee' Harl - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SYSCOLLECTOR_H -#define SYSCOLLECTOR_H 1 - -#define SC_VERSION_MAJOR @SC_VERSION_MAJOR@ -#define SC_VERSION_MINOR @SC_VERSION_MINOR@ -#define SC_VERSION_PATCH @SC_VERSION_PATCH@ - -#define SC_VERSION_EXTRA "@SC_VERSION_EXTRA@" - -#define SC_VERSION_STRING "@SC_VERSION_STRING@" - -#define SC_VERSION_ENCODE(major, minor, patch) \ - ((major) * 10000 + (minor) * 100 + (patch)) -#define SC_VERSION_DECODE(version) \ - (int)((version) / 10000), \ - (int)((version) / 100) - (int)((version) / 10000) * 100, \ - (int)(version) - (int)((version) / 100) * 100 - -#define SC_VERSION SC_VERSION_ENCODE(SC_VERSION_MAJOR, SC_VERSION_MINOR, \ - SC_VERSION_PATCH) - -#ifdef __cplusplus -extern "C" { -#endif - -unsigned int -sc_version(void); - -const char * -sc_version_string(void); - -const char * -sc_version_extra(void); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* ! SYSCOLLECTOR_H */ - -/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ - diff --git a/src/include/sysdb.h.in b/src/include/sysdb.h.in new file mode 100644 index 0000000..5c26de8 --- /dev/null +++ b/src/include/sysdb.h.in @@ -0,0 +1,69 @@ +/* + * SysDB - src/include/sysdb.h + * Copyright (C) 2012 Sebastian 'tokkee' Harl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SYSDB_H +#define SYSDB_H 1 + +#define SDB_VERSION_MAJOR @SDB_VERSION_MAJOR@ +#define SDB_VERSION_MINOR @SDB_VERSION_MINOR@ +#define SDB_VERSION_PATCH @SDB_VERSION_PATCH@ + +#define SDB_VERSION_EXTRA "@SDB_VERSION_EXTRA@" + +#define SDB_VERSION_STRING "@SDB_VERSION_STRING@" + +#define SDB_VERSION_ENCODE(major, minor, patch) \ + ((major) * 10000 + (minor) * 100 + (patch)) +#define SDB_VERSION_DECODE(version) \ + (int)((version) / 10000), \ + (int)((version) / 100) - (int)((version) / 10000) * 100, \ + (int)(version) - (int)((version) / 100) * 100 + +#define SDB_VERSION SDB_VERSION_ENCODE(SDB_VERSION_MAJOR, SDB_VERSION_MINOR, \ + SDB_VERSION_PATCH) + +#ifdef __cplusplus +extern "C" { +#endif + +unsigned int +sdb_version(void); + +const char * +sdb_version_string(void); + +const char * +sdb_version_extra(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* ! SYSDB_H */ + +/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ + diff --git a/src/include/utils/data.h b/src/include/utils/data.h index a18d658..0f38a11 100644 --- a/src/include/utils/data.h +++ b/src/include/utils/data.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/utils/data.h + * SysDB - src/include/utils/data.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,8 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_UTILS_DATA_H -#define SC_UTILS_DATA_H 1 +#ifndef SDB_UTILS_DATA_H +#define SDB_UTILS_DATA_H 1 #include "utils/time.h" @@ -38,15 +38,15 @@ extern "C" { #endif enum { - SC_TYPE_INTEGER = 1, - SC_TYPE_DECIMAL, - SC_TYPE_STRING, - SC_TYPE_DATETIME, - SC_TYPE_BINARY, + SDB_TYPE_INTEGER = 1, + SDB_TYPE_DECIMAL, + SDB_TYPE_STRING, + SDB_TYPE_DATETIME, + SDB_TYPE_BINARY, }; /* - * sc_data_t: + * sdb_data_t: * A datum retrieved from an arbitrary data source. * * The string and binary objects are managed by whoever creates the data @@ -56,22 +56,22 @@ enum { typedef struct { int type; union { - int64_t integer; /* SC_TYPE_INTEGER */ - double decimal; /* SC_TYPE_DECIMAL */ - const char *string; /* SC_TYPE_STRING */ - sc_time_t datetime; /* SC_TYPE_DATETIME */ + int64_t integer; /* SDB_TYPE_INTEGER */ + double decimal; /* SDB_TYPE_DECIMAL */ + const char *string; /* SDB_TYPE_STRING */ + sdb_time_t datetime; /* SDB_TYPE_DATETIME */ struct { size_t length; const unsigned char *datum; - } binary; /* SC_TYPE_BINARY */ + } binary; /* SDB_TYPE_BINARY */ } data; -} sc_data_t; +} sdb_data_t; #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_UTILS_DATA_H */ +#endif /* ! SDB_UTILS_DATA_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/utils/dbi.h b/src/include/utils/dbi.h index b910b97..77d0042 100644 --- a/src/include/utils/dbi.h +++ b/src/include/utils/dbi.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/utils/dbi.h + * SysDB - src/include/utils/dbi.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,58 +25,58 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_UTILS_DBI_H -#define SC_UTILS_DBI_H 1 +#ifndef SDB_UTILS_DBI_H +#define SDB_UTILS_DBI_H 1 #include "core/object.h" #include "utils/data.h" #include -/* translate libdbi types to syscollector types */ +/* translate libdbi types to SysDB types */ #define DBI_TYPE_TO_SC(dt) \ (((dt) == DBI_TYPE_INTEGER) \ - ? SC_TYPE_INTEGER \ + ? SDB_TYPE_INTEGER \ : ((dt) == DBI_TYPE_DECIMAL) \ - ? SC_TYPE_DECIMAL \ + ? SDB_TYPE_DECIMAL \ : ((dt) == DBI_TYPE_STRING) \ - ? SC_TYPE_STRING \ + ? SDB_TYPE_STRING \ : ((dt) == DBI_TYPE_DATETIME) \ - ? SC_TYPE_DATETIME \ + ? SDB_TYPE_DATETIME \ : ((dt) == DBI_TYPE_BINARY) \ - ? SC_TYPE_BINARY : 0) + ? SDB_TYPE_BINARY : 0) #ifdef __cplusplus extern "C" { #endif -struct sc_dbi_options; -typedef struct sc_dbi_options sc_dbi_options_t; +struct sdb_dbi_options; +typedef struct sdb_dbi_options sdb_dbi_options_t; -struct sc_dbi_client; -typedef struct sc_dbi_client sc_dbi_client_t; +struct sdb_dbi_client; +typedef struct sdb_dbi_client sdb_dbi_client_t; -typedef int (*sc_dbi_data_cb)(sc_dbi_client_t *, - size_t, sc_data_t *, sc_object_t *); +typedef int (*sdb_dbi_data_cb)(sdb_dbi_client_t *, + size_t, sdb_data_t *, sdb_object_t *); /* - * sc_dbi_options_t: + * sdb_dbi_options_t: * This object stores DBI connection options (key/value) (e.g. host, dbname, * etc.). It may be used to dynamically create the list of options before * applying it to some client object. */ -sc_dbi_options_t * -sc_dbi_options_create(void); +sdb_dbi_options_t * +sdb_dbi_options_create(void); int -sc_dbi_options_add(sc_dbi_options_t *options, +sdb_dbi_options_add(sdb_dbi_options_t *options, const char *key, const char *value); void -sc_dbi_options_destroy(sc_dbi_options_t *options); +sdb_dbi_options_destroy(sdb_dbi_options_t *options); /* - * sc_dbi_client_create: + * sdb_dbi_client_create: * Creates a new DBI client object using the specified DBI / DBD 'driver' and * connecting to the specified 'database'. * @@ -84,24 +84,24 @@ sc_dbi_options_destroy(sc_dbi_options_t *options); * - the client object on success * - NULL else */ -sc_dbi_client_t * -sc_dbi_client_create(const char *driver, const char *database); +sdb_dbi_client_t * +sdb_dbi_client_create(const char *driver, const char *database); /* - * sc_dbi_client_set_options: + * sdb_dbi_client_set_options: * Apply connection options to an existing client object. This has to be done - * before actually connecting to the database using sc_dbi_client_connect(). + * before actually connecting to the database using sdb_dbi_client_connect(). * * Returns: * - 0 on success * - a negative value else */ int -sc_dbi_client_set_options(sc_dbi_client_t *client, - sc_dbi_options_t *options); +sdb_dbi_client_set_options(sdb_dbi_client_t *client, + sdb_dbi_options_t *options); /* - * sc_dbi_client_connect: + * sdb_dbi_client_connect: * Connect to the database using the options registered beforehand. * * This function may also be used to reconnect to the database. @@ -111,17 +111,17 @@ sc_dbi_client_set_options(sc_dbi_client_t *client, * - a negative value else */ int -sc_dbi_client_connect(sc_dbi_client_t *client); +sdb_dbi_client_connect(sdb_dbi_client_t *client); /* - * sc_dbi_exec_query: + * sdb_dbi_exec_query: * Execute an SQL query on the database. The specified 'callback' will be * called for each row returned from the query. If 'n' is a value equal to or * greater than zero, it specifies the number of columns that are expected in * the query result. For each column, the caller then needs to also specify * the requested type (see the DBI_TYPE_* constants). If the number or types * do not match, an error will be reported and the query will fail. That is, - * this allows to let sc_dbi_exec_query() do basic verification of the + * this allows to let sdb_dbi_exec_query() do basic verification of the * returned values. * * The callback will receive the client object and an array containing the @@ -134,21 +134,21 @@ sc_dbi_client_connect(sc_dbi_client_t *client); * - a negative value else */ int -sc_dbi_exec_query(sc_dbi_client_t *client, const char *query, - sc_dbi_data_cb callback, sc_object_t *user_data, int n, ...); +sdb_dbi_exec_query(sdb_dbi_client_t *client, const char *query, + sdb_dbi_data_cb callback, sdb_object_t *user_data, int n, ...); /* - * sc_dbi_client_destroy: + * sdb_dbi_client_destroy: * Disconnect from the database and destroy the client object. */ void -sc_dbi_client_destroy(sc_dbi_client_t *client); +sdb_dbi_client_destroy(sdb_dbi_client_t *client); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_UTILS_DBI_H */ +#endif /* ! SDB_UTILS_DBI_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/utils/llist.h b/src/include/utils/llist.h index c115bf2..354e976 100644 --- a/src/include/utils/llist.h +++ b/src/include/utils/llist.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/utils/llist.h + * SysDB - src/include/utils/llist.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,8 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_UTILS_LLIST_H -#define SC_UTILS_LLIST_H 1 +#ifndef SDB_UTILS_LLIST_H +#define SDB_UTILS_LLIST_H 1 #include "core/object.h" @@ -34,27 +34,27 @@ extern "C" { #endif -struct sc_llist; -typedef struct sc_llist sc_llist_t; +struct sdb_llist; +typedef struct sdb_llist sdb_llist_t; -struct sc_llist_iter; -typedef struct sc_llist_iter sc_llist_iter_t; +struct sdb_llist_iter; +typedef struct sdb_llist_iter sdb_llist_iter_t; /* - * sc_llist_create, sc_llist_destroy: + * sdb_llist_create, sdb_llist_destroy: * Create and destroy a doubly linked list object. * - * sc_llist_create returns NULL on error. - * sc_llist_destroy will also destroy all remaining elements, thus releasing + * sdb_llist_create returns NULL on error. + * sdb_llist_destroy will also destroy all remaining elements, thus releasing * the included objects (decrement the ref-count). */ -sc_llist_t * -sc_llist_create(void); +sdb_llist_t * +sdb_llist_create(void); void -sc_llist_destroy(sc_llist_t *list); +sdb_llist_destroy(sdb_llist_t *list); /* - * sc_llist_clone: + * sdb_llist_clone: * Clone an existing list. The objects stored in the list will not be copied * but rather their reference count incremented. * @@ -62,11 +62,11 @@ sc_llist_destroy(sc_llist_t *list); * - the copied list on success * - NULL else */ -sc_llist_t * -sc_llist_clone(sc_llist_t *list); +sdb_llist_t * +sdb_llist_clone(sdb_llist_t *list); /* - * sc_llist_append: + * sdb_llist_append: * Append the given 'obj' to the end of 'list'. The list will take ownership * of the object, that is, increment the reference count by one. In case the * caller does not longer use the object for other purposes, it should thus @@ -77,10 +77,10 @@ sc_llist_clone(sc_llist_t *list); * - a negative value on failure */ int -sc_llist_append(sc_llist_t *list, sc_object_t *obj); +sdb_llist_append(sdb_llist_t *list, sdb_object_t *obj); /* - * sc_llist_insert: + * sdb_llist_insert: * Insert the new element at the specified position (zero being the head of * the list; the length of the list being the tail)). If the index is greater * than the length of the list (i.e. past the tail of the list), an error is @@ -93,10 +93,10 @@ sc_llist_append(sc_llist_t *list, sc_object_t *obj); * - a negative value on failure */ int -sc_llist_insert(sc_llist_t *list, sc_object_t *obj, size_t index); +sdb_llist_insert(sdb_llist_t *list, sdb_object_t *obj, size_t index); /* - * sc_llist_insert_sorted: + * sdb_llist_insert_sorted: * Insert the given 'obj' in the 'list' using a sort order as determined by * the 'compare' function. The function will insert the new entry before the * first entry which sorts later than the new entry. It will not ensure that @@ -113,24 +113,24 @@ sc_llist_insert(sc_llist_t *list, sc_object_t *obj, size_t index); * - a negative value on failure */ int -sc_llist_insert_sorted(sc_llist_t *list, sc_object_t *obj, - int (*compare)(const sc_object_t *, const sc_object_t *)); +sdb_llist_insert_sorted(sdb_llist_t *list, sdb_object_t *obj, + int (*compare)(const sdb_object_t *, const sdb_object_t *)); -/* sc_llist_search: +/* sdb_llist_search: * Search for a 'key' in the given 'list'. The function will return the first * entry that matches the specified 'key'. For that purpose, the 'compare' * function is used. It should return 0 iff the two arguments compare equal. * * Returns: - * - a pointer the sc_object_t containing the matching entry + * - a pointer the sdb_object_t containing the matching entry * - NULL else */ -sc_object_t * -sc_llist_search(sc_llist_t *list, const sc_object_t *key, - int (*compare)(const sc_object_t *, const sc_object_t *)); +sdb_object_t * +sdb_llist_search(sdb_llist_t *list, const sdb_object_t *key, + int (*compare)(const sdb_object_t *, const sdb_object_t *)); /* - * sc_llist_shift: + * sdb_llist_shift: * Removes and returns the first element of the list. The ref-count of the * item will not be changed, that is, if the element will not be used any * further, it should be re-referenced by the caller. @@ -139,29 +139,29 @@ sc_llist_search(sc_llist_t *list, const sc_object_t *key, * - the former first element of the list * - NULL if the list is empty */ -sc_object_t * -sc_llist_shift(sc_llist_t *list); +sdb_object_t * +sdb_llist_shift(sdb_llist_t *list); -/* sc_llist_get_iter, sc_llist_iter_has_next, sc_llist_iter_get_next: +/* sdb_llist_get_iter, sdb_llist_iter_has_next, sdb_llist_iter_get_next: * Iterate through the list, element by element. * - * sc_llist_iter_get_next returns NULL if there is no next element. + * sdb_llist_iter_get_next returns NULL if there is no next element. */ -sc_llist_iter_t * -sc_llist_get_iter(sc_llist_t *list); +sdb_llist_iter_t * +sdb_llist_get_iter(sdb_llist_t *list); void -sc_llist_iter_destroy(sc_llist_iter_t *iter); +sdb_llist_iter_destroy(sdb_llist_iter_t *iter); _Bool -sc_llist_iter_has_next(sc_llist_iter_t *iter); -sc_object_t * -sc_llist_iter_get_next(sc_llist_iter_t *iter); +sdb_llist_iter_has_next(sdb_llist_iter_t *iter); +sdb_object_t * +sdb_llist_iter_get_next(sdb_llist_iter_t *iter); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_UTILS_LLIST_H */ +#endif /* ! SDB_UTILS_LLIST_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/utils/string.h b/src/include/utils/string.h index a52205b..7f0a7a3 100644 --- a/src/include/utils/string.h +++ b/src/include/utils/string.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/utils/string.h + * SysDB - src/include/utils/string.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,8 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_UTILS_STRING_H -#define SC_UTILS_STRING_H 1 +#ifndef SDB_UTILS_STRING_H +#define SDB_UTILS_STRING_H 1 #include @@ -35,13 +35,13 @@ extern "C" { #endif char * -sc_strerror(int errnum, char *strerrbuf, size_t buflen); +sdb_strerror(int errnum, char *strerrbuf, size_t buflen); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_UTILS_STRING_H */ +#endif /* ! SDB_UTILS_STRING_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/utils/time.h b/src/include/utils/time.h index f67a46b..cd781e3 100644 --- a/src/include/utils/time.h +++ b/src/include/utils/time.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/utils/time.h + * SysDB - src/include/utils/time.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,8 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_UTILS_TIME_H -#define SC_UTILS_TIME_H 1 +#ifndef SDB_UTILS_TIME_H +#define SDB_UTILS_TIME_H 1 #include #include @@ -37,37 +37,37 @@ extern "C" { #endif /* - * sc_time_t: + * sdb_time_t: * The time, in nano-seconds, since the epoch. */ -typedef uint64_t sc_time_t; +typedef uint64_t sdb_time_t; #define PRIscTIME PRIu64 -#define SECS_TO_SC_TIME(s) ((sc_time_t)(s) * (sc_time_t)1000000000) -#define SC_TIME_TO_SECS(t) ((t) / (sc_time_t)1000000000) +#define SECS_TO_SDB_TIME(s) ((sdb_time_t)(s) * (sdb_time_t)1000000000) +#define SDB_TIME_TO_SECS(t) ((t) / (sdb_time_t)1000000000) -#define NSECS_TO_SC_TIME(ns) ((sc_time_t)ns) +#define NSECS_TO_SDB_TIME(ns) ((sdb_time_t)ns) -#define DOUBLE_TO_SC_TIME(d) ((sc_time_t)((d) * 1000000000.0)) -#define SC_TIME_TO_DOUBLE(t) ((double)(t) / 1000000000.0) +#define DOUBLE_TO_SDB_TIME(d) ((sdb_time_t)((d) * 1000000000.0)) +#define SDB_TIME_TO_DOUBLE(t) ((double)(t) / 1000000000.0) -#define TIMESPEC_TO_SC_TIME(ts) (SECS_TO_SC_TIME((ts).tv_sec) \ - + NSECS_TO_SC_TIME((ts).tv_nsec)) +#define TIMESPEC_TO_SDB_TIME(ts) (SECS_TO_SDB_TIME((ts).tv_sec) \ + + NSECS_TO_SDB_TIME((ts).tv_nsec)) -sc_time_t -sc_gettime(void); +sdb_time_t +sdb_gettime(void); int -sc_sleep(sc_time_t reg, sc_time_t *rem); +sdb_sleep(sdb_time_t reg, sdb_time_t *rem); size_t -sc_strftime(char *s, size_t len, const char *format, sc_time_t); +sdb_strftime(char *s, size_t len, const char *format, sdb_time_t); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_UTILS_TIME_H */ +#endif /* ! SDB_UTILS_TIME_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/utils/unixsock.h b/src/include/utils/unixsock.h index 31a423e..3a38aca 100644 --- a/src/include/utils/unixsock.h +++ b/src/include/utils/unixsock.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/utils/unixsock.h + * SysDB - src/include/utils/unixsock.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,8 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_UTILS_UNIXSOCK_H -#define SC_UTILS_UNIXSOCK_H 1 +#ifndef SDB_UTILS_UNIXSOCK_H +#define SDB_UTILS_UNIXSOCK_H 1 #include "core/object.h" #include "utils/data.h" @@ -39,46 +39,48 @@ extern "C" { #endif -struct sc_unixsock_client; -typedef struct sc_unixsock_client sc_unixsock_client_t; +struct sdb_unixsock_client; +typedef struct sdb_unixsock_client sdb_unixsock_client_t; -typedef int (*sc_unixsock_client_data_cb)(sc_unixsock_client_t *, - size_t, sc_data_t *, sc_object_t *); +typedef int (*sdb_unixsock_client_data_cb)(sdb_unixsock_client_t *, + size_t, sdb_data_t *, sdb_object_t *); -sc_unixsock_client_t * -sc_unixsock_client_create(const char *path); +sdb_unixsock_client_t * +sdb_unixsock_client_create(const char *path); int -sc_unixsock_client_connect(sc_unixsock_client_t *client); +sdb_unixsock_client_connect(sdb_unixsock_client_t *client); int -sc_unixsock_client_send(sc_unixsock_client_t *client, const char *msg); +sdb_unixsock_client_send(sdb_unixsock_client_t *client, + const char *msg); char * -sc_unixsock_client_recv(sc_unixsock_client_t *client, char *buffer, size_t buflen); +sdb_unixsock_client_recv(sdb_unixsock_client_t *client, + char *buffer, size_t buflen); /* - * sc_unixsock_client_process_lines: + * sdb_unixsock_client_process_lines: * Reads up to 'max_lines' lines from the socket, splits each line at the * specified 'delim' and passes the data on to the specified 'callback'. If * 'max_lines' is less than zero, the function will read until EOF or an error * is encountered. If 'n_cols' is greater than zero, the function will expect * that number of columns to appear in each line. Also, it will expect that * number of further arguments, specifying the data-type to be returned for - * the respective column (see sc_data_t). The content of each column will then - * be converted accordingly. + * the respective column (see sdb_data_t). The content of each column will + * then be converted accordingly. * * Returns: * - 0 on success * - a negative value else */ int -sc_unixsock_client_process_lines(sc_unixsock_client_t *client, - sc_unixsock_client_data_cb callback, sc_object_t *user_data, +sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client, + sdb_unixsock_client_data_cb callback, sdb_object_t *user_data, long int max_lines, const char *delim, int n_cols, ...); /* - * sc_unixsock_client_shutdown: + * sdb_unixsock_client_shutdown: * Shut down the client's send and/or receive operations. If appropriate, the * client will automatically re-connect on the next send / receive operation * after that. @@ -86,32 +88,32 @@ sc_unixsock_client_process_lines(sc_unixsock_client_t *client, * See shutdown(3) for details. */ int -sc_unixsock_client_shutdown(sc_unixsock_client_t *client, int how); +sdb_unixsock_client_shutdown(sdb_unixsock_client_t *client, int how); /* - * sc_unixsock_client_clearerr, sc_unixsock_client_eof, - * sc_unixsock_client_error: + * sdb_unixsock_client_clearerr, sdb_unixsock_client_eof, + * sdb_unixsock_client_error: * Check and reset the client status. See the clearerr(3), feof(3), and * ferror(3) manpages for details. */ void -sc_unixsock_client_clearerr(sc_unixsock_client_t *client); +sdb_unixsock_client_clearerr(sdb_unixsock_client_t *client); int -sc_unixsock_client_eof(sc_unixsock_client_t *client); +sdb_unixsock_client_eof(sdb_unixsock_client_t *client); int -sc_unixsock_client_error(sc_unixsock_client_t *client); +sdb_unixsock_client_error(sdb_unixsock_client_t *client); void -sc_unixsock_client_destroy(sc_unixsock_client_t *client); +sdb_unixsock_client_destroy(sdb_unixsock_client_t *client); const char * -sc_unixsock_client_path(sc_unixsock_client_t *client); +sdb_unixsock_client_path(sdb_unixsock_client_t *client); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_UTILS_UNIXSOCK_H */ +#endif /* ! SDB_UTILS_UNIXSOCK_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/syscollector.c b/src/syscollector.c deleted file mode 100644 index b07cf54..0000000 --- a/src/syscollector.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * syscollector - src/syscollector.c - * Copyright (C) 2012 Sebastian 'tokkee' Harl - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "syscollector.h" - -/* - * public API - */ - -unsigned int -sc_version(void) -{ - return SC_VERSION; -} /* sc_version */ - -const char * -sc_version_string(void) -{ - return SC_VERSION_STRING; -} /* sc_version_string */ - -const char * -sc_version_extra(void) -{ - return SC_VERSION_EXTRA; -} /* sc_version_extra */ - -/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ - diff --git a/src/sysdb.c b/src/sysdb.c new file mode 100644 index 0000000..a644acb --- /dev/null +++ b/src/sysdb.c @@ -0,0 +1,53 @@ +/* + * SysDB - src/sysdb.c + * Copyright (C) 2012 Sebastian 'tokkee' Harl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sysdb.h" + +/* + * public API + */ + +unsigned int +sdb_version(void) +{ + return SDB_VERSION; +} /* sdb_version */ + +const char * +sdb_version_string(void) +{ + return SDB_VERSION_STRING; +} /* sdb_version_string */ + +const char * +sdb_version_extra(void) +{ + return SDB_VERSION_EXTRA; +} /* sdb_version_extra */ + +/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ + diff --git a/src/utils/dbi.c b/src/utils/dbi.c index d7398de..ee2280c 100644 --- a/src/utils/dbi.c +++ b/src/utils/dbi.c @@ -1,5 +1,5 @@ /* - * syscollector - src/utils/dbi.c + * SysDB - src/utils/dbi.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -43,20 +43,20 @@ typedef struct { char *key; char *value; -} sc_dbi_option_t; +} sdb_dbi_option_t; -struct sc_dbi_options { - sc_dbi_option_t *options; +struct sdb_dbi_options { + sdb_dbi_option_t *options; size_t options_num; }; -struct sc_dbi_client { +struct sdb_dbi_client { char *driver; char *database; dbi_conn conn; - sc_dbi_options_t *options; + sdb_dbi_options_t *options; }; /* @@ -64,35 +64,35 @@ struct sc_dbi_client { */ static const char * -sc_dbi_strerror(dbi_conn conn) +sdb_dbi_strerror(dbi_conn conn) { const char *errmsg = NULL; dbi_conn_error(conn, &errmsg); return errmsg; -} /* sc_dbi_strerror */ +} /* sdb_dbi_strerror */ static int -sc_dbi_get_field(dbi_result res, unsigned int i, - int type, sc_data_t *data) +sdb_dbi_get_field(dbi_result res, unsigned int i, + int type, sdb_data_t *data) { switch (type) { - case SC_TYPE_INTEGER: + case SDB_TYPE_INTEGER: data->data.integer = dbi_result_get_longlong_idx(res, i); break; - case SC_TYPE_DECIMAL: + case SDB_TYPE_DECIMAL: data->data.decimal = dbi_result_get_double_idx(res, i); break; - case SC_TYPE_STRING: + case SDB_TYPE_STRING: data->data.string = dbi_result_get_string_idx(res, i); break; - case SC_TYPE_DATETIME: + case SDB_TYPE_DATETIME: { /* libdbi does not provide any higher resolutions than that */ time_t datetime = dbi_result_get_datetime_idx(res, i); - data->data.datetime = SECS_TO_SC_TIME(datetime); + data->data.datetime = SECS_TO_SDB_TIME(datetime); } break; - case SC_TYPE_BINARY: + case SDB_TYPE_BINARY: { size_t length = dbi_result_get_field_length_idx(res, i); const unsigned char *datum = dbi_result_get_binary_idx(res, i); @@ -108,14 +108,14 @@ sc_dbi_get_field(dbi_result res, unsigned int i, data->type = type; return 0; -} /* sc_dbi_get_field */ +} /* sdb_dbi_get_field */ static int -sc_dbi_get_data(sc_dbi_client_t *client, dbi_result res, - unsigned int num_fields, sc_dbi_data_cb callback, - sc_object_t *user_data) +sdb_dbi_get_data(sdb_dbi_client_t *client, dbi_result res, + unsigned int num_fields, sdb_dbi_data_cb callback, + sdb_object_t *user_data) { - sc_data_t data[num_fields]; + sdb_data_t data[num_fields]; int types[num_fields]; unsigned int i; @@ -129,7 +129,7 @@ sc_dbi_get_data(sc_dbi_client_t *client, dbi_result res, types[i] = dbi_result_get_field_type_idx(res, i + 1); if (types[i] == DBI_TYPE_ERROR) { fprintf(stderr, "dbi: failed to fetch data: %s\n", - sc_dbi_strerror(client->conn)); + sdb_dbi_strerror(client->conn)); return -1; } types[i] = DBI_TYPE_TO_SC(types[i]); @@ -142,12 +142,12 @@ sc_dbi_get_data(sc_dbi_client_t *client, dbi_result res, for (n = 0; n < num_rows; ++n) { if (! dbi_result_seek_row(res, n + 1)) { fprintf(stderr, "dbi: Failed to retrieve row %llu: %s\n", - n, sc_dbi_strerror(client->conn)); + n, sdb_dbi_strerror(client->conn)); continue; } for (i = 0; i < num_fields; ++i) - if (sc_dbi_get_field(res, (unsigned int)(i + 1), + if (sdb_dbi_get_field(res, (unsigned int)(i + 1), types[i], &data[i])) continue; @@ -160,16 +160,16 @@ sc_dbi_get_data(sc_dbi_client_t *client, dbi_result res, if (! success) return -1; return 0; -} /* sc_dbi_get_data */ +} /* sdb_dbi_get_data */ /* * public API */ -sc_dbi_options_t * -sc_dbi_options_create(void) +sdb_dbi_options_t * +sdb_dbi_options_create(void) { - sc_dbi_options_t *options; + sdb_dbi_options_t *options; options = malloc(sizeof(options)); if (! options) @@ -178,13 +178,13 @@ sc_dbi_options_create(void) options->options = NULL; options->options_num = 0; return options; -} /* sc_dbi_options_create */ +} /* sdb_dbi_options_create */ int -sc_dbi_options_add(sc_dbi_options_t *options, +sdb_dbi_options_add(sdb_dbi_options_t *options, const char *key, const char *value) { - sc_dbi_option_t *new; + sdb_dbi_option_t *new; if ((! options) || (! key) || (! value)) return -1; @@ -210,10 +210,10 @@ sc_dbi_options_add(sc_dbi_options_t *options, ++options->options_num; return 0; -} /* sc_dbi_options_add */ +} /* sdb_dbi_options_add */ void -sc_dbi_options_destroy(sc_dbi_options_t *options) +sdb_dbi_options_destroy(sdb_dbi_options_t *options) { size_t i; @@ -221,7 +221,7 @@ sc_dbi_options_destroy(sc_dbi_options_t *options) return; for (i = 0; i < options->options_num; ++i) { - sc_dbi_option_t *opt = options->options + i; + sdb_dbi_option_t *opt = options->options + i; if (opt->key) free(opt->key); @@ -234,12 +234,12 @@ sc_dbi_options_destroy(sc_dbi_options_t *options) options->options = NULL; options->options_num = 0; free(options); -} /* sc_dbi_options_destroy */ +} /* sdb_dbi_options_destroy */ -sc_dbi_client_t * -sc_dbi_client_create(const char *driver, const char *database) +sdb_dbi_client_t * +sdb_dbi_client_create(const char *driver, const char *database) { - sc_dbi_client_t *client; + sdb_dbi_client_t *client; if ((! driver) || (! database)) return NULL; @@ -255,27 +255,27 @@ sc_dbi_client_create(const char *driver, const char *database) client->driver = strdup(driver); client->database = strdup(database); if ((! client->driver) || (! client->database)) { - sc_dbi_client_destroy(client); + sdb_dbi_client_destroy(client); return NULL; } return client; -} /* sc_dbi_client_create */ +} /* sdb_dbi_client_create */ int -sc_dbi_client_set_options(sc_dbi_client_t *client, - sc_dbi_options_t *options) +sdb_dbi_client_set_options(sdb_dbi_client_t *client, + sdb_dbi_options_t *options) { if (! client) return -1; if (client->options) - sc_dbi_options_destroy(client->options); + sdb_dbi_options_destroy(client->options); client->options = options; return 0; -} /* sc_dbi_client_set_options */ +} /* sdb_dbi_client_set_options */ int -sc_dbi_client_connect(sc_dbi_client_t *client) +sdb_dbi_client_connect(sdb_dbi_client_t *client) { dbi_driver driver; size_t i; @@ -318,7 +318,7 @@ sc_dbi_client_connect(sc_dbi_client_t *client) fprintf(stderr, "dbi: failed to set option '%s': %s\n", client->options->options[i].key, - sc_dbi_strerror(client->conn)); + sdb_dbi_strerror(client->conn)); fprintf(stderr, "dbi: known driver options:\n"); for (opt = dbi_conn_get_option_list(client->conn, NULL); opt; @@ -332,23 +332,23 @@ sc_dbi_client_connect(sc_dbi_client_t *client) if (dbi_conn_set_option(client->conn, "dbname", client->database)) { fprintf(stderr, "dbi: failed to set option 'dbname': %s\n", - sc_dbi_strerror(client->conn)); + sdb_dbi_strerror(client->conn)); dbi_conn_close(client->conn); return -1; } if (dbi_conn_connect(client->conn) < 0) { fprintf(stderr, "dbi: failed to connect to database '%s': %s\n", - client->database, sc_dbi_strerror(client->conn)); + client->database, sdb_dbi_strerror(client->conn)); dbi_conn_close(client->conn); return -1; } return 0; -} /* sc_dbi_client_connect */ +} /* sdb_dbi_client_connect */ int -sc_dbi_exec_query(sc_dbi_client_t *client, const char *query, - sc_dbi_data_cb callback, sc_object_t *user_data, int n, ...) +sdb_dbi_exec_query(sdb_dbi_client_t *client, const char *query, + sdb_dbi_data_cb callback, sdb_object_t *user_data, int n, ...) { dbi_result res; unsigned int num_fields; @@ -361,13 +361,13 @@ sc_dbi_exec_query(sc_dbi_client_t *client, const char *query, res = dbi_conn_query(client->conn, query); if (! res) { fprintf(stderr, "dbi: failed to execute query '%s': %s\n", - query, sc_dbi_strerror(client->conn)); + query, sdb_dbi_strerror(client->conn)); return -1; } if (dbi_result_get_numrows(res) == DBI_ROW_ERROR) { fprintf(stderr, "dbi: failed to fetch rows for query '%s': %s\n", - query, sc_dbi_strerror(client->conn)); + query, sdb_dbi_strerror(client->conn)); dbi_result_free(res); return -1; } @@ -425,14 +425,14 @@ sc_dbi_exec_query(sc_dbi_client_t *client, const char *query, return 0; } - status = sc_dbi_get_data(client, res, num_fields, callback, user_data); + status = sdb_dbi_get_data(client, res, num_fields, callback, user_data); dbi_result_free(res); return status; -} /* sc_dbi_exec_query */ +} /* sdb_dbi_exec_query */ void -sc_dbi_client_destroy(sc_dbi_client_t *client) +sdb_dbi_client_destroy(sdb_dbi_client_t *client) { if (! client) return; @@ -449,11 +449,11 @@ sc_dbi_client_destroy(sc_dbi_client_t *client) dbi_conn_close(client->conn); if (client->options) - sc_dbi_options_destroy(client->options); + sdb_dbi_options_destroy(client->options); client->options = NULL; free(client); -} /* sc_dbi_client_destroy */ +} /* sdb_dbi_client_destroy */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/utils/llist.c b/src/utils/llist.c index 765743f..e853001 100644 --- a/src/utils/llist.c +++ b/src/utils/llist.c @@ -1,5 +1,5 @@ /* - * syscollector - src/utils/llist.c + * SysDB - src/utils/llist.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -36,28 +36,28 @@ * private data types */ -struct sc_llist_elem; -typedef struct sc_llist_elem sc_llist_elem_t; +struct sdb_llist_elem; +typedef struct sdb_llist_elem sdb_llist_elem_t; -struct sc_llist_elem { - sc_object_t *obj; +struct sdb_llist_elem { + sdb_object_t *obj; - sc_llist_elem_t *next; - sc_llist_elem_t *prev; + sdb_llist_elem_t *next; + sdb_llist_elem_t *prev; }; -struct sc_llist { +struct sdb_llist { pthread_rwlock_t lock; - sc_llist_elem_t *head; - sc_llist_elem_t *tail; + sdb_llist_elem_t *head; + sdb_llist_elem_t *tail; size_t length; }; -struct sc_llist_iter { - sc_llist_t *list; - sc_llist_elem_t *elem; +struct sdb_llist_iter { + sdb_llist_t *list; + sdb_llist_elem_t *elem; }; /* @@ -67,10 +67,10 @@ struct sc_llist_iter { /* Insert a new element after 'elem'. If 'elem' is NULL, insert at the head of * the list. */ static int -sc_llist_insert_after(sc_llist_t *list, sc_llist_elem_t *elem, - sc_object_t *obj) +sdb_llist_insert_after(sdb_llist_t *list, sdb_llist_elem_t *elem, + sdb_object_t *obj) { - sc_llist_elem_t *new; + sdb_llist_elem_t *new; assert(list); @@ -109,15 +109,15 @@ sc_llist_insert_after(sc_llist_t *list, sc_llist_elem_t *elem, assert(list->head == list->tail); } - sc_object_ref(obj); + sdb_object_ref(obj); ++list->length; return 0; -} /* sc_llist_insert_after */ +} /* sdb_llist_insert_after */ -static sc_object_t * -sc_llist_remove_elem(sc_llist_t *list, sc_llist_elem_t *elem) +static sdb_object_t * +sdb_llist_remove_elem(sdb_llist_t *list, sdb_llist_elem_t *elem) { - sc_object_t *obj; + sdb_object_t *obj; assert(list && elem); @@ -142,16 +142,16 @@ sc_llist_remove_elem(sc_llist_t *list, sc_llist_elem_t *elem) --list->length; return obj; -} /* sc_llist_remove_elem */ +} /* sdb_llist_remove_elem */ /* * public API */ -sc_llist_t * -sc_llist_create(void) +sdb_llist_t * +sdb_llist_create(void) { - sc_llist_t *list; + sdb_llist_t *list; list = malloc(sizeof(*list)); if (! list) @@ -162,18 +162,18 @@ sc_llist_create(void) list->head = list->tail = NULL; list->length = 0; return list; -} /* sc_llist_create */ +} /* sdb_llist_create */ -sc_llist_t * -sc_llist_clone(sc_llist_t *list) +sdb_llist_t * +sdb_llist_clone(sdb_llist_t *list) { - sc_llist_t *clone; - sc_llist_elem_t *elem; + sdb_llist_t *clone; + sdb_llist_elem_t *elem; if (! list) return NULL; - clone = sc_llist_create(); + clone = sdb_llist_create(); if (! clone) return NULL; @@ -183,18 +183,18 @@ sc_llist_clone(sc_llist_t *list) } for (elem = list->head; elem; elem = elem->next) { - if (sc_llist_append(clone, elem->obj)) { - sc_llist_destroy(clone); + if (sdb_llist_append(clone, elem->obj)) { + sdb_llist_destroy(clone); return NULL; } } return clone; -} /* sc_llist_clone */ +} /* sdb_llist_clone */ void -sc_llist_destroy(sc_llist_t *list) +sdb_llist_destroy(sdb_llist_t *list) { - sc_llist_elem_t *elem; + sdb_llist_elem_t *elem; if (! list) return; @@ -203,9 +203,9 @@ sc_llist_destroy(sc_llist_t *list) elem = list->head; while (elem) { - sc_llist_elem_t *tmp = elem->next; + sdb_llist_elem_t *tmp = elem->next; - sc_object_deref(elem->obj); + sdb_object_deref(elem->obj); free(elem); elem = tmp; @@ -217,10 +217,10 @@ sc_llist_destroy(sc_llist_t *list) pthread_rwlock_unlock(&list->lock); pthread_rwlock_destroy(&list->lock); free(list); -} /* sc_llist_destroy */ +} /* sdb_llist_destroy */ int -sc_llist_append(sc_llist_t *list, sc_object_t *obj) +sdb_llist_append(sdb_llist_t *list, sdb_object_t *obj) { int status; @@ -228,16 +228,16 @@ sc_llist_append(sc_llist_t *list, sc_object_t *obj) return -1; pthread_rwlock_wrlock(&list->lock); - status = sc_llist_insert_after(list, list->tail, obj); + status = sdb_llist_insert_after(list, list->tail, obj); pthread_rwlock_unlock(&list->lock); return status; -} /* sc_llist_append */ +} /* sdb_llist_append */ int -sc_llist_insert(sc_llist_t *list, sc_object_t *obj, size_t index) +sdb_llist_insert(sdb_llist_t *list, sdb_object_t *obj, size_t index) { - sc_llist_elem_t *prev; - sc_llist_elem_t *next; + sdb_llist_elem_t *prev; + sdb_llist_elem_t *next; int status; @@ -255,17 +255,17 @@ sc_llist_insert(sc_llist_t *list, sc_object_t *obj, size_t index) prev = next; next = next->next; } - status = sc_llist_insert_after(list, prev, obj); + status = sdb_llist_insert_after(list, prev, obj); pthread_rwlock_unlock(&list->lock); return status; -} /* sc_llist_insert */ +} /* sdb_llist_insert */ int -sc_llist_insert_sorted(sc_llist_t *list, sc_object_t *obj, - int (*compare)(const sc_object_t *, const sc_object_t *)) +sdb_llist_insert_sorted(sdb_llist_t *list, sdb_object_t *obj, + int (*compare)(const sdb_object_t *, const sdb_object_t *)) { - sc_llist_elem_t *prev; - sc_llist_elem_t *next; + sdb_llist_elem_t *prev; + sdb_llist_elem_t *next; int status; @@ -284,16 +284,16 @@ sc_llist_insert_sorted(sc_llist_t *list, sc_object_t *obj, prev = next; next = next->next; } - status = sc_llist_insert_after(list, prev, obj); + status = sdb_llist_insert_after(list, prev, obj); pthread_rwlock_unlock(&list->lock); return status; -} /* sc_llist_insert_sorted */ +} /* sdb_llist_insert_sorted */ -sc_object_t * -sc_llist_search(sc_llist_t *list, const sc_object_t *key, - int (*compare)(const sc_object_t *, const sc_object_t *)) +sdb_object_t * +sdb_llist_search(sdb_llist_t *list, const sdb_object_t *key, + int (*compare)(const sdb_object_t *, const sdb_object_t *)) { - sc_llist_elem_t *elem; + sdb_llist_elem_t *elem; if ((! list) || (! compare)) return NULL; @@ -309,26 +309,26 @@ sc_llist_search(sc_llist_t *list, const sc_object_t *key, if (elem) return elem->obj; return NULL; -} /* sc_llist_search */ +} /* sdb_llist_search */ -sc_object_t * -sc_llist_shift(sc_llist_t *list) +sdb_object_t * +sdb_llist_shift(sdb_llist_t *list) { - sc_object_t *obj; + sdb_object_t *obj; if ((! list) || (! list->head)) return NULL; pthread_rwlock_wrlock(&list->lock); - obj = sc_llist_remove_elem(list, list->head); + obj = sdb_llist_remove_elem(list, list->head); pthread_rwlock_unlock(&list->lock); return obj; -} /* sc_llist_shift */ +} /* sdb_llist_shift */ -sc_llist_iter_t * -sc_llist_get_iter(sc_llist_t *list) +sdb_llist_iter_t * +sdb_llist_get_iter(sdb_llist_t *list) { - sc_llist_iter_t *iter; + sdb_llist_iter_t *iter; if (! list) return NULL; @@ -345,10 +345,10 @@ sc_llist_get_iter(sc_llist_t *list) /* XXX: keep lock until destroying the iterator? */ pthread_rwlock_unlock(&list->lock); return iter; -} /* sc_llist_get_iter */ +} /* sdb_llist_get_iter */ void -sc_llist_iter_destroy(sc_llist_iter_t *iter) +sdb_llist_iter_destroy(sdb_llist_iter_t *iter) { if (! iter) return; @@ -356,20 +356,20 @@ sc_llist_iter_destroy(sc_llist_iter_t *iter) iter->list = NULL; iter->elem = NULL; free(iter); -} /* sc_llist_iter_destroy */ +} /* sdb_llist_iter_destroy */ _Bool -sc_llist_iter_has_next(sc_llist_iter_t *iter) +sdb_llist_iter_has_next(sdb_llist_iter_t *iter) { if (! iter) return 0; return iter->elem != NULL; -} /* sc_llist_iter_has_next */ +} /* sdb_llist_iter_has_next */ -sc_object_t * -sc_llist_iter_get_next(sc_llist_iter_t *iter) +sdb_object_t * +sdb_llist_iter_get_next(sdb_llist_iter_t *iter) { - sc_object_t *obj; + sdb_object_t *obj; if ((! iter) || (! iter->elem)) return NULL; @@ -381,7 +381,7 @@ sc_llist_iter_get_next(sc_llist_iter_t *iter) pthread_rwlock_unlock(&iter->list->lock); return obj; -} /* sc_llist_iter_get_next */ +} /* sdb_llist_iter_get_next */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/utils/string.c b/src/utils/string.c index 25d3e9e..4fa9def 100644 --- a/src/utils/string.c +++ b/src/utils/string.c @@ -1,5 +1,5 @@ /* - * syscollector - src/utils/string.c + * SysDB - src/utils/string.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -35,7 +35,7 @@ */ char * -sc_strerror(int errnum, char *strerrbuf, size_t buflen) +sdb_strerror(int errnum, char *strerrbuf, size_t buflen) { #if STRERROR_R_CHAR_P { @@ -57,7 +57,7 @@ sc_strerror(int errnum, char *strerrbuf, size_t buflen) strerrbuf[buflen - 1] = '\0'; return strerrbuf; -} /* sc_strerror */ +} /* sdb_strerror */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/utils/time.c b/src/utils/time.c index d3192c3..e3aa5c1 100644 --- a/src/utils/time.c +++ b/src/utils/time.c @@ -1,5 +1,5 @@ /* - * syscollector - src/utils/time.c + * SysDB - src/utils/time.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -36,45 +36,45 @@ * public API */ -sc_time_t -sc_gettime(void) +sdb_time_t +sdb_gettime(void) { struct timespec ts_now = { 0, 0 }; if (clock_gettime(CLOCK_REALTIME, &ts_now)) return 0; - return TIMESPEC_TO_SC_TIME(ts_now); -} /* sc_gettime */ + return TIMESPEC_TO_SDB_TIME(ts_now); +} /* sdb_gettime */ int -sc_sleep(sc_time_t reg, sc_time_t *rem) +sdb_sleep(sdb_time_t reg, sdb_time_t *rem) { struct timespec ts_reg, ts_rem = { 0, 0 }; int status; - ts_reg.tv_sec = (time_t)SC_TIME_TO_SECS(reg); - ts_reg.tv_nsec = (long int)(reg % (sc_time_t)1000000000); + ts_reg.tv_sec = (time_t)SDB_TIME_TO_SECS(reg); + ts_reg.tv_nsec = (long int)(reg % (sdb_time_t)1000000000); status = nanosleep(&ts_reg, &ts_rem); if (rem) - *rem = TIMESPEC_TO_SC_TIME(ts_rem); + *rem = TIMESPEC_TO_SDB_TIME(ts_rem); return status; -} /* sc_sleep */ +} /* sdb_sleep */ size_t -sc_strftime(char *s, size_t len, const char *format, sc_time_t t) +sdb_strftime(char *s, size_t len, const char *format, sdb_time_t t) { time_t tstamp; struct tm tm; memset(&tm, 0, sizeof(tm)); - tstamp = (time_t)SC_TIME_TO_SECS(t); + tstamp = (time_t)SDB_TIME_TO_SECS(t); if (! localtime_r (&tstamp, &tm)) return 0; return strftime(s, len, format, &tm); -} /* sc_strftime */ +} /* sdb_strftime */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c index da2ca1e..564aba7 100644 --- a/src/utils/unixsock.c +++ b/src/utils/unixsock.c @@ -1,5 +1,5 @@ /* - * syscollector - src/utils/unixsock.c + * SysDB - src/utils/unixsock.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -47,23 +47,23 @@ * private data types */ -struct sc_unixsock_client { +struct sdb_unixsock_client { char *path; FILE *fh; int shutdown; }; -#define SC_SHUT_RD (1 << SHUT_RD) -#define SC_SHUT_WR (1 << SHUT_WR) -#define SC_SHUT_RDWR (SC_SHUT_RD | SC_SHUT_WR) +#define SDB_SHUT_RD (1 << SHUT_RD) +#define SDB_SHUT_WR (1 << SHUT_WR) +#define SDB_SHUT_RDWR (SDB_SHUT_RD | SDB_SHUT_WR) /* * private helper functions */ static int -sc_unixsock_get_column_count(const char *string, const char *delim) +sdb_unixsock_get_column_count(const char *string, const char *delim) { int count = 1; @@ -85,32 +85,32 @@ sc_unixsock_get_column_count(const char *string, const char *delim) } } return count; -} /* sc_unixsock_get_column_count */ +} /* sdb_unixsock_get_column_count */ static int -sc_unixsock_parse_cell(char *string, int type, sc_data_t *data) +sdb_unixsock_parse_cell(char *string, int type, sdb_data_t *data) { char *endptr = NULL; switch (type) { - case SC_TYPE_INTEGER: + case SDB_TYPE_INTEGER: errno = 0; data->data.integer = strtoll(string, &endptr, 0); break; - case SC_TYPE_DECIMAL: + case SDB_TYPE_DECIMAL: errno = 0; data->data.decimal = strtod(string, &endptr); break; - case SC_TYPE_STRING: + case SDB_TYPE_STRING: data->data.string = string; break; - case SC_TYPE_DATETIME: + case SDB_TYPE_DATETIME: { double datetime = strtod(string, &endptr); - data->data.datetime = DOUBLE_TO_SC_TIME(datetime); + data->data.datetime = DOUBLE_TO_SDB_TIME(datetime); } break; - case SC_TYPE_BINARY: + case SDB_TYPE_BINARY: /* we don't support any binary information containing 0-bytes */ data->data.binary.length = strlen(string); data->data.binary.datum = (const unsigned char *)string; @@ -121,13 +121,13 @@ sc_unixsock_parse_cell(char *string, int type, sc_data_t *data) return -1; } - if ((type == SC_TYPE_INTEGER) || (type == SC_TYPE_DECIMAL) - || (type == SC_TYPE_DATETIME)) { + if ((type == SDB_TYPE_INTEGER) || (type == SDB_TYPE_DECIMAL) + || (type == SDB_TYPE_DATETIME)) { if (errno || (string == endptr)) { char errbuf[1024]; fprintf(stderr, "unixsock: Failed to parse string '%s' " "as numeric value (type %i): %s\n", string, type, - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } else if (endptr && (*endptr != '\0')) @@ -138,15 +138,15 @@ sc_unixsock_parse_cell(char *string, int type, sc_data_t *data) data->type = type; return 0; -} /* sc_unixsock_parse_cell */ +} /* sdb_unixsock_parse_cell */ static int -sc_unixsock_client_process_one_line(sc_unixsock_client_t *client, - char *line, sc_unixsock_client_data_cb callback, - sc_object_t *user_data, const char *delim, +sdb_unixsock_client_process_one_line(sdb_unixsock_client_t *client, + char *line, sdb_unixsock_client_data_cb callback, + sdb_object_t *user_data, const char *delim, int column_count, int *types) { - sc_data_t data[column_count]; + sdb_data_t data[column_count]; char *orig_line = line; int i; @@ -173,8 +173,8 @@ sc_unixsock_client_process_one_line(sc_unixsock_client_t *client, ++next; } - if (sc_unixsock_parse_cell(line, - types ? types[i] : SC_TYPE_STRING, &data[i])) + if (sdb_unixsock_parse_cell(line, + types ? types[i] : SDB_TYPE_STRING, &data[i])) return -1; line = next; @@ -183,16 +183,16 @@ sc_unixsock_client_process_one_line(sc_unixsock_client_t *client, if (callback(client, (size_t)column_count, data, user_data)) return -1; return 0; -} /* sc_unixsock_client_process_one_line */ +} /* sdb_unixsock_client_process_one_line */ /* * public API */ -sc_unixsock_client_t * -sc_unixsock_client_create(const char *path) +sdb_unixsock_client_t * +sdb_unixsock_client_create(const char *path) { - sc_unixsock_client_t *client; + sdb_unixsock_client_t *client; if (! path) return NULL; @@ -205,16 +205,16 @@ sc_unixsock_client_create(const char *path) client->path = strdup(path); if (! client->path) { - sc_unixsock_client_destroy(client); + sdb_unixsock_client_destroy(client); return NULL; } client->shutdown = 0; return client; -} /* sc_unixsock_client_create */ +} /* sdb_unixsock_client_create */ int -sc_unixsock_client_connect(sc_unixsock_client_t *client) +sdb_unixsock_client_connect(sdb_unixsock_client_t *client) { struct sockaddr_un sa; int fd; @@ -231,7 +231,7 @@ sc_unixsock_client_connect(sc_unixsock_client_t *client) if (fd < 0) { char errbuf[1024]; fprintf(stderr, "unixsock: Failed to open socket: %s\n", - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } @@ -242,7 +242,7 @@ sc_unixsock_client_connect(sc_unixsock_client_t *client) if (connect(fd, (struct sockaddr *)&sa, sizeof(sa))) { char errbuf[1024]; fprintf(stderr, "unixsock: Failed to connect to %s: %s\n", - sa.sun_path, sc_strerror(errno, errbuf, sizeof(errbuf))); + sa.sun_path, sdb_strerror(errno, errbuf, sizeof(errbuf))); close(fd); return -1; } @@ -251,51 +251,53 @@ sc_unixsock_client_connect(sc_unixsock_client_t *client) if (! client->fh) { char errbuf[1024]; fprintf(stderr, "unixsock: Failed to open I/O stream for %s: %s\n", - sa.sun_path, sc_strerror(errno, errbuf, sizeof(errbuf))); + sa.sun_path, sdb_strerror(errno, errbuf, sizeof(errbuf))); close(fd); return -1; } client->shutdown = 0; return 0; -} /* sc_unixsock_client_connect */ +} /* sdb_unixsock_client_connect */ int -sc_unixsock_client_send(sc_unixsock_client_t *client, const char *msg) +sdb_unixsock_client_send(sdb_unixsock_client_t *client, + const char *msg) { int status; if ((! client) || (! client->fh)) return -1; - if (client->shutdown & SC_SHUT_WR) /* reconnect */ - sc_unixsock_client_connect(client); + if (client->shutdown & SDB_SHUT_WR) /* reconnect */ + sdb_unixsock_client_connect(client); status = fprintf(client->fh, "%s\r\n", msg); if (status < 0) { char errbuf[1024]; fprintf(stderr, "unixsock: Failed to write to socket (%s): %s\n", - client->path, sc_strerror(errno, errbuf, sizeof(errbuf))); + client->path, sdb_strerror(errno, errbuf, sizeof(errbuf))); return status; } return status; -} /* sc_unixsock_client_send */ +} /* sdb_unixsock_client_send */ char * -sc_unixsock_client_recv(sc_unixsock_client_t *client, char *buffer, size_t buflen) +sdb_unixsock_client_recv(sdb_unixsock_client_t *client, + char *buffer, size_t buflen) { if ((! client) || (! client->fh) || (! buffer)) return NULL; - if (client->shutdown & SC_SHUT_RD) /* reconnect */ - sc_unixsock_client_connect(client); + if (client->shutdown & SDB_SHUT_RD) /* reconnect */ + sdb_unixsock_client_connect(client); buffer = fgets(buffer, (int)buflen - 1, client->fh); if (! buffer) { if (! feof(client->fh)) { char errbuf[1024]; fprintf(stderr, "unixsock: Failed to read from socket (%s): %s\n", - client->path, sc_strerror(errno, errbuf, sizeof(errbuf))); + client->path, sdb_strerror(errno, errbuf, sizeof(errbuf))); } return buffer; } @@ -307,11 +309,11 @@ sc_unixsock_client_recv(sc_unixsock_client_t *client, char *buffer, size_t bufle --buflen; } return buffer; -} /* sc_unixsock_client_recv */ +} /* sdb_unixsock_client_recv */ int -sc_unixsock_client_process_lines(sc_unixsock_client_t *client, - sc_unixsock_client_data_cb callback, sc_object_t *user_data, +sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client, + sdb_unixsock_client_data_cb callback, sdb_object_t *user_data, long int max_lines, const char *delim, int n_cols, ...) { int *types = NULL; @@ -333,7 +335,7 @@ sc_unixsock_client_process_lines(sc_unixsock_client_t *client, for (i = 0; i < n_cols; ++i) { types[i] = va_arg(ap, int); - if ((types[i] < 1) || (types[i] > SC_TYPE_BINARY)) { + if ((types[i] < 1) || (types[i] > SDB_TYPE_BINARY)) { fprintf(stderr, "unixsock: Unknown column type %i while " "processing response from the UNIX socket @ %s.\n", types[i], client->path); @@ -358,13 +360,13 @@ sc_unixsock_client_process_lines(sc_unixsock_client_t *client, if (max_lines > 0) --max_lines; - sc_unixsock_client_clearerr(client); - line = sc_unixsock_client_recv(client, buffer, sizeof(buffer)); + sdb_unixsock_client_clearerr(client); + line = sdb_unixsock_client_recv(client, buffer, sizeof(buffer)); if (! line) break; - column_count = sc_unixsock_get_column_count(line, delim); + column_count = sdb_unixsock_get_column_count(line, delim); if ((n_cols >= 0) && (n_cols != column_count)) { fprintf(stderr, "unixsock: number of columns (%i) does not " @@ -377,7 +379,7 @@ sc_unixsock_client_process_lines(sc_unixsock_client_t *client, if (column_count <= 0) /* no data */ continue; - if (! sc_unixsock_client_process_one_line(client, line, callback, + if (! sdb_unixsock_client_process_one_line(client, line, callback, user_data, delim, column_count, types)) ++success; } @@ -385,21 +387,21 @@ sc_unixsock_client_process_lines(sc_unixsock_client_t *client, free(types); if ((max_lines > 0) - || ((max_lines < 0) && (! sc_unixsock_client_eof(client))) - || sc_unixsock_client_error(client)) { + || ((max_lines < 0) && (! sdb_unixsock_client_eof(client))) + || sdb_unixsock_client_error(client)) { char errbuf[1024]; fprintf(stderr, "unixsock: Unexpected end of data while reading " "from socket (%s): %s\n", client->path, - sc_strerror(errno, errbuf, sizeof(errbuf))); + sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } if (! success) return -1; return 0; -} /* sc_unixsock_client_process_lines */ +} /* sdb_unixsock_client_process_lines */ int -sc_unixsock_client_shutdown(sc_unixsock_client_t *client, int how) +sdb_unixsock_client_shutdown(sdb_unixsock_client_t *client, int how) { int status; @@ -413,43 +415,43 @@ sc_unixsock_client_shutdown(sc_unixsock_client_t *client, int how) if (! status) { if (how == SHUT_RDWR) - client->shutdown |= SC_SHUT_RDWR; + client->shutdown |= SDB_SHUT_RDWR; else client->shutdown |= 1 << how; } return status; -} /* sc_unixsock_client_shutdown */ +} /* sdb_unixsock_client_shutdown */ void -sc_unixsock_client_clearerr(sc_unixsock_client_t *client) +sdb_unixsock_client_clearerr(sdb_unixsock_client_t *client) { if ((! client) || (! client->fh)) return; clearerr(client->fh); -} /* sc_unixsock_client_clearerr */ +} /* sdb_unixsock_client_clearerr */ int -sc_unixsock_client_eof(sc_unixsock_client_t *client) +sdb_unixsock_client_eof(sdb_unixsock_client_t *client) { if ((! client) || (! client->fh)) { errno = EBADF; return -1; } return feof(client->fh); -} /* sc_unixsock_client_eof */ +} /* sdb_unixsock_client_eof */ int -sc_unixsock_client_error(sc_unixsock_client_t *client) +sdb_unixsock_client_error(sdb_unixsock_client_t *client) { if ((! client) || (! client->fh)) { errno = EBADF; return -1; } return ferror(client->fh); -} /* sc_unixsock_client_error */ +} /* sdb_unixsock_client_error */ void -sc_unixsock_client_destroy(sc_unixsock_client_t *client) +sdb_unixsock_client_destroy(sdb_unixsock_client_t *client) { if (! client) return; @@ -463,15 +465,15 @@ sc_unixsock_client_destroy(sc_unixsock_client_t *client) client->fh = NULL; free(client); -} /* sc_unixsock_client_destroy */ +} /* sdb_unixsock_client_destroy */ const char * -sc_unixsock_client_path(sc_unixsock_client_t *client) +sdb_unixsock_client_path(sdb_unixsock_client_t *client) { if (! client) return NULL; return client->path; -} /* sc_unixsock_client_path */ +} /* sdb_unixsock_client_path */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/version-gen.sh b/version-gen.sh index c2ff7c4..de3b31d 100755 --- a/version-gen.sh +++ b/version-gen.sh @@ -3,7 +3,7 @@ DEFAULT_VERSION="0.0.0.git" VERSION="$( git describe --tags 2> /dev/null \ - | sed -e 's/syscollector-//' || true )" + | sed -e 's/sysdb-//' || true )" if test -z "$VERSION"; then VERSION="$DEFAULT_VERSION"