From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 4F420138334 for ; Wed, 2 Oct 2019 22:45:34 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9462FE091F; Wed, 2 Oct 2019 22:45:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7BA3CE0919 for ; Wed, 2 Oct 2019 22:45:31 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7994D34B7CB for ; Wed, 2 Oct 2019 22:45:30 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id ED86583C for ; Wed, 2 Oct 2019 22:45:27 +0000 (UTC) From: "Thomas Deutschmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Thomas Deutschmann" Message-ID: <1570027380.24365d81911373e036ca684f1bc47f7d4a253637.whissi@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: / X-VCS-Repository: proj/genkernel X-VCS-Files: gen_funcs.sh X-VCS-Directories: / X-VCS-Committer: whissi X-VCS-Committer-Name: Thomas Deutschmann X-VCS-Revision: 24365d81911373e036ca684f1bc47f7d4a253637 X-VCS-Branch: master Date: Wed, 2 Oct 2019 22:45:27 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: db2edaf1-845f-4d88-b7d9-9d9acc9683b6 X-Archives-Hash: 71eeb2a8f4c927534703aa2cafed9c35 commit: 24365d81911373e036ca684f1bc47f7d4a253637 Author: Thomas Deutschmann gentoo org> AuthorDate: Wed Oct 2 12:34:20 2019 +0000 Commit: Thomas Deutschmann gentoo org> CommitDate: Wed Oct 2 14:43:00 2019 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=24365d81 gen_funcs.sh: cleanup(): Try to kill all running child processes before cleanup If genkernel was aborted, it maybe possible that child processes are still running which maybe prevent cleanup. With this commit, cleanup() will try to kill all running child processes. Signed-off-by: Thomas Deutschmann gentoo.org> gen_funcs.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/gen_funcs.sh b/gen_funcs.sh index cfe53b9..0e7c5ba 100755 --- a/gen_funcs.sh +++ b/gen_funcs.sh @@ -438,6 +438,52 @@ setup_cache_dir() { } cleanup() { + # Child processes we maybe want to kill can only appear in + # current session + local session=$(ps -o sess= ${$} 2>/dev/null | awk '{ print $1 }') + if [ -n "${session}" ] + then + # Time to kill any still running child process. + # All our childs will have GK_SHARE environment variable set. + local -a killed_pids + + local pid_to_kill= + while IFS= read -r -u 3 pid_to_kill + do + # Don't kill ourselves or we will trigger trap + [ "${pid_to_kill}" = "${BASHPID}" ] && continue + + # Killing process group allows us to catch grandchilds + # with clean environment, too. + if kill -${pid_to_kill} &>/dev/null + then + killed_pids+=( ${pid_to_kill} ) + fi + done 3< <(ps e -s ${session} 2>/dev/null | grep GK_SHARE= 2>/dev/null | awk '{ print $1 }') + + if [ ${#killed_pids[@]} -gt 0 ] + then + # Be patient -- still running process could prevent cleanup! + sleep 3 + + # Add one valid pid so that ps command won't fail + killed_pids+=( ${BASHPID} ) + + killed_pids=$(IFS=,; echo "${killed_pids[*]}") + + # Processes had enough time to gracefully terminate! + while IFS= read -r -u 3 pid_to_kill + do + # Don't kill ourselves or we will trigger trap + [ "${pid_to_kill}" = "${BASHPID}" ] && continue + + kill -9 -${pid_to_kill} &>/dev/null + done 3< <(ps --no-headers -q ${killed_pids} 2>/dev/null | awk '{ print $1 }') + fi + else + print_warning 1 "Failed to determine session leader; Will not try to stop child processes" + fi + if isTrue "${CLEANUP}" then if [ -n "${TEMP}" -a -d "${TEMP}" ]