Skip to content

Commit 653f465

Browse files
committed
Clean up cleanup in run.sh
The cleanup function was busier than it needed to be, and because of the exec of the client, was never actually being invoked. This change: - reworks cleanup to use "gpgconf --kill" to stop the agent - invokes it explicitly before the client is run - removes the exec so that "trap cleanup EXIT" works and cleanup happens after the client exits Making sure gpg-agent is stopped should prevent any problems it might have if GNUPGHOME is pulled from under its feet between client runs. This should make run.sh more robust when developers are mucking about with SDC_HOME. We might consider adding similar agent cleanup in production, but since SDC_HOME should be consistent and in normal usage should never be removed, the problems we've seen with the GPG agent should not arise in production use.
1 parent 93994ab commit 653f465

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

run.sh

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
set -e
2+
3+
set -eo pipefail
34

45
while [ -n "$1" ]; do
56
param="$1"
@@ -19,22 +20,22 @@ SDC_HOME=${SDC_HOME:-$(mktemp -d)}
1920

2021
export SDC_HOME
2122

22-
GPG_HOME="$SDC_HOME/gpg"
23-
mkdir -p "$GPG_HOME"
24-
chmod 0700 "$SDC_HOME" "$GPG_HOME"
23+
GNUPGHOME="$SDC_HOME/gpg"
24+
export GNUPGHOME
25+
mkdir -p "$GNUPGHOME"
26+
chmod 0700 "$SDC_HOME" "$GNUPGHOME"
2527

2628
function cleanup {
27-
PID=$(ps -ef | grep gpg-agent | grep "$GPG_HOME" | grep -v grep | awk '{print $2}')
28-
if [ "$PID" ]; then
29-
kill "$PID"
30-
fi
29+
gpgconf --kill gpg-agent
3130
}
3231
trap cleanup EXIT
3332

3433
echo "Running app with home directory: $SDC_HOME"
3534
echo ""
3635

37-
gpg --homedir "$GPG_HOME" --allow-secret-key-import --import tests/files/securedrop.gpg.asc &
36+
cleanup
37+
38+
gpg --allow-secret-key-import --import tests/files/securedrop.gpg.asc &
3839

3940
# create the database and config for local testing
4041
./create_dev_data.py "$SDC_HOME" &
@@ -60,4 +61,4 @@ fi
6061

6162
wait
6263

63-
exec python -m securedrop_client --sdc-home "$SDC_HOME" --no-proxy "$qubes_flag" $@
64+
python -m securedrop_client --sdc-home "$SDC_HOME" --no-proxy "$qubes_flag" "$@"

0 commit comments

Comments
 (0)