From 9d7b86ed23eb8b3eb7e51763bcd1bd0ab0f29c8b Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Sun, 13 Sep 2026 22:07:33 -0700 Subject: [PATCH] maint: commit-msg: handle reparenting by Linux subreapers * scripts/git-hooks/commit-msg ($git_pid): Define the parent process ID at the start of the script. Use it to check if we were reparented. --- scripts/git-hooks/commit-msg | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/git-hooks/commit-msg b/scripts/git-hooks/commit-msg index 769cd1a50..bcf7ecaa7 100755 --- a/scripts/git-hooks/commit-msg +++ b/scripts/git-hooks/commit-msg @@ -4,6 +4,14 @@ eval '(exit $?0)' && eval 'exec perl -w "$0" ${1+"$@"}' use strict; use warnings; + +# Get the process ID of our parent as soon as possible to minimize the +# likelihood of our parent dying while we are alive. Note that we don't +# check that the parent is init, since on Linux a process may become a +# subreaper using PR_SET_CHILD_SUBREAPER, e.g., as done by the +# 'systemd --user' process. +my $git_pid = getppid (); + (my $ME = $0) =~ s|.*/||; # Emulate Git's choice of the editor for the commit message. @@ -165,7 +173,7 @@ sub check_msg($$) re_edit $log_file; # Stop if our parent is killed. - getppid() == 1 + getppid () != $git_pid and last; } }