Skip to content

Commit aa5db47

Browse files
authored
Merge pull request #18347 from TomSweeneyRedHat/dev/tsweeney/4.4.1-preexec
[v4.4.1-rhel] Add file switch for pre-exec hooks
2 parents fd0ea3b + 3db7f4c commit aa5db47

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

pkg/rootless/rootless_linux.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ do_preexec_hooks_dir (const char *dir, char **argv, int argc)
263263
static void
264264
do_preexec_hooks (char **argv, int argc)
265265
{
266+
// Access the preexec_hooks_dir indicator file
267+
// return without processing if the file doesn't exist
268+
char preexec_hooks_path[] = "/etc/containers/podman_preexec_hooks.txt";
269+
if (access(preexec_hooks_path, F_OK) != 0) {
270+
return;
271+
}
272+
266273
char *preexec_hooks = getenv ("PODMAN_PREEXEC_HOOKS_DIR");
267274
do_preexec_hooks_dir (LIBEXECPODMAN "/pre-exec-hooks", argv, argc);
268275
do_preexec_hooks_dir (ETC_PREEXEC_HOOKS, argv, argc);

test/system/950-preexec-hooks.bats

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,39 @@
66
load helpers
77
load helpers.network
88

9+
# The existence of this file allows preexec hooks to run.
10+
preexec_hook_ok_file=/etc/containers/podman_preexec_hooks.txt
11+
912
function setup() {
1013
basic_setup
1114
}
1215

1316
function teardown() {
17+
if [[ -n "$preexec_hook_ok_file" ]]; then
18+
sudo -n rm -f $preexec_hook_ok_file || true
19+
fi
20+
1421
basic_teardown
1522
}
1623

1724
@test "podman preexec hook" {
25+
# This file does not exist on any CI system nor any developer system
26+
# nor actually anywhere in the universe except a small small set of
27+
# places with very specific requirements. If we find this file on
28+
# our test system, it could be a leftover from prior testing, or
29+
# basically just something very weird. So, fail loudly if we see it.
30+
# No podman developer ever wants this file to exist.
31+
if [[ -e $preexec_hook_ok_file ]]; then
32+
# Unset the variable, so we don't delete it in teardown
33+
msg="File already exists (it should not): $preexec_hook_ok_file"
34+
preexec_hook_ok_file=
35+
36+
die "$msg"
37+
fi
38+
39+
# Good. File does not exist. Now see if we can TEMPORARILY create it.
40+
sudo -n touch $preexec_hook_ok_file || skip "test requires sudo"
41+
1842
preexec_hook_dir=$PODMAN_TMPDIR/auth
1943
mkdir -p $preexec_hook_dir
2044
preexec_hook_script=$preexec_hook_dir/pull_check.sh
@@ -29,5 +53,10 @@ EOF
2953
chmod +x $preexec_hook_script
3054

3155
PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman 42 pull foobar
32-
PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman 43 pull barfoo
56+
PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman 43 version
57+
58+
sudo -n rm -f $preexec_hook_ok_file || true
59+
60+
# no hooks-ok file, everything should now work again (HOOKS_DIR is ignored)
61+
PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman version
3362
}

0 commit comments

Comments
 (0)