From dcc721a95bef6f0d8e6d8775b8efe33e5aecd562 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 18:28:20 +0200 Subject: Adding upstream version 8.2402.0. Signed-off-by: Daniel Baumann --- plugins/omprog/Makefile.am | 8 + plugins/omprog/Makefile.in | 797 +++++++++++++++++++++++++++ plugins/omprog/omprog.c | 1281 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2086 insertions(+) create mode 100644 plugins/omprog/Makefile.am create mode 100644 plugins/omprog/Makefile.in create mode 100644 plugins/omprog/omprog.c (limited to 'plugins/omprog') diff --git a/plugins/omprog/Makefile.am b/plugins/omprog/Makefile.am new file mode 100644 index 0000000..63fe09b --- /dev/null +++ b/plugins/omprog/Makefile.am @@ -0,0 +1,8 @@ +pkglib_LTLIBRARIES = omprog.la + +omprog_la_SOURCES = omprog.c +omprog_la_CPPFLAGS = $(RSRT_CFLAGS) $(PTHREADS_CFLAGS) +omprog_la_LDFLAGS = -module -avoid-version +omprog_la_LIBADD = + +EXTRA_DIST = diff --git a/plugins/omprog/Makefile.in b/plugins/omprog/Makefile.in new file mode 100644 index 0000000..f54047d --- /dev/null +++ b/plugins/omprog/Makefile.in @@ -0,0 +1,797 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = plugins/omprog +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_check_define.m4 \ + $(top_srcdir)/m4/atomic_operations.m4 \ + $(top_srcdir)/m4/atomic_operations_64bit.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(pkglibdir)" +LTLIBRARIES = $(pkglib_LTLIBRARIES) +omprog_la_DEPENDENCIES = +am_omprog_la_OBJECTS = omprog_la-omprog.lo +omprog_la_OBJECTS = $(am_omprog_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +omprog_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(omprog_la_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/omprog_la-omprog.Plo +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(omprog_la_SOURCES) +DIST_SOURCES = $(omprog_la_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +APU_CFLAGS = @APU_CFLAGS@ +APU_LIBS = @APU_LIBS@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CIVETWEB_LIBS = @CIVETWEB_LIBS@ +CONF_FILE_PATH = @CONF_FILE_PATH@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CURL_CFLAGS = @CURL_CFLAGS@ +CURL_LIBS = @CURL_LIBS@ +CYGPATH_W = @CYGPATH_W@ +CZMQ_CFLAGS = @CZMQ_CFLAGS@ +CZMQ_LIBS = @CZMQ_LIBS@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DL_LIBS = @DL_LIBS@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FAUP_LIBS = @FAUP_LIBS@ +FGREP = @FGREP@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ +GNUTLS_LIBS = @GNUTLS_LIBS@ +GREP = @GREP@ +GSS_LIBS = @GSS_LIBS@ +GT_KSI_LS12_CFLAGS = @GT_KSI_LS12_CFLAGS@ +GT_KSI_LS12_LIBS = @GT_KSI_LS12_LIBS@ +HASH_XXHASH_LIBS = @HASH_XXHASH_LIBS@ +HIREDIS_CFLAGS = @HIREDIS_CFLAGS@ +HIREDIS_LIBS = @HIREDIS_LIBS@ +IMUDP_LIBS = @IMUDP_LIBS@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +IP = @IP@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBCAPNG_CFLAGS = @LIBCAPNG_CFLAGS@ +LIBCAPNG_LIBS = @LIBCAPNG_LIBS@ +LIBCAPNG_PRESENT_CFLAGS = @LIBCAPNG_PRESENT_CFLAGS@ +LIBCAPNG_PRESENT_LIBS = @LIBCAPNG_PRESENT_LIBS@ +LIBDBI_CFLAGS = @LIBDBI_CFLAGS@ +LIBDBI_LIBS = @LIBDBI_LIBS@ +LIBESTR_CFLAGS = @LIBESTR_CFLAGS@ +LIBESTR_LIBS = @LIBESTR_LIBS@ +LIBEVENT_CFLAGS = @LIBEVENT_CFLAGS@ +LIBEVENT_LIBS = @LIBEVENT_LIBS@ +LIBFASTJSON_CFLAGS = @LIBFASTJSON_CFLAGS@ +LIBFASTJSON_LIBS = @LIBFASTJSON_LIBS@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBLOGGING_CFLAGS = @LIBLOGGING_CFLAGS@ +LIBLOGGING_LIBS = @LIBLOGGING_LIBS@ +LIBLOGGING_STDLOG_CFLAGS = @LIBLOGGING_STDLOG_CFLAGS@ +LIBLOGGING_STDLOG_LIBS = @LIBLOGGING_STDLOG_LIBS@ +LIBLOGNORM_CFLAGS = @LIBLOGNORM_CFLAGS@ +LIBLOGNORM_LIBS = @LIBLOGNORM_LIBS@ +LIBLZ4_CFLAGS = @LIBLZ4_CFLAGS@ +LIBLZ4_LIBS = @LIBLZ4_LIBS@ +LIBM = @LIBM@ +LIBMONGOC_CFLAGS = @LIBMONGOC_CFLAGS@ +LIBMONGOC_LIBS = @LIBMONGOC_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBRDKAFKA_CFLAGS = @LIBRDKAFKA_CFLAGS@ +LIBRDKAFKA_LIBS = @LIBRDKAFKA_LIBS@ +LIBS = @LIBS@ +LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ +LIBSYSTEMD_JOURNAL_CFLAGS = @LIBSYSTEMD_JOURNAL_CFLAGS@ +LIBSYSTEMD_JOURNAL_LIBS = @LIBSYSTEMD_JOURNAL_LIBS@ +LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ +LIBTOOL = @LIBTOOL@ +LIBUUID_CFLAGS = @LIBUUID_CFLAGS@ +LIBUUID_LIBS = @LIBUUID_LIBS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MYSQL_CFLAGS = @MYSQL_CFLAGS@ +MYSQL_CONFIG = @MYSQL_CONFIG@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OPENSSL_CFLAGS = @OPENSSL_CFLAGS@ +OPENSSL_LIBS = @OPENSSL_LIBS@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PGSQL_CFLAGS = @PGSQL_CFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PG_CONFIG = @PG_CONFIG@ +PID_FILE_PATH = @PID_FILE_PATH@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PROTON_CFLAGS = @PROTON_CFLAGS@ +PROTON_LIBS = @PROTON_LIBS@ +PROTON_PROACTOR_CFLAGS = @PROTON_PROACTOR_CFLAGS@ +PROTON_PROACTOR_LIBS = @PROTON_PROACTOR_LIBS@ +PTHREADS_CFLAGS = @PTHREADS_CFLAGS@ +PTHREADS_LIBS = @PTHREADS_LIBS@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +RABBITMQ_CFLAGS = @RABBITMQ_CFLAGS@ +RABBITMQ_LIBS = @RABBITMQ_LIBS@ +RANLIB = @RANLIB@ +READLINK = @READLINK@ +REDIS = @REDIS@ +RELP_CFLAGS = @RELP_CFLAGS@ +RELP_LIBS = @RELP_LIBS@ +RSRT_CFLAGS = @RSRT_CFLAGS@ +RSRT_CFLAGS1 = @RSRT_CFLAGS1@ +RSRT_LIBS = @RSRT_LIBS@ +RSRT_LIBS1 = @RSRT_LIBS1@ +RST2MAN = @RST2MAN@ +RT_LIBS = @RT_LIBS@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SNMP_CFLAGS = @SNMP_CFLAGS@ +SNMP_LIBS = @SNMP_LIBS@ +SOL_LIBS = @SOL_LIBS@ +STRIP = @STRIP@ +TCL_BIN_DIR = @TCL_BIN_DIR@ +TCL_INCLUDE_SPEC = @TCL_INCLUDE_SPEC@ +TCL_LIB_FILE = @TCL_LIB_FILE@ +TCL_LIB_FLAG = @TCL_LIB_FLAG@ +TCL_LIB_SPEC = @TCL_LIB_SPEC@ +TCL_PATCH_LEVEL = @TCL_PATCH_LEVEL@ +TCL_SRC_DIR = @TCL_SRC_DIR@ +TCL_STUB_LIB_FILE = @TCL_STUB_LIB_FILE@ +TCL_STUB_LIB_FLAG = @TCL_STUB_LIB_FLAG@ +TCL_STUB_LIB_SPEC = @TCL_STUB_LIB_SPEC@ +TCL_VERSION = @TCL_VERSION@ +UDPSPOOF_CFLAGS = @UDPSPOOF_CFLAGS@ +UDPSPOOF_LIBS = @UDPSPOOF_LIBS@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +WARN_CFLAGS = @WARN_CFLAGS@ +WARN_LDFLAGS = @WARN_LDFLAGS@ +WARN_SCANNERFLAGS = @WARN_SCANNERFLAGS@ +WGET = @WGET@ +YACC = @YACC@ +YACC_FOUND = @YACC_FOUND@ +YFLAGS = @YFLAGS@ +ZLIB_CFLAGS = @ZLIB_CFLAGS@ +ZLIB_LIBS = @ZLIB_LIBS@ +ZSTD_CFLAGS = @ZSTD_CFLAGS@ +ZSTD_LIBS = @ZSTD_LIBS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +moddirs = @moddirs@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +pkglib_LTLIBRARIES = omprog.la +omprog_la_SOURCES = omprog.c +omprog_la_CPPFLAGS = $(RSRT_CFLAGS) $(PTHREADS_CFLAGS) +omprog_la_LDFLAGS = -module -avoid-version +omprog_la_LIBADD = +EXTRA_DIST = +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu plugins/omprog/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu plugins/omprog/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkglibdir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pkglibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pkglibdir)"; \ + } + +uninstall-pkglibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pkglibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pkglibdir)/$$f"; \ + done + +clean-pkglibLTLIBRARIES: + -test -z "$(pkglib_LTLIBRARIES)" || rm -f $(pkglib_LTLIBRARIES) + @list='$(pkglib_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +omprog.la: $(omprog_la_OBJECTS) $(omprog_la_DEPENDENCIES) $(EXTRA_omprog_la_DEPENDENCIES) + $(AM_V_CCLD)$(omprog_la_LINK) -rpath $(pkglibdir) $(omprog_la_OBJECTS) $(omprog_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/omprog_la-omprog.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +omprog_la-omprog.lo: omprog.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(omprog_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT omprog_la-omprog.lo -MD -MP -MF $(DEPDIR)/omprog_la-omprog.Tpo -c -o omprog_la-omprog.lo `test -f 'omprog.c' || echo '$(srcdir)/'`omprog.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/omprog_la-omprog.Tpo $(DEPDIR)/omprog_la-omprog.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='omprog.c' object='omprog_la-omprog.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(omprog_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o omprog_la-omprog.lo `test -f 'omprog.c' || echo '$(srcdir)/'`omprog.c + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(pkglibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-pkglibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/omprog_la-omprog.Plo + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-pkglibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/omprog_la-omprog.Plo + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-pkglibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libtool clean-pkglibLTLIBRARIES \ + cscopelist-am ctags ctags-am distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-pkglibLTLIBRARIES install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am uninstall-pkglibLTLIBRARIES + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/plugins/omprog/omprog.c b/plugins/omprog/omprog.c new file mode 100644 index 0000000..f21169a --- /dev/null +++ b/plugins/omprog/omprog.c @@ -0,0 +1,1281 @@ +/* omprog.c + * This output plugin enables rsyslog to execute a program and + * feed it the message stream as standard input. + * + * NOTE: read comments in module-template.h for more specifics! + * + * File begun on 2009-04-01 by RGerhards + * + * Copyright 2009-2020 Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * -or- + * see COPYING.ASL20 in the source distribution + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rsyslog.h" +#include "conf.h" +#include "syslogd-types.h" +#include "srUtils.h" +#include "template.h" +#include "module-template.h" +#include "errmsg.h" +#include "cfsysline.h" +#include "glbl.h" +#include "rsconf.h" + +MODULE_TYPE_OUTPUT +MODULE_TYPE_NOKEEP +MODULE_CNFNAME("omprog") + +extern char **environ; /* POSIX environment ptr, by std not in a header... (see man 7 environ) */ + +/* internal structures + */ +DEF_OMOD_STATIC_DATA + +#define NO_HUP_FORWARD -1 /* indicates that HUP should NOT be forwarded */ +#define DEFAULT_CONFIRM_TIMEOUT_MS 10000 +#define DEFAULT_CLOSE_TIMEOUT_MS 5000 +#define RESPONSE_LINE_BUFFER_SIZE 4096 +#define OUTPUT_CAPTURE_BUFFER_SIZE 4096 +#define MAX_FD_TO_CLOSE 65535 + +typedef struct childProcessCtx { + int bIsRunning; /* is the program running? (if 0, next fields are uninitialized) */ + pid_t pid; /* pid of currently running child process */ + int fdPipeOut; /* fd for sending messages to the program */ + int fdPipeIn; /* fd for receiving status messages from the program, or -1 */ +} childProcessCtx_t; + +typedef struct outputCaptureCtx { + uchar *szFileName; /* name of file to write the program output to, or NULL */ + mode_t fCreateMode; /* output file creation permissions */ + pthread_mutex_t mutStart; /* mutex for starting the output-capture thread */ + pthread_mutex_t mutWrite; /* mutex for reopening the output file on HUP while being written */ + pthread_mutex_t mutTerm; /* mutex for signaling the termination of the thread */ + pthread_cond_t condTerm; /* condition for signaling the termination of the thread */ + int bIsRunning; /* is the thread running? (if 0, next fields are uninitialized) */ + pthread_t thrdID; /* ID of the output-capture thread */ + int fdPipe[2]; /* pipe for capturing the output of the child processes */ + int fdFile; /* fd of the output file (-1 if it could not be opened) */ + int bFileErr; /* file open error occurred? (to avoid reporting too many errors) */ + int bReadErr; /* read error occurred? (to avoid reporting too many errors) */ + int bWriteErr; /* write error occurred? (to avoid reporting too many errors) */ +} outputCaptureCtx_t; + +typedef struct _instanceData { + uchar *szBinary; /* name of external program to call */ + char **aParams; /* optional parameters to pass to external program */ + int iParams; /* holds the count of parameters if set */ + uchar *szTemplateName; /* assigned output template */ + int bConfirmMessages; /* does the program provide feedback via stdout? */ + long lConfirmTimeout; /* how long to wait for feedback from the program (ms) */ + int bReportFailures; /* report failures returned by the program as warning logs? */ + int bUseTransactions; /* send begin/end transaction marks to program? */ + uchar *szBeginTransactionMark; /* mark message for begin transaction */ + uchar *szCommitTransactionMark; /* mark message for commit transaction */ + int iHUPForward; /* signal to forward on HUP (or NO_HUP_FORWARD) */ + int bSignalOnClose; /* should send SIGTERM to program before closing pipe? */ + long lCloseTimeout; /* how long to wait for program to terminate after closing pipe (ms) */ + int bKillUnresponsive; /* should send SIGKILL if closeTimeout is reached? */ + int bForceSingleInst; /* start only one instance of program, even with multiple workers? */ + childProcessCtx_t *pSingleChildCtx; /* child process context when bForceSingleInst=true */ + pthread_mutex_t *pSingleChildMut; /* mutex for interacting with single child process */ + outputCaptureCtx_t *pOutputCaptureCtx; /* settings and state for the output capture thread */ + time_t block_if_err; /* time until which interface error is not to be shown */ +} instanceData; + +typedef struct wrkrInstanceData { + instanceData *pData; + childProcessCtx_t *pChildCtx; /* child process context (can be equal to pSingleChildCtx) */ +} wrkrInstanceData_t; + +typedef struct configSettings_s { + uchar *szBinary; /* name of external program to call */ +} configSettings_t; +static configSettings_t cs; + +/* tables for interfacing with the v6 config system */ +/* action (instance) parameters */ +static struct cnfparamdescr actpdescr[] = { + { "binary", eCmdHdlrString, CNFPARAM_REQUIRED }, + { "confirmMessages", eCmdHdlrBinary, 0 }, + { "confirmTimeout", eCmdHdlrInt, 0 }, + { "reportFailures", eCmdHdlrBinary, 0 }, + { "useTransactions", eCmdHdlrBinary, 0 }, + { "beginTransactionMark", eCmdHdlrString, 0 }, + { "commitTransactionMark", eCmdHdlrString, 0 }, + { "forceSingleInstance", eCmdHdlrBinary, 0 }, + { "hup.signal", eCmdHdlrGetWord, 0 }, + { "template", eCmdHdlrGetWord, 0 }, + { "signalOnClose", eCmdHdlrBinary, 0 }, + { "closeTimeout", eCmdHdlrInt, 0 }, + { "killUnresponsive", eCmdHdlrBinary, 0 }, + { "output", eCmdHdlrString, 0 }, + { "fileCreateMode", eCmdHdlrFileCreateMode, 0 } +}; + +static struct cnfparamblk actpblk = + { CNFPARAMBLK_VERSION, + sizeof(actpdescr)/sizeof(struct cnfparamdescr), + actpdescr + }; + +/* execute the external program (must be called in child context after fork). + */ +static __attribute__((noreturn)) void +execBinary(const instanceData *pData, int fdStdin, int fdStdout) +{ + int fdOutput, maxFd, fd, sigNum; + struct sigaction sigAct; + sigset_t sigSet; + char errStr[1024]; + + if(dup2(fdStdin, STDIN_FILENO) == -1) { + goto failed; + } + + if(pData->pOutputCaptureCtx != NULL) { + fdOutput = pData->pOutputCaptureCtx->fdPipe[1]; + } else { + fdOutput = open("/dev/null", O_WRONLY); + if(fdOutput == -1) { + goto failed; + } + } + + if(fdStdout != -1) { + /* confirmMessages enabled: redirect stdout to parent via pipe. After + * this point, anything written to the child's stdout will be treated + * by omprog as initialization feedback (see startChild). This + * includes debug messages (DBGPRINTF) when in debug mode. So we + * cannot use DBGPRINTF from this point on, except for error cases. + */ + if(dup2(fdStdout, STDOUT_FILENO) == -1) { + goto failed; + } + } else { + /* confirmMessages disabled: redirect stdout to file or /dev/null */ + if(dup2(fdOutput, STDOUT_FILENO) == -1) { + goto failed; + } + } + + /* redirect stderr to file or /dev/null */ + if(dup2(fdOutput, STDERR_FILENO) == -1) { + goto failed; + } + + /* close the file handles the child process doesn't need (all above STDERR). + * The following way is simple and portable, though not perfect. + * See https://stackoverflow.com/a/918469 for alternatives. + */ + maxFd = sysconf(_SC_OPEN_MAX); + if(maxFd < 0 || maxFd > MAX_FD_TO_CLOSE) { + maxFd = MAX_FD_TO_CLOSE; + } +# ifdef VALGRIND + else { /* don't close valgrind reserved fds, to avoid warnings */ + maxFd -= 10; + } +# endif + for(fd = STDERR_FILENO + 1 ; fd <= maxFd ; ++fd) { + close(fd); + } + + /* reset signal handlers to default */ + memset(&sigAct, 0, sizeof(sigAct)); + sigemptyset(&sigAct.sa_mask); + sigAct.sa_handler = SIG_DFL; + for(sigNum = 1 ; sigNum < NSIG ; ++sigNum) { + sigaction(sigNum, &sigAct, NULL); + } + + /* we need to block SIGINT, otherwise our program is cancelled when we are + * stopped in debug mode. + */ + sigAct.sa_handler = SIG_IGN; + sigaction(SIGINT, &sigAct, NULL); + sigemptyset(&sigSet); + sigprocmask(SIG_SETMASK, &sigSet, NULL); + + alarm(0); + + /* finally exec program */ + execve((char*)pData->szBinary, pData->aParams, environ); + +failed: + /* an error occurred: log it and exit the child process. We use the + * 'syslog' system call to log the error (we cannot use LogMsg/LogError, + * since these functions add directly to the rsyslog input queue). + */ + rs_strerror_r(errno, errStr, sizeof(errStr)); + DBGPRINTF("omprog: failed to execute program '%s': %s\n", + pData->szBinary, errStr); + openlog("rsyslogd", 0, LOG_SYSLOG); + syslog(LOG_ERR, "omprog: failed to execute program '%s': %s\n", + pData->szBinary, errStr); + exit(1); +} + +/* creates a pipe and starts program, uses pipe as stdin for program. + * rgerhards, 2009-04-01 + */ +static rsRetVal +openPipe(instanceData *pData, childProcessCtx_t *pChildCtx) +{ + int pipeStdin[2] = { -1, -1 }; + int pipeStdout[2] = { -1, -1 }; + pid_t cpid; + DEFiRet; + + /* open a pipe to send messages to the program */ + if(pipe(pipeStdin) == -1) { + ABORT_FINALIZE(RS_RET_ERR_CREAT_PIPE); + } + + /* if the 'confirmMessages' setting is enabled, open a pipe to receive + message confirmations from the program */ + if(pData->bConfirmMessages && pipe(pipeStdout) == -1) { + ABORT_FINALIZE(RS_RET_ERR_CREAT_PIPE); + } + + DBGPRINTF("omprog: executing program '%s' with '%d' parameters\n", pData->szBinary, + pData->iParams); + + cpid = fork(); + if(cpid == -1) { + ABORT_FINALIZE(RS_RET_ERR_FORK); + } + + if(cpid == 0) { /* we are now the child process: execute the program */ + /* close the pipe ends that the child doesn't need */ + close(pipeStdin[1]); + if(pipeStdout[0] != -1) { + close(pipeStdout[0]); + } + + execBinary(pData, pipeStdin[0], pipeStdout[1]); + /* NO CODE HERE - WILL NEVER BE REACHED! */ + } + + DBGPRINTF("omprog: child has pid %d\n", (int) cpid); + + /* close the pipe ends that the parent doesn't need */ + close(pipeStdin[0]); + if(pipeStdout[1] != -1) { + close(pipeStdout[1]); + } + + pChildCtx->fdPipeOut = pipeStdin[1]; /* we'll send messages to the program via this fd */ + pChildCtx->fdPipeIn = pipeStdout[0]; /* we'll receive message confirmations via this fd */ + pChildCtx->pid = cpid; + pChildCtx->bIsRunning = 1; + +finalize_it: + if(iRet != RS_RET_OK) { + if(pipeStdin[0] != -1) { + close(pipeStdin[0]); + close(pipeStdin[1]); + } + if(pipeStdout[0] != -1) { + close(pipeStdout[0]); + close(pipeStdout[1]); + } + } + RETiRet; +} + +static void +waitForChild(instanceData *pData, childProcessCtx_t *pChildCtx) +{ + int status; + int ret; + long counter; + + counter = pData->lCloseTimeout / 10; + while ((ret = waitpid(pChildCtx->pid, &status, WNOHANG)) == 0 && counter > 0) { + srSleep(0, 10000); /* 0 seconds, 10 milliseconds */ + --counter; + } + + if (ret == 0) { /* timeout reached */ + if (!pData->bKillUnresponsive) { + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: program '%s' (pid %ld) did not terminate " + "within timeout (%ld ms); ignoring it", pData->szBinary, + (long) pChildCtx->pid, pData->lCloseTimeout); + return; + } + + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: program '%s' (pid %ld) did not terminate " + "within timeout (%ld ms); killing it", pData->szBinary, (long) pChildCtx->pid, + pData->lCloseTimeout); + if (kill(pChildCtx->pid, SIGKILL) == -1) { + LogError(errno, RS_RET_SYS_ERR, "omprog: could not send SIGKILL to child process"); + return; + } + + ret = waitpid(pChildCtx->pid, &status, 0); + } + + /* waitpid will fail with errno == ECHILD if the child process has already + been reaped by the rsyslogd main loop (see rsyslogd.c) */ + if(ret == pChildCtx->pid) { + glblReportChildProcessExit(runConf, pData->szBinary, pChildCtx->pid, status); + } +} + +/* close pipe and wait for child to terminate + */ +static void +cleanupChild(instanceData *pData, childProcessCtx_t *pChildCtx) +{ + assert(pChildCtx->bIsRunning); + + if(pChildCtx->fdPipeIn != -1) { + close(pChildCtx->fdPipeIn); + pChildCtx->fdPipeIn = -1; + } + if(pChildCtx->fdPipeOut != -1) { + close(pChildCtx->fdPipeOut); + pChildCtx->fdPipeOut = -1; + } + + /* wait for the child AFTER closing the pipe, so it receives EOF */ + waitForChild(pData, pChildCtx); + + pChildCtx->bIsRunning = 0; +} + +/* Send SIGTERM to child process if configured to do so, close pipe + * and wait for child to terminate. + */ +static void +terminateChild(instanceData *pData, childProcessCtx_t *pChildCtx) +{ + DBGPRINTF("terminateChild called\n"); + assert(pChildCtx->bIsRunning); + + if (pData->bSignalOnClose) { + kill(pChildCtx->pid, SIGTERM); + } + + cleanupChild(pData, pChildCtx); +} + +/* write message to pipe + * note that we do not try to run block-free. If the user fears something + * may block (and this is not acceptable), the action should be run on its + * own action queue. + */ +static rsRetVal +sendMessage(instanceData *pData, childProcessCtx_t *pChildCtx, const uchar *szMsg) +{ + ssize_t written; + size_t offset = 0; + DEFiRet; + + const size_t len = strlen((char*)szMsg); + + do { + written = write(pChildCtx->fdPipeOut, ((char*)szMsg) + offset, len - offset); + if(written == -1) { + if(errno == EINTR) { + continue; /* call interrupted: retry write */ + } + if(errno == EPIPE) { + LogMsg(0, RS_RET_ERR_WRITE_PIPE, LOG_WARNING, + "omprog: program '%s' (pid %ld) terminated; will be restarted", + pData->szBinary, (long) pChildCtx->pid); + cleanupChild(pData, pChildCtx); /* force restart in tryResume() */ + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + LogError(errno, RS_RET_ERR_WRITE_PIPE, "omprog: error sending message to program"); + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + offset += written; + } while(offset < len); + +finalize_it: + RETiRet; +} + +static rsRetVal +lineToStatusCode(instanceData *pData, const char* line) +{ + DEFiRet; + + /* strip leading dots (.) from the line, so the program can use them as a keep-alive mechanism */ + while(line[0] == '.') { + ++line; + } + + if(strcmp(line, "OK") == 0) { + iRet = RS_RET_OK; + } else if(strcmp(line, "DEFER_COMMIT") == 0) { + iRet = RS_RET_DEFER_COMMIT; + } else if(strcmp(line, "PREVIOUS_COMMITTED") == 0) { + iRet = RS_RET_PREVIOUS_COMMITTED; + } else { + /* anything else is considered a recoverable error */ + DBGPRINTF("omprog: program '%s' returned: %s\n", pData->szBinary, line); + if(pData->bReportFailures) { + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: program '%s' returned: %s", + pData->szBinary, line); + } + iRet = RS_RET_SUSPENDED; + } + RETiRet; +} + +static rsRetVal +readStatus(instanceData *pData, childProcessCtx_t *pChildCtx) +{ + struct pollfd fdToPoll[1]; + int numReady; + char lineBuf[RESPONSE_LINE_BUFFER_SIZE]; + ssize_t lenRead; + size_t offset = 0; + int lineEnded = 0; + DEFiRet; + + fdToPoll[0].fd = pChildCtx->fdPipeIn; + fdToPoll[0].events = POLLIN; + + do { + numReady = poll(fdToPoll, 1, pData->lConfirmTimeout); + if(numReady == -1) { + if(errno == EINTR) { + continue; /* call interrupted: retry poll */ + } + LogError(errno, RS_RET_SYS_ERR, "omprog: error polling for response from program"); + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + + if(numReady == 0) { /* timeout reached */ + LogMsg(0, RS_RET_TIMED_OUT, LOG_WARNING, "omprog: program '%s' (pid %ld) did not respond " + "within timeout (%ld ms); will be restarted", pData->szBinary, + (long) pChildCtx->pid, pData->lConfirmTimeout); + terminateChild(pData, pChildCtx); + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + + lenRead = read(pChildCtx->fdPipeIn, lineBuf + offset, sizeof(lineBuf) - offset - 1); + if(lenRead == -1) { + if(errno == EINTR) { + continue; /* call interrupted: retry poll + read */ + } + LogError(errno, RS_RET_READ_ERR, "omprog: error reading response from program"); + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + + if(lenRead == 0) { + LogMsg(0, RS_RET_READ_ERR, LOG_WARNING, "omprog: program '%s' (pid %ld) terminated; " + "will be restarted", pData->szBinary, (long) pChildCtx->pid); + cleanupChild(pData, pChildCtx); + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + + offset += lenRead; + lineBuf[offset] = '\0'; + lineEnded = (lineBuf[offset-1] == '\n'); + + /* check that the program has not returned multiple lines. This should not occur if + * the program honors the specified interface. Otherwise, we force a restart of the + * program, since we have probably lost synchronism with it. + */ + if(!lineEnded && strchr(lineBuf + offset - lenRead, '\n') != NULL) { + DBGPRINTF("omprog: program '%s' returned: %s\n", pData->szBinary, lineBuf); + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: program '%s' returned a multiline response; " + "will be restarted", pData->szBinary); + if(pData->bReportFailures) { + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: program '%s' returned: %s", + pData->szBinary, lineBuf); + } + terminateChild(pData, pChildCtx); + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + } while(!lineEnded && offset < sizeof(lineBuf) - 1); + + if(!lineEnded) { + DBGPRINTF("omprog: program '%s' returned: %s\n", pData->szBinary, lineBuf); + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: program '%s' returned a too long response; " + "will be restarted", pData->szBinary); + if(pData->bReportFailures) { + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: program '%s' returned: %s", + pData->szBinary, lineBuf); + } + terminateChild(pData, pChildCtx); + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + + lineBuf[offset-1] = '\0'; /* strip newline char */ + + /* NOTE: coverity does not like CHKiRet() if it is the last thing before finalize_it. + * Reason is that the if() inside that macro than does not lead to different code paths. + */ + iRet = lineToStatusCode(pData, lineBuf); + +finalize_it: + RETiRet; +} + +static rsRetVal +allocChildCtx(childProcessCtx_t **ppChildCtx) +{ + childProcessCtx_t *pChildCtx; + DEFiRet; + + CHKmalloc(pChildCtx = calloc(1, sizeof(childProcessCtx_t))); + *ppChildCtx = pChildCtx; + + pChildCtx->bIsRunning = 0; + pChildCtx->pid = -1; + pChildCtx->fdPipeOut = -1; + pChildCtx->fdPipeIn = -1; + +finalize_it: + RETiRet; +} + +static rsRetVal +startChild(instanceData *pData, childProcessCtx_t *pChildCtx) +{ + DEFiRet; + + assert(!pChildCtx->bIsRunning); + + CHKiRet(openPipe(pData, pChildCtx)); + + if(pData->bConfirmMessages) { + /* wait for program to confirm successful initialization */ + CHKiRet(readStatus(pData, pChildCtx)); + } + +finalize_it: + if(iRet != RS_RET_OK && pChildCtx->bIsRunning) { + /* if initialization has failed, terminate program */ + terminateChild(pData, pChildCtx); + } + RETiRet; +} + +static rsRetVal +startSingleChildOnce(instanceData *pData) +{ + DEFiRet; + + assert(pData->bForceSingleInst); + CHKiConcCtrl(pthread_mutex_lock(pData->pSingleChildMut)); + + if(pData->pSingleChildCtx->bIsRunning) + goto finalize_it; /* child process already started: nothing to do */ + + iRet = startChild(pData, pData->pSingleChildCtx); + +finalize_it: + pthread_mutex_unlock(pData->pSingleChildMut); + RETiRet; +} + +static void +writeOutputToFile(outputCaptureCtx_t *pCtx, char *buf, ssize_t len) +{ + ssize_t written; + ssize_t offset = 0; + + assert(pCtx->bIsRunning); + pthread_mutex_lock(&pCtx->mutWrite); + + if(pCtx->fdFile == -1) { + if(pCtx->bFileErr) { /* discarding output because file couldn't be opened */ + goto done; + } + + pCtx->fdFile = open((char*)pCtx->szFileName, O_WRONLY | O_APPEND | O_CREAT, + pCtx->fCreateMode); + if(pCtx->fdFile == -1) { + LogError(errno, RS_RET_NO_FILE_ACCESS, "omprog: error opening output file %s; " + "output from program will be discarded", pCtx->szFileName); + pCtx->bFileErr = 1; /* avoid reporting too many errors */ + goto done; + } + } + + do { + written = write(pCtx->fdFile, buf + offset, len - offset); + if(written == -1) { + if(errno == EINTR) { + continue; /* call interrupted: retry write */ + } + + if(!pCtx->bWriteErr) { + LogError(errno, RS_RET_SYS_ERR, "omprog: error writing to output file " + "(subsequent errors will not be reported)"); + pCtx->bWriteErr = 1; /* avoid reporting too many errors */ + } + break; + } + + if(pCtx->bWriteErr) { + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: resumed writing to output file"); + pCtx->bWriteErr = 0; + } + + offset += written; + } while(offset < len); + +done: + pthread_mutex_unlock(&pCtx->mutWrite); +} + +static void +closeOutputFile(outputCaptureCtx_t *pCtx) +{ + DBGPRINTF("omprog: reopening output file upon reception of HUP signal\n"); + pthread_mutex_lock(&pCtx->mutWrite); + + if(pCtx->fdFile != -1) { + close(pCtx->fdFile); + pCtx->fdFile = -1; + } + pCtx->bFileErr = 0; /* if there was an error opening the file, we'll retry */ + + pthread_mutex_unlock(&pCtx->mutWrite); +} + +/* This code runs in a dedicated thread. Captures the output of the child processes + * through a shared pipe (one reader and multiple writers), and writes the output + * to a file. The lines concurrently emmitted to stdout/stderr by the child processes + * will not appear intermingled in the output file if 1) the lines are short enough + * (less than PIPE_BUF bytes long: 4KB on Linux, and 512 bytes or more on other + * POSIX systems), and 2) the program outputs each line using a single 'write' + * syscall (line buffering mode). When a HUP signal is received, the output file is + * reopened (this provides support for external rotation of the file). + */ +static void * +captureOutput(void *_pCtx) { + outputCaptureCtx_t *pCtx = (outputCaptureCtx_t *)_pCtx; + sigset_t sigSet; + char readBuf[OUTPUT_CAPTURE_BUFFER_SIZE]; + ssize_t lenRead; + + DBGPRINTF("omprog: starting output capture thread\n"); + + /* block signals for this thread (otherwise shutdown hangs on FreeBSD) */ + sigfillset(&sigSet); + pthread_sigmask(SIG_SETMASK, &sigSet, NULL); + + for(;;) { + lenRead = read(pCtx->fdPipe[0], readBuf, sizeof(readBuf)); + if(lenRead == -1) { + if(errno == EINTR) { + continue; /* call interrupted: retry read */ + } + + if(!pCtx->bReadErr) { + LogError(errno, RS_RET_SYS_ERR, "omprog: error capturing output from program " + "(subsequent errors will not be reported)"); + pCtx->bReadErr = 1; /* avoid reporting too many errors */ + } + continue; /* continue with next line */ + } + + if(lenRead == 0) { + break; /* all write ends of pipe closed: exit loop and terminate thread */ + } + + if(pCtx->bReadErr) { + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: resumed capturing output from program"); + pCtx->bReadErr = 0; + } + + writeOutputToFile(pCtx, readBuf, lenRead); + } + + DBGPRINTF("omprog: all output-capture pipe ends closed, terminating output capture thread\n"); + pthread_mutex_lock(&pCtx->mutTerm); + pCtx->bIsRunning = 0; + pthread_cond_signal(&pCtx->condTerm); + pthread_mutex_unlock(&pCtx->mutTerm); + return NULL; +} + +static rsRetVal +allocOutputCaptureCtx(outputCaptureCtx_t **ppCtx) +{ + outputCaptureCtx_t *pCtx; + DEFiRet; + + CHKmalloc(pCtx = calloc(1, sizeof(outputCaptureCtx_t))); + *ppCtx = pCtx; + + pCtx->szFileName = NULL; + pCtx->fCreateMode = 0600; + pCtx->bIsRunning = 0; + + CHKiConcCtrl(pthread_mutex_init(&pCtx->mutStart, NULL)); + CHKiConcCtrl(pthread_mutex_init(&pCtx->mutWrite, NULL)); + CHKiConcCtrl(pthread_mutex_init(&pCtx->mutTerm, NULL)); + CHKiConcCtrl(pthread_cond_init(&pCtx->condTerm, NULL)); + +finalize_it: + RETiRet; +} + +static void +freeOutputCaptureCtx(outputCaptureCtx_t *pCtx) { + if(pCtx->szFileName != NULL) { + free(pCtx->szFileName); + } + + pthread_cond_destroy(&pCtx->condTerm); + pthread_mutex_destroy(&pCtx->mutTerm); + pthread_mutex_destroy(&pCtx->mutWrite); + pthread_mutex_destroy(&pCtx->mutStart); + + free(pCtx); +} + +static rsRetVal +startOutputCaptureOnce(outputCaptureCtx_t *pCtx) +{ + int pip[2] = { -1, -1 }; + DEFiRet; + + CHKiConcCtrl(pthread_mutex_lock(&pCtx->mutStart)); + + if(pCtx->bIsRunning) + goto finalize_it; /* output capture thread already started: nothing to do */ + + /* open a (single) pipe to capture output from (all) child processes */ + if(pipe(pip) == -1) { + ABORT_FINALIZE(RS_RET_ERR_CREAT_PIPE); + } + + pCtx->fdPipe[0] = pip[0]; + pCtx->fdPipe[1] = pip[1]; + pCtx->fdFile = -1; + pCtx->bFileErr = 0; + pCtx->bReadErr = 0; + pCtx->bWriteErr = 0; + + /* start a thread to read lines from the pipe and write them to the output file */ + CHKiConcCtrl(pthread_create(&pCtx->thrdID, NULL, captureOutput, (void *)pCtx)); + + pCtx->bIsRunning = 1; + +finalize_it: + if(iRet != RS_RET_OK && pip[0] != -1) { + close(pip[0]); + close(pip[1]); + } + pthread_mutex_unlock(&pCtx->mutStart); + RETiRet; +} + +static void +endOutputCapture(outputCaptureCtx_t *pCtx, long timeoutMs) +{ + struct timespec ts; + int bTimedOut; + + assert(pCtx->bIsRunning); + + /* close our write end of the output-capture pipe */ + close(pCtx->fdPipe[1]); + + /* the output capture thread will now terminate because there are no more + * writers attached to the output-capture pipe. However, if a child becomes + * unresponsive without closing its pipe end (assuming killUnresponsive=off), + * we would wait forever. To avoid this, we wait for the thread to terminate + * during a maximum timeout (we reuse the 'closeTimeout' setting for this). + */ + timeoutComp(&ts, timeoutMs); + pthread_mutex_lock(&pCtx->mutTerm); + bTimedOut = 0; + while(pCtx->bIsRunning && !bTimedOut) { + if(pthread_cond_timedwait(&pCtx->condTerm, &pCtx->mutTerm, &ts) == ETIMEDOUT) { + bTimedOut = 1; + } + } + pthread_mutex_unlock(&pCtx->mutTerm); + + if(bTimedOut) { + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: forcing termination of output capture " + "thread because of unresponsive child process"); + pthread_cancel(pCtx->thrdID); + pCtx->bIsRunning = 0; + } + + pthread_join(pCtx->thrdID, NULL); + + /* close the read end of the output-capture pipe */ + close(pCtx->fdPipe[0]); + + /* close the output file (if it could be opened) */ + if(pCtx->fdFile != -1) { + close(pCtx->fdFile); + } +} + + +BEGINinitConfVars /* (re)set config variables to default values */ +CODESTARTinitConfVars + cs.szBinary = NULL; /* name of binary to call */ +ENDinitConfVars + + +BEGINcreateInstance +CODESTARTcreateInstance + pData->szBinary = NULL; + pData->szTemplateName = NULL; + pData->aParams = NULL; + pData->iParams = 0; + pData->bConfirmMessages = 0; + pData->block_if_err = 0; + pData->lConfirmTimeout = DEFAULT_CONFIRM_TIMEOUT_MS; + pData->bReportFailures = 0; + pData->bUseTransactions = 0; + pData->szBeginTransactionMark = NULL; + pData->szCommitTransactionMark = NULL; + pData->iHUPForward = NO_HUP_FORWARD; + pData->bSignalOnClose = 0; + pData->lCloseTimeout = DEFAULT_CLOSE_TIMEOUT_MS; + pData->bKillUnresponsive = -1; + pData->bForceSingleInst = 0; + pData->pSingleChildCtx = NULL; + pData->pSingleChildMut = NULL; + pData->pOutputCaptureCtx = NULL; +ENDcreateInstance + + +static rsRetVal +postInitInstance(instanceData *pData) +{ + DEFiRet; + + if(pData->bUseTransactions && pData->szBeginTransactionMark == NULL) { + pData->szBeginTransactionMark = (uchar*)strdup("BEGIN TRANSACTION"); + } + if(pData->bUseTransactions && pData->szCommitTransactionMark == NULL) { + pData->szCommitTransactionMark = (uchar*)strdup("COMMIT TRANSACTION"); + } + if(pData->bKillUnresponsive == -1) { /* default value: bSignalOnClose */ + pData->bKillUnresponsive = pData->bSignalOnClose; + } + + if(pData->pOutputCaptureCtx != NULL && pData->pOutputCaptureCtx->szFileName == NULL) { + LogError(0, RS_RET_CONF_PARAM_INVLD, "omprog: the 'fileCreateMode' parameter requires " + "specifying the 'output' parameter also"); + ABORT_FINALIZE(RS_RET_CONF_PARAM_INVLD); + } + + if(pData->bForceSingleInst) { + CHKmalloc(pData->pSingleChildMut = calloc(1, sizeof(pthread_mutex_t))); + CHKiConcCtrl(pthread_mutex_init(pData->pSingleChildMut, NULL)); + CHKiRet(allocChildCtx(&pData->pSingleChildCtx)); + /* do not start the child here. The config is still being parsed, and the daemon + has not been forked yet. When the daemon is forked, all fds will be closed! */ + } + +finalize_it: + /* no cleanup needed on error: newActInst() will call freeInstance() */ + RETiRet; +} + + +BEGINcreateWrkrInstance +CODESTARTcreateWrkrInstance + pWrkrData->pChildCtx = NULL; + + if(pWrkrData->pData->pOutputCaptureCtx != NULL) { + CHKiRet(startOutputCaptureOnce(pWrkrData->pData->pOutputCaptureCtx)); + } + + if(pWrkrData->pData->bForceSingleInst) { + CHKiRet(startSingleChildOnce(pWrkrData->pData)); + pWrkrData->pChildCtx = pData->pSingleChildCtx; + } else { + CHKiRet(allocChildCtx(&pWrkrData->pChildCtx)); + CHKiRet(startChild(pWrkrData->pData, pWrkrData->pChildCtx)); + } + +finalize_it: +ENDcreateWrkrInstance + + +BEGINisCompatibleWithFeature +CODESTARTisCompatibleWithFeature + if(eFeat == sFEATURERepeatedMsgReduction) { + iRet = RS_RET_OK; + } +ENDisCompatibleWithFeature + + +BEGINdbgPrintInstInfo +CODESTARTdbgPrintInstInfo +ENDdbgPrintInstInfo + + +BEGINtryResume +CODESTARTtryResume + if(pWrkrData->pData->bForceSingleInst) { + CHKiConcCtrl(pthread_mutex_lock(pWrkrData->pData->pSingleChildMut)); + } + if(!pWrkrData->pChildCtx->bIsRunning) { + CHKiRet(startChild(pWrkrData->pData, pWrkrData->pChildCtx)); + } + +finalize_it: + if(pWrkrData->pData->bForceSingleInst) { + pthread_mutex_unlock(pWrkrData->pData->pSingleChildMut); + } +ENDtryResume + + +BEGINbeginTransaction +CODESTARTbeginTransaction + if(pWrkrData->pData->bForceSingleInst) { + CHKiConcCtrl(pthread_mutex_lock(pWrkrData->pData->pSingleChildMut)); + } + if(!pWrkrData->pData->bUseTransactions) { + FINALIZE; + } + + CHKiRet(sendMessage(pWrkrData->pData, pWrkrData->pChildCtx, + pWrkrData->pData->szBeginTransactionMark)); + CHKiRet(sendMessage(pWrkrData->pData, pWrkrData->pChildCtx, (uchar*) "\n")); + + if(pWrkrData->pData->bConfirmMessages) { + CHKiRet(readStatus(pWrkrData->pData, pWrkrData->pChildCtx)); + } + +finalize_it: + if(pWrkrData->pData->bForceSingleInst) { + pthread_mutex_unlock(pWrkrData->pData->pSingleChildMut); + } +ENDbeginTransaction + + +BEGINdoAction +CODESTARTdoAction + if(pWrkrData->pData->bForceSingleInst) { + CHKiConcCtrl(pthread_mutex_lock(pWrkrData->pData->pSingleChildMut)); + } + if(!pWrkrData->pChildCtx->bIsRunning) { /* should not occur */ + ABORT_FINALIZE(RS_RET_SUSPENDED); + } + + const uchar *const szMsg = ppString[0]; + const size_t len = strlen((char*)szMsg); + CHKiRet(sendMessage(pWrkrData->pData, pWrkrData->pChildCtx, szMsg)); + if(szMsg[len-1] != '\n') { + const time_t tt = time(NULL); + if(tt > pWrkrData->pData->block_if_err) { + LogMsg(0, NO_ERRCODE, LOG_WARNING, "omprog: messages must be terminated with \\n " + "at end of message, but this message is not: '%s'\n", ppString[0]); + pWrkrData->pData->block_if_err = tt + 30; + } + CHKiRet(sendMessage(pWrkrData->pData, pWrkrData->pChildCtx, (uchar*) "\n")); + } + + if(pWrkrData->pData->bConfirmMessages) { + CHKiRet(readStatus(pWrkrData->pData, pWrkrData->pChildCtx)); + } else if(pWrkrData->pData->bUseTransactions) { + /* ensure endTransaction will be called */ + iRet = RS_RET_DEFER_COMMIT; + } + +finalize_it: + if(pWrkrData->pData->bForceSingleInst) { + pthread_mutex_unlock(pWrkrData->pData->pSingleChildMut); + } +ENDdoAction + + +BEGINendTransaction +CODESTARTendTransaction + if(pWrkrData->pData->bForceSingleInst) { + CHKiConcCtrl(pthread_mutex_lock(pWrkrData->pData->pSingleChildMut)); + } + if(!pWrkrData->pData->bUseTransactions) { + FINALIZE; + } + + CHKiRet(sendMessage(pWrkrData->pData, pWrkrData->pChildCtx, + pWrkrData->pData->szCommitTransactionMark)); + CHKiRet(sendMessage(pWrkrData->pData, pWrkrData->pChildCtx, (uchar*) "\n")); + + if(pWrkrData->pData->bConfirmMessages) { + CHKiRet(readStatus(pWrkrData->pData, pWrkrData->pChildCtx)); + } + +finalize_it: + if(pWrkrData->pData->bForceSingleInst) { + pthread_mutex_unlock(pWrkrData->pData->pSingleChildMut); + } +ENDendTransaction + + +BEGINfreeWrkrInstance +CODESTARTfreeWrkrInstance + if(!pWrkrData->pData->bForceSingleInst) { + if(pWrkrData->pChildCtx->bIsRunning) { + terminateChild(pWrkrData->pData, pWrkrData->pChildCtx); + } + free(pWrkrData->pChildCtx); + } +ENDfreeWrkrInstance + + +BEGINfreeInstance + int i; +CODESTARTfreeInstance + if(pData->pSingleChildCtx != NULL) { + if(pData->pSingleChildCtx->bIsRunning) { + terminateChild(pData, pData->pSingleChildCtx); + } + free(pData->pSingleChildCtx); + } + + if(pData->pSingleChildMut != NULL) { + pthread_mutex_destroy(pData->pSingleChildMut); + free(pData->pSingleChildMut); + } + + if(pData->pOutputCaptureCtx != NULL) { + if(pData->pOutputCaptureCtx->bIsRunning) { + endOutputCapture(pData->pOutputCaptureCtx, pData->lCloseTimeout); + } + freeOutputCaptureCtx(pData->pOutputCaptureCtx); + } + + free(pData->szBinary); + free(pData->szTemplateName); + free(pData->szBeginTransactionMark); + free(pData->szCommitTransactionMark); + + if(pData->aParams != NULL) { + for (i = 0; i < pData->iParams; i++) { + free(pData->aParams[i]); + } + free(pData->aParams); + } +ENDfreeInstance + + +BEGINnewActInst + struct cnfparamvals *pvals; + int i; +CODESTARTnewActInst + if((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL) { + ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS); + } + + CHKiRet(createInstance(&pData)); + + for(i = 0 ; i < actpblk.nParams ; ++i) { + if(!pvals[i].bUsed) + continue; + if(!strcmp(actpblk.descr[i].name, "binary")) { + CHKiRet(split_binary_parameters(&pData->szBinary, &pData->aParams, &pData->iParams, + pvals[i].val.d.estr)); + } else if(!strcmp(actpblk.descr[i].name, "confirmMessages")) { + pData->bConfirmMessages = (int) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "confirmTimeout")) { + pData->lConfirmTimeout = (long) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "reportFailures")) { + pData->bReportFailures = (int) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "useTransactions")) { + pData->bUseTransactions = (int) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "beginTransactionMark")) { + pData->szBeginTransactionMark = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + } else if(!strcmp(actpblk.descr[i].name, "commitTransactionMark")) { + pData->szCommitTransactionMark = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + } else if(!strcmp(actpblk.descr[i].name, "forceSingleInstance")) { + pData->bForceSingleInst = (int) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "signalOnClose")) { + pData->bSignalOnClose = (int) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "closeTimeout")) { + pData->lCloseTimeout = (long) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "killUnresponsive")) { + pData->bKillUnresponsive = (int) pvals[i].val.d.n; + } else if(!strcmp(actpblk.descr[i].name, "hup.signal")) { + const char *const sig = es_str2cstr(pvals[i].val.d.estr, NULL); + if(!strcmp(sig, "HUP")) + pData->iHUPForward = SIGHUP; + else if(!strcmp(sig, "USR1")) + pData->iHUPForward = SIGUSR1; + else if(!strcmp(sig, "USR2")) + pData->iHUPForward = SIGUSR2; + else if(!strcmp(sig, "INT")) + pData->iHUPForward = SIGINT; + else if(!strcmp(sig, "TERM")) + pData->iHUPForward = SIGTERM; + else { + LogError(0, RS_RET_CONF_PARAM_INVLD, + "omprog: hup.signal '%s' in hup.signal parameter", sig); + ABORT_FINALIZE(RS_RET_CONF_PARAM_INVLD); + } + free((void*)sig); + } else if(!strcmp(actpblk.descr[i].name, "template")) { + pData->szTemplateName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + } else if(!strcmp(actpblk.descr[i].name, "output")) { + if(pData->pOutputCaptureCtx == NULL) { + CHKiRet(allocOutputCaptureCtx(&pData->pOutputCaptureCtx)); + } + pData->pOutputCaptureCtx->szFileName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + } else if(!strcmp(actpblk.descr[i].name, "fileCreateMode")) { + if(pData->pOutputCaptureCtx == NULL) { + CHKiRet(allocOutputCaptureCtx(&pData->pOutputCaptureCtx)); + } + pData->pOutputCaptureCtx->fCreateMode = (mode_t) pvals[i].val.d.n; + } else { + DBGPRINTF("omprog: program error, non-handled param '%s'\n", actpblk.descr[i].name); + } + } + + CODE_STD_STRING_REQUESTnewActInst(1) + CHKiRet(OMSRsetEntry(*ppOMSR, 0, (uchar*)strdup(pData->szTemplateName == NULL ? + "RSYSLOG_FileFormat" : (char*)pData->szTemplateName), OMSR_NO_RQD_TPL_OPTS)); + + iRet = postInitInstance(pData); + +CODE_STD_FINALIZERnewActInst + cnfparamvalsDestruct(pvals, &actpblk); +ENDnewActInst + + +BEGINparseSelectorAct +CODESTARTparseSelectorAct +CODE_STD_STRING_REQUESTparseSelectorAct(1) + /* first check if this config line is actually for us */ + if(strncmp((char*) p, ":omprog:", sizeof(":omprog:") - 1)) { + ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED); + } + + /* ok, if we reach this point, we have something for us */ + p += sizeof(":omprog:") - 1; /* eat indicator sequence (-1 because of '\0'!) */ + if(cs.szBinary == NULL) { + LogError(0, RS_RET_CONF_RQRD_PARAM_MISSING, "no binary to execute specified"); + ABORT_FINALIZE(RS_RET_CONF_RQRD_PARAM_MISSING); + } + + CHKiRet(createInstance(&pData)); + CHKmalloc(pData->szBinary = (uchar*) strdup((char*)cs.szBinary)); + + /* check if a non-standard template is to be applied */ + if(*(p-1) == ';') + --p; + CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, 0, (uchar*) "RSYSLOG_FileFormat")); + + iRet = postInitInstance(pData); + +CODE_STD_FINALIZERparseSelectorAct +ENDparseSelectorAct + + +BEGINdoHUP +CODESTARTdoHUP + if(pData->bForceSingleInst && pData->iHUPForward != NO_HUP_FORWARD && + pData->pSingleChildCtx->bIsRunning) { + DBGPRINTF("omprog: forwarding HUP to program '%s' (pid %ld) as signal %d\n", + pData->szBinary, (long) pData->pSingleChildCtx->pid, pData->iHUPForward); + kill(pData->pSingleChildCtx->pid, pData->iHUPForward); + } + + if(pData->pOutputCaptureCtx != NULL && pData->pOutputCaptureCtx->bIsRunning) { + closeOutputFile(pData->pOutputCaptureCtx); + } +ENDdoHUP + + +BEGINdoHUPWrkr +CODESTARTdoHUPWrkr + if(!pWrkrData->pData->bForceSingleInst && pWrkrData->pData->iHUPForward != NO_HUP_FORWARD && + pWrkrData->pChildCtx->bIsRunning) { + DBGPRINTF("omprog: forwarding HUP to program '%s' (pid %ld) as signal %d\n", + pWrkrData->pData->szBinary, (long) pWrkrData->pChildCtx->pid, + pWrkrData->pData->iHUPForward); + kill(pWrkrData->pChildCtx->pid, pWrkrData->pData->iHUPForward); + } +ENDdoHUPWrkr + + +BEGINmodExit +CODESTARTmodExit + free(cs.szBinary); + cs.szBinary = NULL; +ENDmodExit + + +BEGINqueryEtryPt +CODESTARTqueryEtryPt +CODEqueryEtryPt_STD_OMOD_QUERIES +CODEqueryEtryPt_STD_OMOD8_QUERIES +CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES +CODEqueryEtryPt_TXIF_OMOD_QUERIES /* we support the transactional interface */ +CODEqueryEtryPt_doHUP +CODEqueryEtryPt_doHUPWrkr +ENDqueryEtryPt + + +/* Reset legacy config variables for this module to default values. + */ +static rsRetVal +resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal) +{ + DEFiRet; + free(cs.szBinary); + cs.szBinary = NULL; + RETiRet; +} + +BEGINmodInit() +CODESTARTmodInit +INITLegCnfVars + *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ +CODEmodInit_QueryRegCFSLineHdlr + /* tell engine which objects we need */ + + /* check that rsyslog core supports transactional plugins */ + INITChkCoreFeature(bCoreSupportsBatching, CORE_FEATURE_BATCHING); + if (!bCoreSupportsBatching) { + LogError(0, NO_ERRCODE, "omprog: rsyslog core too old (does not support batching)"); + ABORT_FINALIZE(RS_RET_ERR); + } + + CHKiRet(omsdRegCFSLineHdlr((uchar *)"actionomprogbinary", 0, eCmdHdlrGetWord, NULL, &cs.szBinary, + STD_LOADABLE_MODULE_ID)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, + NULL, STD_LOADABLE_MODULE_ID)); +CODEmodInit_QueryRegCFSLineHdlr +ENDmodInit -- cgit v1.2.3