GNU hello has a copy of scripts/git-hooks/commit-msg from coreutils. I
started getting a bit annoyed with it giving me false positives
periodically. I suspect it was because it was copied before commit
a2b21e910 (maint: commit-msg: compute UTF-8-aware line-length,
2021-12-19).
Anyways, while copying it I noticed that the reparenting check is a
bit dated. It assumes that the process will be reparented by init.
That isn't true on Linux, which caused problems in 'timeout' fixed by
e644eea12 (timeout: don't exit immediately if the parent is the init
process, 2026-03-13).
I'll push this one after the release.
-- 8< --
* 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;
}
}
--
2.55.0