From 10715f1d3a57e6c468466a76059efb000840f594 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Tue, 19 Dec 2017 00:24:02 +0100 Subject: [PATCH] Rewrite GDB command to stop on the first error, e.g. if lsof is broken. The use of call("echo 'string'") instead of print('string') or sys.stdout.write('string') is due to the latter two not reliably reporting back whether they were successful or not: print doesn't return anything (and actually can't be chained like this), and the return value of sys.stdout.write depends on the Python version (None on Python 2, number of bytes written on Python 3). --- kill-wpull-connections | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kill-wpull-connections b/kill-wpull-connections index 3fe1ac1..73b8e6d 100755 --- a/kill-wpull-connections +++ b/kill-wpull-connections @@ -50,9 +50,8 @@ fi gdb -batch -batch-silent \ -ex "attach ${wpullPid}" \ - -ex 'shell echo "FDs before forced shutdown:"; lsof -an -p '${wpullPid}' -i TCP | grep -v 127\.0\.0\.1' \ -ex 'python import subprocess' \ - -ex 'python for fd in subprocess.check_output("lsof -an -p '${wpullPid}' -i TCP -F pfn | awk '\''NR%2==0{fd=substr($0,2)}NR%2==1&&NR>1&&!/127\.0\.0\.1/{print fd}'\''", shell = True).decode("ascii").strip().split("\n"): gdb.execute("p shutdown(" + fd + ", 2)")' \ - -ex 'shell echo "FDs after forced shutdown:"; lsof -an -p '${wpullPid}' -i TCP | grep -v 127\.0\.0\.1' \ + -ex 'python def call(s): return subprocess.call(s, shell = True) == 0' \ + -ex 'python call("echo '\''FDs before forced shutdown:'\''") and call("lsof -an -p '${wpullPid}' -i TCP | grep -v 127\.0\.0\.1") and ([gdb.execute("p shutdown(" + fd + ", 2)") for fd in subprocess.check_output("lsof -an -p '${wpullPid}' -i TCP -F pfn | awk '\''NR%2==0{fd=substr($0,2)}NR%2==1&&NR>1&&!/127\.0\.0\.1/{print fd}'\''", shell = True).decode("ascii").strip().split("\n")] or True) and call("echo '\''FDs after forced shutdown:'\''") and call("lsof -an -p '${wpullPid}' -i TCP | grep -v 127\.0\.0\.1")' \ -ex detach \ -ex quit