From bbca58329bf4ebc41a53ea768fc4595f346aae4d Mon Sep 17 00:00:00 2001 From: pavel-shirshov Date: Wed, 20 Jun 2018 12:15:09 -0700 Subject: [PATCH] Manually send SIGHUP to vtysh when the current session was disconnected (#1801) * Manually send SIGHUP to vtysh when the current session was disconnected * Address comments --- dockers/docker-fpm-frr/base_image_files/vtysh | 15 ++++++++++++++- dockers/docker-fpm-quagga/base_image_files/vtysh | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dockers/docker-fpm-frr/base_image_files/vtysh b/dockers/docker-fpm-frr/base_image_files/vtysh index c479fcd3653b..24016bd96b2c 100755 --- a/dockers/docker-fpm-frr/base_image_files/vtysh +++ b/dockers/docker-fpm-frr/base_image_files/vtysh @@ -1,3 +1,16 @@ #!/bin/bash -docker exec -i bgp vtysh "$@" +# Determine whether stdout is on a terminal +if [ -t 1 ] ; then + # Prepare a function to send HUP signal to vtysh in the container + # we mark the new instance of vtysh with the current tty as a tag + TTY=$(tty) + function cleanup + { + docker exec -i bgp pkill -HUP -f "vtysh $TTY" + } + trap cleanup HUP + docker exec -ti bgp vtysh "$TTY" "$@" +else + docker exec -i bgp vtysh "$@" +fi diff --git a/dockers/docker-fpm-quagga/base_image_files/vtysh b/dockers/docker-fpm-quagga/base_image_files/vtysh index c479fcd3653b..24016bd96b2c 100755 --- a/dockers/docker-fpm-quagga/base_image_files/vtysh +++ b/dockers/docker-fpm-quagga/base_image_files/vtysh @@ -1,3 +1,16 @@ #!/bin/bash -docker exec -i bgp vtysh "$@" +# Determine whether stdout is on a terminal +if [ -t 1 ] ; then + # Prepare a function to send HUP signal to vtysh in the container + # we mark the new instance of vtysh with the current tty as a tag + TTY=$(tty) + function cleanup + { + docker exec -i bgp pkill -HUP -f "vtysh $TTY" + } + trap cleanup HUP + docker exec -ti bgp vtysh "$TTY" "$@" +else + docker exec -i bgp vtysh "$@" +fi