Subject: bug#499: Smokeping service unable to stop/restart

From: ShadowM00n <[email-masked]>
Date: Mon, 27 Jul 2020 12:46:15 -0500

Package: smokeping
Version: 2.7.3-2

First-time submitter, so please excuse and correct me on any procedural 
errors on my part.

Basically, the current version of smokeping's init service quietly fails 
to stop smokeping, and then subsequently fails to restart it because the 
process is still running.

My understanding is that between ASCII and Beowulf the service was 
altered in an attempt to improve security. In ASCII, it checked only 
that a process with a saved PID existed; in Beowulf it also tries to 
compare the invocation string to the program string in the process list. 

While this seems a reasonable idea for most daemons, smokeping seems to 
be a bit of an exception -- it runs under an interpreter (perl), and as 
such the stored PID refers to the perl process launching it; naturally, 
the process string differs from the invocation, being e.g.
"/usr/bin/perl /usr/sbin/smokeping --config=/etc/smokeping/config" while 
being launched as "/usr/sbin/smokeping --config=/etc/smokeping/config".

Given this complication, my current personal setup, and my suggestion, 
is to instead check the owner of the process against the $DAEMON_USER 
when stopping, as this is configured to be a package-specific user 
called "smokeping":

< start-stop-daemon --oknodo --stop --retry 3 --quiet --pidfile $PIDFILE --exec $DAEMON --signal 15
> start-stop-daemon --oknodo --stop --retry 3 --quiet --pidfile $PIDFILE --user $DAEMON_USER --signal 15

This seems to work well for me, though I would certainly not be opposed 
to any other working method if this is less than ideal for some reason.

---

From: Mark Hindley <[email-masked]>
Date: Tue, 28 Jul 2020 11:04:04 +0100

Control: tags -1 debian

> First-time submitter, so please excuse and correct me on any procedural 

Thanks for taking the time to report this.

> compare the invocation string to the program string in the process list. 

Your analysis seems resonable.

In Devuan this package is used directly from Debian without recompilation. In
general for packages in that category, the bug reports should go to Debian's BTS
to be fixed there as the bug will also be present in Debian.

Please could you report to [email-masked]? Once you have we can add the
forwarded bug number/URL here.

Thanks.

Mark

---

From: ShadowM00n <[email-masked]>
Date: Tue, 28 Jul 2020 12:45:04 -0500

> forwarded bug number/URL here.

I was going to do so, but I don't think this actually affects Debian.

I wanted to be sure before filing a bug with them, so I set up two VMs, 
one with stock Buster and one with stock Beowulf, both installed from 
netinstall images and without a DE. I found that despite the init files 
being identical (confirmed with md5sum) and the versions of both 
packages being 2.7.3-2 (confirmed with dpkg -s smokeping | grep 
Version), the behaviour is not -- the service actually stops correctly 
on Debian and fails to stop on Beowulf. I took a side-by-side screenshot 
showcasing all of this for reference. I can include it if it's deemed 
useful, though I'm not sure it is beyond merely confirming what I just 
wrote.

I am now uncertain how accurate my earlier analysis was given that the 
Debian system worked without my fix. Any suggestions on what else should 
be looked at?

---

From: "Devuan bug Tracking System" <[email-masked]>
Date: Wed, 11 Jan 2023 12:16:02 +0000

This is an automatic notification regarding your bug report
which was filed against the smokeping package:

#499: Smokeping service unable to stop/restart

It has been closed by Mark Hindley <[email-masked]>.

Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Mark Hindley <[email-masked]> by
replying to this email.

-- 
499: https://bugs.devuan.org/cgi/bugreport.cgi?bug=499
Devuan Bug Tracking System
Contact [email-masked] with problems

Subject: Fixed in Debian #989354
From: Mark Hindley <[email-masked]>
To: [email-masked]
Date: Wed, 11 Jan 2023 12:14:13 +0000

Version: 2.7.3-4

Subject: Smokeping service unable to stop/restart
From: ShadowM00n <[email-masked]>
To: [email-masked]
Date: Mon, 27 Jul 2020 12:46:15 -0500

Package: smokeping
Version: 2.7.3-2

---

From: "Devuan bug Tracking System" <[email-masked]>
Date: Wed, 11 Jan 2023 12:16:04 +0000

