Skip to content

Commit 1997293

Browse files
authored
Merge pull request #911 from giuseppe/hook-inherits-env
linux: hooks inherit env if not specified
2 parents 777b7ef + f0cd1a7 commit 1997293

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

.github/workflows/test.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ jobs:
1111
matrix:
1212
include:
1313
- arch: armv7
14-
distro: ubuntu20.04
14+
distro: ubuntu_latest
1515
- arch: aarch64
16-
distro: ubuntu20.04
16+
distro: ubuntu_latest
1717
- arch: s390x
18-
distro: ubuntu20.04
18+
distro: ubuntu_latest
1919
- arch: ppc64le
20-
distro: ubuntu20.04
20+
distro: ubuntu_latest
2121
steps:
22-
- uses: actions/[email protected]
23-
- uses: uraimo/[email protected]
22+
- uses: actions/[email protected]
23+
with:
24+
submodules: true
25+
set-safe-directory: true
26+
27+
- uses: uraimo/[email protected]
2428
name: Build
2529
id: build
2630
with:
@@ -34,6 +38,7 @@ jobs:
3438
apt-get install -q -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev libprotobuf-c-dev
3539
3640
run: |
41+
find $(pwd) -name '.git' -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
3742
./autogen.sh
3843
./configure CFLAGS='-Wall -Werror'
3944
make -j $(nproc) -C libocispec libocispec.la
@@ -87,6 +92,7 @@ jobs:
8792
- name: run autogen.sh
8893
run: |
8994
git clean -fdx .
95+
find $(pwd) -name '.git' -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
9096
./autogen.sh
9197
9298
- name: run test
@@ -190,6 +196,7 @@ jobs:
190196
- uses: lumaxis/shellcheck-problem-matchers@v1
191197
- name: shellcheck
192198
run: |
199+
find $(pwd) -name '.git' -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
193200
./autogen.sh
194201
./configure
195202
make shellcheck

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ These dependencies are required for the build:
5959

6060
```console
6161
$ sudo dnf install -y make python git gcc automake autoconf libcap-devel \
62-
systemd-devel yajl-devel libseccomp-devel \
62+
systemd-devel yajl-devel libseccomp-devel pkg-config \
6363
go-md2man glibc-static python3-libmount libtool
6464
```
6565

src/libcrun/container.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,12 @@ do_hooks (runtime_spec_schema_config_schema *def, pid_t pid, const char *id, boo
711711

712712
for (i = 0; i < hooks_len; i++)
713713
{
714-
ret = run_process_with_stdin_timeout_envp (hooks[i]->path, hooks[i]->args, cwd, hooks[i]->timeout, hooks[i]->env,
714+
char **env = environ;
715+
716+
if (hooks[i]->env)
717+
env = hooks[i]->env;
718+
719+
ret = run_process_with_stdin_timeout_envp (hooks[i]->path, hooks[i]->args, cwd, hooks[i]->timeout, env,
715720
stdin, stdin_len, out_fd, err_fd, err);
716721
if (UNLIKELY (ret != 0))
717722
{

tests/test_hooks.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with crun. If not, see <http://www.gnu.org/licenses/>.
1717

18+
import os
1819
from tests_utils import *
1920

2021
def test_fail_prestart():
@@ -37,9 +38,40 @@ def test_success_prestart():
3738
return -1
3839
return 0
3940

41+
def test_hook_env_inherit():
42+
conf = base_config()
43+
path = os.getenv("PATH")
44+
45+
hook = {"path" : "/bin/sh", "args" : ["/bin/sh", "-c", "test \"$PATH\" = %s" % path]}
46+
conf['hooks'] = {"prestart" : [hook]}
47+
48+
add_all_namespaces(conf)
49+
print(conf['hooks'])
50+
try:
51+
out, _ = run_and_get_output(conf)
52+
except:
53+
return -1
54+
return 0
55+
56+
def test_hook_env_no_inherit():
57+
conf = base_config()
58+
59+
hook = {"path" : "/bin/sh", "env": ["PATH=/foo"], "args" : ["/bin/sh", "-c", "/bin/test \"$PATH\" == '/foo'"]}
60+
conf['hooks'] = {"prestart" : [hook]}
61+
62+
add_all_namespaces(conf)
63+
print(conf['hooks'])
64+
try:
65+
out, _ = run_and_get_output(conf)
66+
except:
67+
return -1
68+
return 0
69+
4070
all_tests = {
4171
"test-fail-prestart" : test_fail_prestart,
4272
"test-success-prestart" : test_success_prestart,
73+
"test-hook-env-inherit" : test_hook_env_inherit,
74+
"test-hook-env-no-inherit" : test_hook_env_no_inherit,
4375
}
4476

4577
if __name__ == "__main__":

0 commit comments

Comments
 (0)