Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 367553

Summary: net-misc/openssh - sshd sessions don't get killed when system goes down or reboots
Product: Gentoo Linux Reporter: Herbert Wantesh <rauchwolke>
Component: [OLD] Core systemAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED DUPLICATE    
Severity: normal CC: alexander, polynomial-c
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
See Also: https://bugs.gentoo.org/show_bug.cgi?id=259183
Whiteboard:
Package list:
Runtime testing required: ---

Description Herbert Wantesh 2011-05-16 16:50:44 UTC
when i reboot my system or shut it down and im connected to the pc with ssh the session gets stuck until the system comes up again (then its dropped) or the timeout is over (also dropped) therefor when the system goes down or reboots all sshd sessions should get killed to disconnect all users that are connected with ssh to the pc

this is the modified stop routine for sshd to kill all sshd sessions when the system goes down or reboots ...

stop() {
        if [ "${RC_CMD}" = "restart" ] ; then
                checkconfig || return 1
        fi
        ebegin "Stopping ${SVCNAME}"
        if [ "`/sbin/runlevel|/bin/cut -c 3`" = "3" ]; then
                start-stop-daemon --stop --exec "${SSHD_BINARY}" \
                    --pidfile "${SSHD_PIDFILE}" --quiet
        else
                killall -q /usr/sbin/sshd
        fi
        eend $?
}


Reproducible: Always

Steps to Reproduce:
1.start sshd
2.connect to sshd
3.reboot or shutdown pc
4.connection stucks until timeout is over or the pc is up again ....


Expected Results:  
all clients should be disconnected when the pc goes down or reboots
Comment 1 Herbert Wantesh 2011-05-16 17:04:50 UTC
updated version that uses SSHD_BINARY instead...

stop() {
        if [ "${RC_CMD}" = "restart" ] ; then
                checkconfig || return 1
        fi
        ebegin "Stopping ${SVCNAME}"
        if [ "`/sbin/runlevel|/bin/cut -c 3`" = "3" ]; then
                start-stop-daemon --stop --exec "${SSHD_BINARY}" \
                    --pidfile "${SSHD_PIDFILE}" --quiet
        else
                killall -q "${SSHD_BINARY}"
        fi
        eend $?
}
Comment 2 Herbert Wantesh 2011-05-16 17:16:10 UTC
to keep consistency use start-stop-daemon ...

stop() {
        if [ "${RC_CMD}" = "restart" ] ; then
                checkconfig || return 1
        fi
        ebegin "Stopping ${SVCNAME}"
        if [ "`/sbin/runlevel|/bin/cut -c 3`" = "1" ]; then
                start-stop-daemon --stop --exec "${SSHD_BINARY}" \
                    --pidfile "${SSHD_PIDFILE}" --quiet
        else
                start-stop-daemon --stop -n "${SSHD_BINARY}" --quiet
        fi
        eend $?
}
Comment 3 Herbert Wantesh 2011-05-16 17:17:18 UTC
test for runlevel 3 not 1 ...

stop() {
        if [ "${RC_CMD}" = "restart" ] ; then
                checkconfig || return 1
        fi
        ebegin "Stopping ${SVCNAME}"
        if [ "`/sbin/runlevel|/bin/cut -c 3`" = "3" ]; then
                start-stop-daemon --stop --exec "${SSHD_BINARY}" \
                    --pidfile "${SSHD_PIDFILE}" --quiet
        else
                start-stop-daemon --stop -n "${SSHD_BINARY}" --quiet
        fi
        eend $?
}
Comment 4 SpanKY gentoo-dev 2011-05-17 18:55:47 UTC
yeah, we cant merge any of those.  obviously the first one will kill too much when doing `/etc/init.d/sshd stop`, and the latter rely on sysvinit.

i dont see this as being a real problem, and i'm not aware of any other distro that attempts to address this.
Comment 5 Herbert Wantesh 2011-05-21 20:52:57 UTC
but there is no better way to find out if the service is stopped by the user or at reboot/shutdown?
Comment 6 SpanKY gentoo-dev 2011-05-28 19:05:18 UTC
atm, i dont think so.  openrc doesnt provide differentiation between "shutting down" and "switching runlevels".  simply switching between runlevels where the new one doesnt have sshd init.d in it should not kill sessions.

i dont think `fuser` or a similar util can deduce the reason for an app using the network, so it couldnt just say "kill all processes with a network socket open" before bringing down the network.
Comment 7 Alex Xu (Hello71) 2012-12-03 22:06:33 UTC
Shouldn't services that need net be stopped before net goes down?
Comment 8 Doug Goldstein gentoo-dev 2012-12-03 22:18:05 UTC
(In reply to comment #7)
> Shouldn't services that need net be stopped before net goes down?

As Mike pointed out in comment #6, OpenRC doesn't provide the ability to know that shut down is happening due to a runlevel change or the system going down.
Comment 9 Lars Wendler (Polynomial-C) gentoo-dev 2013-01-14 13:05:29 UTC
*** Bug 452026 has been marked as a duplicate of this bug. ***
Comment 10 Herbert Wantesh 2013-01-14 13:31:03 UTC
as it seems openrc intruduced this fix a long time ago

kexec allready uses this

the stop function for the openssh initscript should be changed to:

stop() {
        if [ "${RC_CMD}" = "restart" ] ; then
                checkconfig || return 1
        fi
        ebegin "Stopping ${SVCNAME}"
        if yesno $RC_REBOOT; then
#rebooting
                start-stop-daemon --stop -n "${SSHD_BINARY}" --quiet
        else
                start-stop-daemon --stop --exec "${SSHD_BINARY}" \
                        --pidfile "${SSHD_PIDFILE}" --quiet
        fi
        eend $?
}
Comment 11 Herbert Wantesh 2013-01-17 09:36:21 UTC
this fix doesn't work as it just recognizes a reboot a shutdown is still unhandeld
Comment 12 Alexander Tsoy 2013-02-11 16:00:41 UTC
Isn't this a dublicate of bug 259183?
Comment 13 SpanKY gentoo-dev 2013-04-27 09:08:47 UTC

*** This bug has been marked as a duplicate of bug 259183 ***