#699: smokeping: Init script fails to stop smokeping

Version: 2.7.3-4

Subject: smokeping: Init script fails to stop smokeping
From: TS Lura <[email-masked]>
To: [email-masked]
Date: Mon, 8 Aug 2022 22:11:27 +0200

Package: smokeping
Version: 2.7.3-3
Severity: normal

Dear Maintainer,

I wanted to restart my smokeping daemon after a change of my config files.
I wanted to run the command /etc/init.d/smokeping stop
But the smokeping process did not terminate.
I wanted the smokeping process to terminate.

I have supplied a patch.

If you change the line 131 in /etc/init.d/smokeping from:
    start-stop-daemon --oknodo --stop --retry 3 --quiet --pidfile
$PIDFILE --exec $DAEMON --signal 15
to
    start-stop-daemon --oknodo --stop --retry 3 --quiet --pidfile
$PIDFILE --user $DAEMON_USER --signal 15

The command /etc/init.d/smokeping stop , works. e.g. The smokeping
daemon is killed.

-- System Information:
Distributor ID:	Devuan
Description:	Devuan GNU/Linux 4 (chimaera)
Release:	4
Codename:	chimaera
Architecture: x86_64

Kernel: Linux 5.10.0-16-amd64 (SMP w/4 CPU threads)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8),
LANGUAGE=en_GB:en
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)
LSM: AppArmor: enabled

Versions of packages smokeping depends on:
ii  adduser                                    3.118
ii  debianutils                                4.11.2
ii  exim4-daemon-light [mail-transport-agent]  4.94.2-7
ii  fping                                      5.0-1
ii  libcgi-fast-perl                           1:2.15-1
ii  libconfig-grammar-perl                     1.13-3
ii  libdigest-hmac-perl                        1.03+dfsg-2.1
ii  libjs-cropper                              1.2.2-1.1
ii  libjs-prototype                            1.7.1-3.1
ii  libjs-scriptaculous                        1.9.0-2.1
ii  librrds-perl                               1.7.2-3+b7
ii  libsnmp-session-perl                       1.14~git20201002.0dedded-1
ii  liburi-perl                                5.08-1
ii  libwww-perl                                6.52-1
ii  lsb-base                                   11.1.0
ii  perl                                       5.32.1-4+deb11u2
ii  ucf                                        3.0043

Versions of packages smokeping recommends:
ii  apache2 [httpd-cgi]        2.4.54-1~deb11u1
ii  bind9-dnsutils [dnsutils]  1:9.16.27-1~deb11u1
pn  echoping                   <none>
ii  libsocket6-perl            0.29-1+b3

Versions of packages smokeping suggests:
ii  curl                   7.74.0-1.3+deb11u1
pn  libauthen-radius-perl  <none>
ii  libio-socket-ssl-perl  2.069-1
pn  libnet-dns-perl        <none>
pn  libnet-ldap-perl       <none>
pn  libnet-telnet-perl     <none>
ii  openssh-client         1:8.4p1-5+deb11u1

-- Configuration Files:
/etc/init.d/smokeping changed:
set -e
. /lib/lsb/init-functions
DAEMON=/usr/sbin/smokeping
NAME=smokeping
DESC="latency logger daemon"
CONFIG=/etc/smokeping/config
PIDFILE=/var/run/smokeping/$NAME.pid
DAEMON_USER=smokeping
DEFAULTS=/etc/default/smokeping
MODE=master
DAEMON_ARGS="--config=$CONFIG"
unset LC_ALL
test -f "$DAEMON" || exit 0
if [ -f "$DEFAULTS" ]
then
    . "$DEFAULTS"
