-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Walk process tree as part of TTY inference
Unless the GPG_TTY environment variable is set by the user, we try our best to find the process' TTY ourselves and set the environment variable accordingly. However, so far we only looked at our own process' stdin to see whether it refers to a TTY. Alas, we could have been invoked by another process and stdin could have been redirected arbitrarily in such a case. git-send-email, for example, does such a dance. If that's the case, we'd end up reporting a file as a TTY candidate that isn't really a TTY. It seems somewhat sensible to just "do the right thing" and walk up the process hierarchy until we find "the" TTY to use (at least until we get a report where that breaks). With this change we do exactly that.
- Loading branch information
Showing
2 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
|
||
# Copyright (C) 2022 The Nitrocli Developers | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
# We support testing both /dev/null and pipe redirection of stdin and | ||
# the first argument controls which one to use. | ||
stdin=${1:-"pipe"} | ||
instance=${2:-1} | ||
|
||
if [ $instance -ge 5 ]; then | ||
# Print own process ID and then just wait for a while until we get | ||
# killed. | ||
echo $$ | ||
sleep 60 | ||
else | ||
# Invoke the script recursively, doing an actual fork and not just an | ||
# exec in order to spawn a new process. Also redirect stdin to | ||
# simulate it not referring to a TTY directly. | ||
if [ $stdin != "pipe" ]; then | ||
sh $0 $stdin $((instance + 1)) < /dev/null | ||
else | ||
cat | sh $0 $stdin $((instance + 1)) | ||
fi | ||
fi |