diff options
| author | Lucas Castro <lucas@gnuabordo.com.br> | 2024-01-11 12:07:59 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2024-06-05 19:00:29 -0300 |
| commit | a4676d0e2e75ebcadfb2c947f7a1fa39b8aea246 (patch) | |
| tree | 635a07582f6f525318bfed44c38bda264f65f28c | |
| parent | ca0774165e52cc2c08a6bac98ed3f8622842930e (diff) | |
New upstream version 1.0.8
| -rw-r--r-- | Makefile | 26 | ||||
| -rw-r--r-- | README | 14 | ||||
| -rw-r--r-- | default_script | 4 | ||||
| -rw-r--r-- | default_script.sample | 2 | ||||
| -rw-r--r-- | defs.h | 2 | ||||
| -rw-r--r-- | foolsm.c (renamed from lsm.c) | 13 | ||||
| -rw-r--r-- | foolsm.conf (renamed from lsm.conf) | 10 | ||||
| -rw-r--r-- | foolsm.conf.sample (renamed from lsm.conf.sample) | 12 | ||||
| -rw-r--r-- | foolsm.h (renamed from lsm.h) | 4 | ||||
| -rw-r--r-- | foolsm.init | 97 | ||||
| -rw-r--r-- | foolsm.service (renamed from lsm.service) | 4 | ||||
| -rw-r--r-- | foolsm.spec (renamed from lsm.spec) | 170 | ||||
| -rw-r--r-- | forkexec.c | 24 | ||||
| -rw-r--r-- | globals.c | 6 | ||||
| -rw-r--r-- | group_script | 6 | ||||
| -rw-r--r-- | lsm.init | 97 | ||||
| -rw-r--r-- | plugin_export.c | 12 | ||||
| -rw-r--r-- | plugin_export.h | 2 | ||||
| -rw-r--r-- | rsyslog-foolsm.conf.sample | 3 | ||||
| -rw-r--r-- | rsyslog-lsm.conf.sample | 3 | ||||
| -rw-r--r-- | save_statuses.c | 2 | ||||
| -rw-r--r-- | shorewall6_script | 1 | ||||
| -rw-r--r-- | shorewall_script | 1 | ||||
| -rw-r--r-- | usage.c | 4 |
24 files changed, 295 insertions, 224 deletions
@@ -4,12 +4,12 @@ # License: GPLv2 # -VERSION ?= $(lastword $(shell grep ^Version: lsm.spec)) -PROGS = lsm -PKG = lsm +VERSION ?= $(lastword $(shell grep ^Version: foolsm.spec)) +PROGS = foolsm +PKG = foolsm CC = gcc -override CFLAGS += -Wall -O2 -DLSM_VERSION=\"$(VERSION)\" +override CFLAGS += -Wall -O2 -DFOOLSM_VERSION=\"$(VERSION)\" #override CFLAGS += -D NO_PLUGIN_EXPORT #override CFLAGS += -D NO_PLUGIN_EXPORT_MUNIN #override CFLAGS += -D NO_PLUGIN_EXPORT_STATUS @@ -18,15 +18,15 @@ PREFIX ?= /usr/local DESTDIR ?= BINDIR ?= $(PREFIX)/sbin ifeq ($(PREFIX), /usr) -ETCDIR ?= /etc/lsm +ETCDIR ?= /etc/foolsm else -ETCDIR ?= $(PREFIX)/etc/lsm +ETCDIR ?= $(PREFIX)/etc/foolsm endif -DOCDIR ?= $(PREFIX)/share/doc/lsm +DOCDIR ?= $(PREFIX)/share/doc/foolsm EXAMPLEDIR ?= $(DOCDIR)/examples -SCRIPTDIR ?= $(PREFIX)/libexec/lsm +SCRIPTDIR ?= $(PREFIX)/libexec/foolsm -DOCFILES = README lsm.conf.sample default_script.sample rsyslog-lsm.conf.sample +DOCFILES = README foolsm.conf.sample default_script.sample rsyslog-foolsm.conf.sample SCRIPTS = shorewall_script shorewall6_script default_script group_script override CFLAGS += -D ETCDIR=\"$(ETCDIR)\" @@ -36,7 +36,7 @@ override CFLAGS += -D SCRIPTDIR=\"$(SCRIPTDIR)\" all: $(PROGS) -lsm: lsm.o icmp_t.o icmp6_t.o config.o globals.o cksum.o forkexec.o signal_handler.o timecalc.o plugin_export.o save_statuses.o pidfile.o cmdline.o usage.o +foolsm: foolsm.o icmp_t.o icmp6_t.o config.o globals.o cksum.o forkexec.o signal_handler.o timecalc.o plugin_export.o save_statuses.o pidfile.o cmdline.o usage.o clean distclean: rm -rf *~ .*~ *.o $(PROGS) debugfiles.list debuglinks.list debugsources.list *.orig @@ -57,9 +57,9 @@ rpm: tar install: all install -d $(DESTDIR)$(EXAMPLEDIR) install -d $(DESTDIR)$(SCRIPTDIR) - install -d $(DESTDIR)/var/lib/lsm - install -D -m0644 lsm.conf $(DESTDIR)$(ETCDIR)/lsm.conf - install -D -m0755 lsm $(DESTDIR)$(BINDIR)/lsm + install -d $(DESTDIR)/var/lib/foolsm + install -D -m0644 foolsm.conf $(DESTDIR)$(ETCDIR)/foolsm.conf + install -D -m0755 foolsm $(DESTDIR)$(BINDIR)/foolsm install -m0644 $(DOCFILES) $(DESTDIR)$(EXAMPLEDIR) install -m0755 $(SCRIPTS) $(DESTDIR)$(SCRIPTDIR) @@ -6,7 +6,7 @@ License: GPLv2 You should be able to find GNU Public License from www.gnu.org. -LSM is a Link Status Monitor which can be used to monitor +Foolsm is a Link Status Monitor which can be used to monitor for example a Linux router/firewall connectivity and if you happen to have multiple connections it can change routing when an up/down event happens by utilizing external @@ -38,9 +38,9 @@ TODO DECISION MAKING =============== -As of lsm v0.27, the detection algorithm works like this: +As of foolsm v0.27, the detection algorithm works like this: -LSM keeps track of +Foolsm keeps track of 1) the result of the most recent pings (up to 100) 2) the number of consecutive lost pings. 3) the number of consecutive received pings. @@ -57,7 +57,7 @@ Else If connection (or group) is DOWN AND ( (A <= min_packet_loss) AND (C > min_successive_pkts_rcved) ) then change the connection (or group) to up. -Note: LSM assumes each connection starts UP. +Note: Foolsm assumes each connection starts UP. DEPENDENCIES @@ -71,7 +71,7 @@ INSTALLING ========== There is now Makefile target install for those of you not using rpms. I use only -rpm based distros so that may not be in sync with lsm.spec which does all what +rpm based distros so that may not be in sync with foolsm.spec which does all what I need. @@ -80,6 +80,4 @@ AUTHORS Mika Ilmaranta <ilmis@nullnet.fi> -See lsm.spec's changelog section for patch submitters. - -#EOF +See foolsm.spec's changelog section for patch submitters. diff --git a/default_script b/default_script index 2fe3e7c..b736053 100644 --- a/default_script +++ b/default_script @@ -33,7 +33,7 @@ fi DATE=$(date --date=@${TIMESTAMP}) -cat <<EOM | mail -s "LSM: ${NAME} ${STATE}, IP ${CHECKIP}" ${WARN_EMAIL} +cat <<EOM | mail -s "Foolsm: ${NAME} ${STATE}, IP ${CHECKIP}" ${WARN_EMAIL} Hi, @@ -59,7 +59,7 @@ cons_miss = ${CONS_MISS} consecutive packets that have timed out avg_rtt = ${AVG_RTT} average rtt [usec], calculated from received packets BR, -Your LSM installation +Your Foolsm installation EOM diff --git a/default_script.sample b/default_script.sample index e602859..70a8f7f 100644 --- a/default_script.sample +++ b/default_script.sample @@ -2,7 +2,7 @@ # You can call a set of scripts like so on an event -cd /etc/lsm/script.d +cd /etc/foolsm/script.d for script in $(ls); do if [ ! -x $script ]; then continue @@ -22,7 +22,7 @@ License: GPLv2 #define min(x, y) ((x)<(y) ? (x) : (y)) -#define PLUGIN_EXPORT_DIR "/var/lib/lsm" +#define PLUGIN_EXPORT_DIR "/var/lib/foolsm" #endif @@ -44,7 +44,7 @@ License: GPLv2 #include "signal_handler.h" #include "forkexec.h" #include "timecalc.h" -#include "lsm.h" +#include "foolsm.h" #ifndef NO_PLUGIN_EXPORT #include "plugin_export.h" #endif @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) { struct timeval last_sent_time = {0, 0}; int start = 0; - openlog("lsm", LOG_PID, LOG_DAEMON); + openlog("foolsm", LOG_PID, LOG_DAEMON); cmdline_parse(argc, argv); @@ -1402,7 +1402,7 @@ static int ping_send(CONFIG *cur) { seq = t->seq % FOLLOWED_PKTS; #if defined(DEBUG) - fprintf(stderr, "ping_send seq = %ld to %s, num_sent = %ld, %ld, pkt_size = %d\n", t->seq, inet_ntoa(t->saddr.sin_addr), t->num_sent, pdp->ping_count, ping_pkt_size); + fprintf(stderr, "ping_send seq = %d to %s, num_sent = %ld, %ld, pkt_size = %d\n", t->seq, inet_ntoa(t->dst_addr.sin_addr), t->num_sent, pdp->ping_count, ping_pkt_size); #endif t->sentpkts[seq].seq = t->seq; t->sentpkts[seq].sent_time = t->last_send_time; @@ -1470,7 +1470,7 @@ static int ping_send(CONFIG *cur) { seq = t->seq % FOLLOWED_PKTS; #if defined(DEBUG) - fprintf(stderr, "ping_send seq = %ld to %s, num_sent = %ld, %ld, pkt_size = %d\n", t->seq, inet_ntoa(t->saddr.sin_addr), t->num_sent, pdp->ping_count, ping_pkt_size); + fprintf(stderr, "ping_send seq = %d to %s, num_sent = %ld, %ld, pkt_size = %d\n", t->seq, inet_ntoa(t->dst_addr.sin_addr), t->num_sent, pdp->ping_count, ping_pkt_size); #endif t->sentpkts[seq].seq = t->seq; t->sentpkts[seq].sent_time = t->last_send_time; @@ -1585,6 +1585,11 @@ static void init_config_data(CONFIG *first, CONFIG *last, CONFIG ***ctable) t->dst_addr.sin_family = AF_INET; t->dst_addr.sin_addr = *((struct in_addr *)&ipaddress); t->dst = *((struct in_addr *)&ipaddress); + if(cur->srcinfo) { + if(inet_pton(AF_INET, cur->sourceip, &t->src) != 1) { + syslog(LOG_ERR, "%s: %s: src inet_pton failed for %s", __FILE__, __FUNCTION__, cur->name); + } + } } } @@ -20,7 +20,7 @@ # name=defaults # checkip=127.0.0.1 # eventscript= -# notifyscript=/usr/libexec/lsm/default_script +# notifyscript=/usr/libexec/foolsm/default_script # max_packet_loss=15 # max_successive_pkts_lost=7 # min_packet_loss=5 @@ -36,7 +36,7 @@ # device=eth0 # use system default ttl # ttl=0 -# assume initial up state at lsm startup +# assume initial up state at foolsm startup # (1 = up, 0 = down, 2 = unknown (default)) # status=1 # how many packets have to go through before a connection is declared up @@ -48,9 +48,7 @@ #} # -# Some example connections are found in lsm.conf.sample +# Some example connections are found in foolsm.conf.sample # --include /etc/lsm/local*.conf - -#EOF +-include /etc/foolsm/local*.conf diff --git a/lsm.conf.sample b/foolsm.conf.sample index 9a6f187..0d071f6 100644 --- a/lsm.conf.sample +++ b/foolsm.conf.sample @@ -18,7 +18,7 @@ debug=8 defaults { name=defaults checkip=127.0.0.1 - eventscript=/usr/libexec/lsm/default_script + eventscript=/usr/libexec/foolsm/default_script max_packet_loss=15 max_successive_pkts_lost=7 min_packet_loss=5 @@ -34,7 +34,7 @@ defaults { # device=eth0 # use system default ttl ttl=0 -# assume initial up state at lsm startup (1 = up, 0 = down, 2 = unknown (default)) +# assume initial up state at foolsm startup (1 = up, 0 = down, 2 = unknown (default)) # status=1 } @@ -45,7 +45,7 @@ defaults { # connection { # name=connection-1 # checkip=127.108.68.69 -# eventscript=/usr/libexec/lsm/conn1 +# eventscript=/usr/libexec/foolsm/conn1 # max_packet_loss=15 # max_successive_pkts_lost=7 # min_packet_loss=5 @@ -62,7 +62,7 @@ defaults { # connection { # name=connection-2 # checkip=127.108.68.65 -# eventscript=/usr/libexec/lsm/conn2 +# eventscript=/usr/libexec/foolsm/conn2 # max_packet_loss=15 # max_successive_pkts_lost=7 # min_packet_loss=5 @@ -79,7 +79,7 @@ defaults { # connection { # name=connection-3 # checkip=127.108.68.68 -# eventscript=/usr/libexec/lsm/conn3 +# eventscript=/usr/libexec/foolsm/conn3 # max_packet_loss=15 # max_successive_pkts_lost=7 # min_packet_loss=5 @@ -140,5 +140,3 @@ defaults { # member-connection=conn-a # member-connection=conn-b # } - -#EOF @@ -6,8 +6,8 @@ License: GPLv2 */ -#ifndef __LSM_H__ -#define __LSM_H__ +#ifndef __FOOLSM_H__ +#define __FOOLSM_H__ #include <netinet/in.h> /* for struct sockaddr_in */ #include <linux/if_arp.h> /* for struct sockadd_ll */ diff --git a/foolsm.init b/foolsm.init new file mode 100644 index 0000000..e9e12ea --- /dev/null +++ b/foolsm.init @@ -0,0 +1,97 @@ +#!/bin/sh +# +# /etc/init.d/foolsm +# +# This shellscript takes care of starting and stopping foolsm. +# +# chkconfig: - 79 31 +# description: Foolsm, Link Status Monitor +# +### BEGIN INIT INFO +# Provides: foolsm +# Required-Start: $network $syslog +# Required-Stop: +# Default-Stop: 0 1 6 +# Short-Description: Foolsm - link status monitor +# Description: Foolsm is the link status monitor +# Foolsm can ping multiple targets and when up or down event happens +# it will execute user configured external script so it can be used +# as poor man's routing protocol. +### END INIT INFO + +# Source function library. +. /etc/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +# Check that networking is up. +[ ${NETWORKING} = "no" ] && exit 0 + +CONFIGFILE="/etc/foolsm/foolsm.conf" +PIDFILE="/var/run/foolsm.pid" + +[ -f /etc/sysconfig/foolsm ] && . /etc/sysconfig/foolsm +[ -x /usr/sbin/foolsm ] || exit 0 + +RETVAL=0 + +start() { + echo -n $"Starting foolsm: " + daemon --pidfile=${PIDFILE} /usr/sbin/foolsm --config $CONFIGFILE --pidfile $PIDFILE + RETVAL=$? + /bin/usleep 10000 + echo + [ $RETVAL = 0 ] && touch /var/lock/subsys/foolsm + return $RETVAL +} + +stop() { + echo -n $"Stopping foolsm: " + killproc /usr/sbin/foolsm + RETVAL=$? + echo + [ $RETVAL = 0 ] && rm -f /var/lock/subsys/foolsm + return $RETVAL +} + +restart() { + stop + start +} + +reload() { + echo -n $"Reloading foolsm: " + killproc -p ${PIDFILE} /usr/sbin/foolsm -HUP + RETVAL=$? + echo + return $RETVAL +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + reload) + reload + ;; + condrestart) + [ -f /var/lock/subsys/foolsm ] && restart + ;; + status) + status -p ${PIDFILE} foolsm + RETVAL=$? + ;; + *) + echo "Usage: foolsm {start|stop|restart|condrestart|status}" + RETVAL=2 +esac + +exit $RETVAL diff --git a/lsm.service b/foolsm.service index 4b3ed8c..7c74717 100644 --- a/lsm.service +++ b/foolsm.service @@ -1,12 +1,12 @@ [Unit] -Description=LSM is the link status monitor +Description=Foolsm is the link status monitor Documentation=http://lsm.foobar.fi/ Wants=network-online.target After=network-online.target shorewall.service shorewall6.service [Service] Type=simple -ExecStart=/usr/sbin/lsm --config /etc/lsm/lsm.conf --no-fork +ExecStart=/usr/sbin/foolsm --config /etc/foolsm/foolsm.conf --no-fork ExecReload=/bin/kill -HUP $MAINPID Restart=on-abort @@ -1,39 +1,45 @@ #define devel 1 +%if 0%{?rhel} >= 7 || 0%{?fedora} +%bcond_without systemd # enabled +%else +%bcond_with systemd # disabled +%endif -Summary: The Link Status Monitor -Name: lsm -Version: 1.0.5 +Summary: The Foobar Link Status Monitor +Name: foolsm +Version: 1.0.8 Release: 1%{?dist} License: GPLv2 -Group: System Environment/Daemons URL: http://lsm.foobar.fi/ -Source: %{name}-%{version}.tar.gz -%if 0%{?rhel} >= 7 || 0%{?fedora} -%bcond_without systemd # enabled -Requires(post): systemd -Requires(preun): systemd -Requires(postun): systemd +Source0: %{name}-%{version}.tar.gz +%if %{with systemd} +Requires(post): systemd-units +Requires(preun): systemd-units +Requires(postun): systemd-units BuildRequires: systemd %else -%bcond_with systemd # disabled Requires(post): chkconfig Requires(postun): /sbin/service Requires(preun): /sbin/service Requires(preun): chkconfig %endif -%if 0%{?rhel} && 0%{?rhel} <= 5 -%global _sharedstatedir /var/lib -%endif Requires: mailx %if 0%{?devel} BuildRequires: ElectricFence %endif +%if 0%{?rhel} && 0%{?rhel} <= 5 +Group: System Environment/Daemons +%global _sharedstatedir /var/lib BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +%endif +Obsoletes: lsm < 1.0.7-1 +Conflicts: lsm < 1.0.7-1 +Provides: lsm = %{version}-%{release} %description -Lsm is the link status monitor. +Foolsm is the Foobar Link Status Monitor. -Lsm can ping multiple targets and when up or down event happens +Foolsm can ping multiple targets and when up or down event happens it will execute user configured external script so it can be used as poor man's routing protocol. @@ -52,82 +58,140 @@ make PREFIX=%{_prefix} CFLAGS="$RPM_OPT_FLAGS" LDFLAGS=${EFENCE} %{?_smp_mflags} %install rm -rf %{buildroot} -mkdir -p %{buildroot}%{_sysconfdir}/lsm +mkdir -p %{buildroot}%{_sysconfdir}/foolsm mkdir -p %{buildroot}%{_sbindir} -mkdir -p %{buildroot}%{_libexecdir}/lsm -mkdir -p %{buildroot}%{_sharedstatedir}/lsm +mkdir -p %{buildroot}%{_libexecdir}/foolsm +mkdir -p %{buildroot}%{_sharedstatedir}/foolsm -install -m0755 lsm %{buildroot}%{_sbindir} -install -m0644 lsm.conf %{buildroot}%{_sysconfdir}/lsm +install -m0755 foolsm %{buildroot}%{_sbindir} +install -m0644 foolsm.conf %{buildroot}%{_sysconfdir}/foolsm install -m0755 default_script group_script shorewall_script shorewall6_script \ - %{buildroot}%{_libexecdir}/lsm/ + %{buildroot}%{_libexecdir}/foolsm/ %if %{with systemd} mkdir -p %{buildroot}%{_unitdir} -install -m0644 lsm.service %{buildroot}%{_unitdir}/ +install -m0644 foolsm.service %{buildroot}%{_unitdir}/ %else mkdir -p %{buildroot}%{_initrddir} -install -m0755 lsm.init %{buildroot}%{_initrddir}/lsm -# Compat symlinks for older system versions -mkdir -p %{buildroot}%{_datadir}/lsm -ln -s ../../libexec/lsm/shorewall_script \ - %{buildroot}%{_datadir}/lsm/ -ln -s ../../libexec/lsm/default_script \ - %{buildroot}%{_datadir}/lsm/ +install -m0755 foolsm.init %{buildroot}%{_initrddir}/foolsm %endif %clean rm -rf %{buildroot} +%triggerun -- lsm < 1.0.7-1 +%if %{with systemd} +systemctl --quiet is-enabled lsm.service && \ + touch %{_localstatedir}/lock/subsys/lsm.enabled || : +systemctl --quiet is-active lsm.service && \ + touch %{_localstatedir}/lock/subsys/lsm.started || : +%else +/sbin/chkconfig lsm >/dev/null 2>&1 && \ + touch %{_localstatedir}/lock/subsys/lsm.enabled || : +/sbin/service lsm status >/dev/null 2>&1 && \ + touch %{_localstatedir}/lock/subsys/lsm.started || : +%endif +for config in %{_sysconfdir}/lsm/lsm.conf \ + %{_sysconfdir}/lsm/local*.conf \ + %{_sysconfdir}/lsm/*_script +do + [ -f ${config} ] && \ + cp -p ${config} %{_sysconfdir}/foolsm/ +done +if [ -f %{_sysconfdir}/foolsm/lsm.conf ]; then + mv -f %{_sysconfdir}/foolsm/foolsm.conf \ + %{_sysconfdir}/foolsm/foolsm.conf.rpmnew + echo "warning: %{_sysconfdir}/foolsm/foolsm.conf created as %{_sysconfdir}/foolsm/foolsm.conf.rpmnew" + mv -f %{_sysconfdir}/foolsm/lsm.conf %{_sysconfdir}/foolsm/foolsm.conf +fi +for config in %{_sysconfdir}/foolsm/*.conf; do + sed --in-place=.rpmsave \ + -e 's@/etc/lsm/@/etc/foolsm/@g' \ + -e 's@%{_datadir}/lsm/@%{_libexecdir}/foolsm/@g' \ + -e 's@%{_libexecdir}/lsm/@%{_libexecdir}/foolsm/@g' \ + ${config} >/dev/null 2>&1 || : +done + +%triggerpostun -- lsm < 1.0.7-1 +%if %{with systemd} +if [ -f %{_localstatedir}/lock/subsys/lsm.enabled ]; then + systemctl enable foolsm.service >/dev/null 2>&1 || : + rm -f %{_localstatedir}/lock/subsys/lsm.enabled +fi +if [ -f %{_localstatedir}/lock/subsys/lsm.started ]; then + systemctl start foolsm.service >/dev/null 2>&1 || : + rm -f %{_localstatedir}/lock/subsys/lsm.started +fi +%else +/sbin/chkconfig --add foolsm +if [ -f %{_localstatedir}/lock/subsys/lsm.enabled ]; then + /sbin/chkconfig foolsm on + rm -f %{_localstatedir}/lock/subsys/lsm.enabled +fi +if [ -f %{_localstatedir}/lock/subsys/lsm.started ]; then + /sbin/service foolsm restart >/dev/null 2>&1 + rm -f %{_localstatedir}/lock/subsys/lsm.started +fi +%endif + %post %if %{with systemd} -%systemd_post lsm.service +%systemd_post foolsm.service %else -/sbin/chkconfig --add lsm +/sbin/chkconfig --add foolsm %endif %preun %if %{with systemd} -%systemd_preun lsm.service +%systemd_preun foolsm.service %else if [ $1 -eq 0 ]; then - /sbin/service lsm stop >/dev/null 2>&1 || : - /sbin/chkconfig --del lsm + /sbin/service foolsm stop >/dev/null 2>&1 || : + /sbin/chkconfig --del foolsm fi %endif %postun %if %{with systemd} -%systemd_postun_with_restart lsm.service +%systemd_postun_with_restart foolsm.service %else if [ $1 -ge 1 ]; then - /sbin/service lsm condrestart >/dev/null 2>&1 || : + /sbin/service foolsm condrestart >/dev/null 2>&1 || : fi %endif %files -%defattr(-,root,root) -%doc README lsm.conf.sample default_script.sample rsyslog-lsm.conf.sample +%defattr(-,root,root,-) +%doc README foolsm.conf.sample default_script.sample rsyslog-foolsm.conf.sample %if %{with systemd} -%{_unitdir}/lsm.service +%{_unitdir}/foolsm.service %else -%{_initrddir}/lsm -%dir %{_datadir}/lsm -%{_datadir}/lsm/default_script -%{_datadir}/lsm/shorewall_script +%{_initrddir}/foolsm %endif -%dir %{_libexecdir}/lsm -%{_libexecdir}/lsm/default_script -%{_libexecdir}/lsm/group_script -%{_libexecdir}/lsm/shorewall_script -%{_libexecdir}/lsm/shorewall6_script -%dir %{_sysconfdir}/lsm -%config(noreplace) %{_sysconfdir}/lsm/lsm.conf -%{_sbindir}/lsm -%dir %{_sharedstatedir}/lsm +%dir %{_libexecdir}/foolsm +%{_libexecdir}/foolsm/default_script +%{_libexecdir}/foolsm/group_script +%{_libexecdir}/foolsm/shorewall_script +%{_libexecdir}/foolsm/shorewall6_script +%dir %{_sysconfdir}/foolsm +%config(noreplace) %{_sysconfdir}/foolsm/foolsm.conf +%{_sbindir}/foolsm +%dir %{_sharedstatedir}/foolsm %changelog +* Wed Sep 9 2016 Mika Ilmaranta <ilmis@nullnet.fi> - 1.0.8-1 +- foolsm.spec: triggers to move old lsm config for foolsm +- fix forever loop in waitpid while loop + +* Wed Sep 7 2016 Mika Ilmaranta <ilmis@nullnet.fi> - 1.0.7-1 +- project name changed to foolsm due to conflicting path(s) with + libstoragemgmt + +* Wed Sep 7 2016 Mika Ilmaranta <ilmis@nullnet.fi> - 1.0.6-1 +- patches from Andrew Timonin, better handling of waitpid, debug message + fixes and ipv4 srcinfo handling + * Fri May 13 2016 Mika Ilmaranta <ilmis@nullnet.fi> - 1.0.5-1 - patches from Lucas de Castro Borges for Debian - exept for POSIX compliancy scriptdir PREFIX/libexec/lsm @@ -86,6 +86,8 @@ void create_sigchld_hdl(void) memset (&act, 0, sizeof(act)); act.sa_handler = sigchld_hdl; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_RESTART | SA_NOCLDSTOP; if (sigaction(SIGCHLD, &act, 0)) { syslog(LOG_ERR, "%s: %s: %d: failed to set up child signal handler: %s", __FILE__, __FUNCTION__, __LINE__, strerror(errno)); return; @@ -102,16 +104,24 @@ static void sigchld_hdl(int sig) /* Wait for the dead process. * We use a non-blocking call to be sure this signal handler will not * block if a child was cleaned up in another part of the program. */ - int exitval; + int saved_errno = errno; + int script_status; pid_t pid; - if((pid = waitpid(-1, &exitval, WNOHANG)) == -1) { - if(cfg.debug >= 9 && errno != ECHILD) syslog(LOG_ERR, "%s: %s: %d: waitpid failed %s", __FILE__, __FUNCTION__, __LINE__, strerror(errno)); - } else { - if(cfg.debug >= 9 && exitval) syslog(LOG_ERR, "%s: %s: %d: child script with pid %d exited with non null exit value %d", __FILE__, __FUNCTION__, __LINE__, pid, exitval); - else if(cfg.debug >= 9) syslog(LOG_ERR, "%s: %s: %d: child script with pid %d exited successfully", __FILE__, __FUNCTION__, __LINE__, pid); - exec_queue_delete(pid); + while ((pid = waitpid(WAIT_ANY, &script_status, WNOHANG)) != 0) { + if(pid == -1) { + if(cfg.debug >= 9 && errno != ECHILD) + syslog(LOG_ERR, "%s: %s: %d: waitpid failed %s", __FILE__, __FUNCTION__, __LINE__, strerror(errno)); + break; + } else { + if(cfg.debug >= 9 && WEXITSTATUS(script_status)) + syslog(LOG_ERR, "%s: %s: %d: child script with pid %d exited with non null exit value %d", __FILE__, __FUNCTION__, __LINE__, pid, WEXITSTATUS(script_status)); + else if(cfg.debug >= 9) + syslog(LOG_ERR, "%s: %s: %d: child script with pid %d exited successfully", __FILE__, __FUNCTION__, __LINE__, pid); + exec_queue_delete(pid); + } } + errno = saved_errno; } void exec_queue_add(char *queue, char **argv, char **envp) @@ -12,7 +12,7 @@ License: GPLv2 #include "globals.h" #include "defs.h" -#define LSM_CONFIG_FILE ETCDIR "/lsm.conf" +#define FOOLSM_CONFIG_FILE ETCDIR "/foolsm.conf" static char *prog = NULL; static int cont = TRUE; @@ -20,8 +20,8 @@ static int dump = FALSE; static int ident = 0; static int reload_cfg = FALSE; static int dump_if_list = FALSE; -static char *configfile = LSM_CONFIG_FILE; -static char *pidfile = "/var/run/lsm.pid"; +static char *configfile = FOOLSM_CONFIG_FILE; +static char *pidfile = "/var/run/foolsm.pid"; static int nodaemon = 0; static char *status_str[] = { "down", "up", "unknown", "long_down" }; diff --git a/group_script b/group_script index 7010492..c50887f 100644 --- a/group_script +++ b/group_script @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2012,2015 Tuomo Soini <tis@foobar.fi> +# Copyright (C) 2012-2016 Tuomo Soini <tis@foobar.fi> # # License: GPLv2 # @@ -32,7 +32,7 @@ fi DATE=$(date --date=@${TIMESTAMP}) -cat <<EOM | mail -s "LSM: ${NAME} ${STATE}" ${WARN_EMAIL} +cat <<EOM | mail -s "Foolsm: ${NAME} ${STATE}" ${WARN_EMAIL} Hi, @@ -47,7 +47,7 @@ warn_email = ${WARN_EMAIL} Packet statuses are not available for groups. BR, -Your LSM installation +Your Foolsm installation EOM diff --git a/lsm.init b/lsm.init deleted file mode 100644 index eb4f868..0000000 --- a/lsm.init +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/sh -# -# /etc/init.d/lsm -# -# This shellscript takes care of starting and stopping lsm. -# -# chkconfig: - 79 31 -# description: Lsm, Link Status Monitor -# -### BEGIN INIT INFO -# Provides: lsm -# Required-Start: $network $syslog -# Required-Stop: -# Default-Stop: 0 1 6 -# Short-Description: LSM - link status monitor -# Description: LSM is the link status monitor -# LSM can ping multiple targets and when up or down event happens -# it will execute user configured external script so it can be used -# as poor man's routing protocol. -### END INIT INFO - -# Source function library. -. /etc/init.d/functions - -# Source networking configuration. -. /etc/sysconfig/network - -# Check that networking is up. -[ ${NETWORKING} = "no" ] && exit 0 - -CONFIGFILE="/etc/lsm/lsm.conf" -PIDFILE="/var/run/lsm.pid" - -[ -f /etc/sysconfig/lsm ] && . /etc/sysconfig/lsm -[ -x /usr/sbin/lsm ] || exit 0 - -RETVAL=0 - -start() { - echo -n $"Starting lsm: " - daemon --pidfile=${PIDFILE} /usr/sbin/lsm --config $CONFIGFILE --pidfile $PIDFILE - RETVAL=$? - /bin/usleep 10000 - echo - [ $RETVAL = 0 ] && touch /var/lock/subsys/lsm - return $RETVAL -} - -stop() { - echo -n $"Stopping lsm: " - killproc /usr/sbin/lsm - RETVAL=$? - echo - [ $RETVAL = 0 ] && rm -f /var/lock/subsys/lsm - return $RETVAL -} - -restart() { - stop - start -} - -reload() { - echo -n $"Reloading lsm: " - killproc -p ${PIDFILE} /usr/sbin/lsm -HUP - RETVAL=$? - echo - return $RETVAL -} - -# See how we were called. -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - reload) - reload - ;; - condrestart) - [ -f /var/lock/subsys/lsm ] && restart - ;; - status) - status -p ${PIDFILE} lsm - RETVAL=$? - ;; - *) - echo "Usage: lsm {start|stop|restart|condrestart|status}" - RETVAL=2 -esac - -exit $RETVAL diff --git a/plugin_export.c b/plugin_export.c index b2a9f82..a6db219 100644 --- a/plugin_export.c +++ b/plugin_export.c @@ -67,9 +67,9 @@ static void plugin_export_munin(CONFIG *first) return; } - fprintf(fp, "graph_title LSM Average Ping Latency\n"); + fprintf(fp, "graph_title Foolsm Average Ping Latency\n"); fprintf(fp, "graph_vlabel ms\n"); - fprintf(fp, "graph_info This graph shows LSM status\n"); + fprintf(fp, "graph_info This graph shows Foolsm status\n"); fprintf(fp, "graph_category network\n"); fprintf(fp, "graph_args --base 1000 -l 0\n"); @@ -107,9 +107,9 @@ static void plugin_export_munin(CONFIG *first) return; } - fprintf(fp, "graph_title LSM packet counts\n"); + fprintf(fp, "graph_title Foolsm packet counts\n"); fprintf(fp, "graph_vlabel percent\n"); - fprintf(fp, "graph_info This graph shows LSM status\n"); + fprintf(fp, "graph_info This graph shows Foolsm status\n"); fprintf(fp, "graph_category network\n"); fprintf(fp, "graph_args --base 1000 -l 0\n"); @@ -177,9 +177,9 @@ static void plugin_export_munin(CONFIG *first) return; } - fprintf(fp, "graph_title LSM connection statuses\n"); + fprintf(fp, "graph_title Foolsm connection statuses\n"); fprintf(fp, "graph_vlabel Status\n"); - fprintf(fp, "graph_info This graph shows LSM connection statuses\n"); + fprintf(fp, "graph_info This graph shows Foolsm connection statuses\n"); fprintf(fp, "graph_category network\n"); fprintf(fp, "graph_info Status: 0 = DOWN, 1 = UP, 2 = UNKNOWN, 3 = LONG_DOWN\n"); fprintf(fp, "graph_args --base 1000 --lower-limit 0 --upper-limit 3\n"); diff --git a/plugin_export.h b/plugin_export.h index 79c714b..22a6c95 100644 --- a/plugin_export.h +++ b/plugin_export.h @@ -12,7 +12,7 @@ License: GPLv2 #define __PLUGIN_EXPORT_H__ #include "config.h" -#include "lsm.h" +#include "foolsm.h" void plugin_export_init(void); void plugin_export(CONFIG *first); diff --git a/rsyslog-foolsm.conf.sample b/rsyslog-foolsm.conf.sample new file mode 100644 index 0000000..b35b089 --- /dev/null +++ b/rsyslog-foolsm.conf.sample @@ -0,0 +1,3 @@ +# Foobar Link Status Monitor Log file +if $programname == 'foolsm' then /var/log/foolsm.log +if $programname == 'foolsm' then ~ diff --git a/rsyslog-lsm.conf.sample b/rsyslog-lsm.conf.sample deleted file mode 100644 index a0da81c..0000000 --- a/rsyslog-lsm.conf.sample +++ /dev/null @@ -1,3 +0,0 @@ -# Link Status Monitor Log file -if $programname == 'lsm' then /var/log/lsm.log -if $programname == 'lsm' then ~ diff --git a/save_statuses.c b/save_statuses.c index d1178a4..a3aec0c 100644 --- a/save_statuses.c +++ b/save_statuses.c @@ -11,7 +11,7 @@ License: GPLv2 #include <string.h> #include "config.h" -#include "lsm.h" +#include "foolsm.h" #include "save_statuses.h" typedef struct status_data { diff --git a/shorewall6_script b/shorewall6_script index b6d59c7..fad9afb 100644 --- a/shorewall6_script +++ b/shorewall6_script @@ -49,4 +49,3 @@ else fi exit 0 -# diff --git a/shorewall_script b/shorewall_script index b9aa859..3144480 100644 --- a/shorewall_script +++ b/shorewall_script @@ -50,4 +50,3 @@ else fi exit 0 -# @@ -14,8 +14,8 @@ #include "usage.h" void usage_and_exit(void) { -#if defined(LSM_VERSION) - printf("%s version %s\n", get_prog(), LSM_VERSION); +#if defined(FOOLSM_VERSION) + printf("%s version %s\n", get_prog(), FOOLSM_VERSION); #endif printf("usage: %s\n" " [-h|--help|-v|--version]\n" |