fi
check_slave() {
    if [ "$MODE" != "slave" ]
    then
        return
    fi
    if [ -z "$SHARED_SECRET" ]
    then
        log_progress_msg "(missing \$SHARED_SECRET setting)"
        log_end_msg 6 # program is not configured
        exit 6
    fi
    if [ ! -r "$SHARED_SECRET" ]
    then
        log_progress_msg "(invalid \$SHARED_SECRET setting)"
        log_end_msg 2 # invalid or excess argument(s)
        exit 2
    fi
    if [ -z "$MASTER_URL" ]
    then
        log_progress_msg "(missing \$MASTER_URL setting)"
        log_end_msg 6 # program is not configured
        exit 6
    fi
    DAEMON_ARGS="$DAEMON_ARGS --master-url $MASTER_URL --shared-secret
$SHARED_SECRET"
    if [ -n "$SLAVE_NAME" ]
    then
        DAEMON_ARGS="$DAEMON_ARGS --slave-name $SLAVE_NAME"
    fi
    DAEMON_ARGS="$DAEMON_ARGS --cache-dir /var/lib/smokeping"
    DAEMON_ARGS="$DAEMON_ARGS --pid-dir /var/run/smokeping"
}
check_config () {
    echo "Checking smokeping configuration file syntax..."
    # Check whether the configuration file is available
    if [ ! -r "$CONFIG" ] && [ "$MODE" = "master" ]
    then
        log_progress_msg "($CONFIG does not exist)"
        log_end_msg 6 # program is not configured
        exit 6
    fi
    if [ ! -d /var/run/smokeping ]; then
        mkdir /var/run/smokeping
        chown ${DAEMON_USER}.root /var/run/smokeping
        chmod 0755 /var/run/smokeping
    fi
    ${DAEMON} --config=${CONFIG} --check || exit 6
}
case "$1" in
    start)
        check_config
        log_daemon_msg "Starting $DESC" $NAME
        check_slave
        set +e
        pidofproc -p "$PIDFILE" "$DAEMON" > /dev/null
        STATUS=$?
        set -e
        if [ "$STATUS" = 0 ]
        then
            log_progress_msg "already running"
            log_end_msg $STATUS
            exit $STATUS
        fi
        set +e
        start-stop-daemon --start --quiet --exec $DAEMON --oknodo \
            --chuid $DAEMON_USER --pidfile $PIDFILE \
            -- $DAEMON_ARGS \
            | logger -p daemon.notice -t $NAME
        STATUS=$?
        set -e
        log_end_msg $STATUS
        exit $STATUS
        ;;
    stop)
        log_daemon_msg "Shutting down $DESC" $NAME
        set +e
        start-stop-daemon --oknodo --stop --retry 3 --quiet --pidfile
$PIDFILE --user $DAEMON_USER --signal 15
        STATUS=$?
        set -e
        log_end_msg $STATUS
        exit $STATUS
        ;;
    restart)
        # Restart service (if running) or start service
        $0 stop
        $0 start
        ;;
    reload|force-reload)
        check_config
        log_action_begin_msg "Reloading $DESC configuration"
        set +e
        $DAEMON --reload $DAEMON_ARGS | logger -p daemon.notice -t smokeping
        STATUS=$?
        set -e
        if [ "$STATUS" = 0 ]
        then
            log_action_end_msg 0 "If the CGI has problems reloading,
see README.Debian."
        else
            log_action_end_msg $STATUS
        fi
        exit $STATUS
        ;;
    check)
	check_config
	;;
    status)
        log_daemon_msg "Checking $DESC status" $NAME
        # Use pidofproc to check the status of the service,
        # pidofproc returns the exit status code of 0 when it the process is
        # running.
        # LSB defined exit status codes for status:
        # 0    program is running or service is OK
        # 1    program is dead and /var/run pid file exists
        # 2    program is dead and /var/lock lock file exists
        # 3    program is not running
        # 4    program or service status is unknown
        # 5-199    reserved (5-99 LSB, 100-149 distribution, 150-199
applications)
        set +e
        pidofproc -p "$PIDFILE" "$DAEMON" > /dev/null
        STATUS=$?
        log_progress_msg "(status $STATUS)"
        log_end_msg 0
        set -e
        exit $STATUS
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|force-reload|reload}"
        exit 1
        ;;
esac

/etc/smokeping/config.d/Probes changed:
 *** Probes ***
 + FPing
 binary = /usr/bin/fping

/etc/smokeping/config.d/Targets changed:
*** Targets ***
probe = FPing
menu = Top
title = Network Latency Grapher
remark = Welcome to the SmokePing website of xxx Company. \
         Here you will learn all about the latency of our network.
+ Local
menu = Local
title = Local Network
++ LocalMachine
menu = Local Machine
title = This host
host = localhost

-- no debconf information