Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show informative error for non-executable exec target #688

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

- Support nvidia-container-cli v1.8.0 and above, via fix to capability set.
- Do not truncate environment variables with commas
- Show an informative error when `exec` target is not executable.

## v3.9.6 \[2022-03-10\]

Expand Down
20 changes: 16 additions & 4 deletions e2e/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ func (c actionTests) actionExec(t *testing.T) {
homePath := filepath.Join("/home", basename)

tests := []struct {
name string
argv []string
exit int
name string
argv []string
exit int
errorContains string
}{
{
name: "NoCommand",
Expand Down Expand Up @@ -250,17 +251,28 @@ func (c actionTests) actionExec(t *testing.T) {
argv: []string{"--no-home", c.env.ImagePath, "ls", "-ld", user.Dir},
exit: 1,
},
{
name: "NotExecutable",
argv: []string{c.env.ImagePath, "/etc/hosts"},
exit: 1,
errorContains: "/etc/hosts is not an executable file in the container. Check it exists and has executable permissions.",
},
}

for _, tt := range tests {
resultOps := []e2e.SingularityCmdResultOp{}
if tt.errorContains != "" {
resultOps = append(resultOps, e2e.ExpectError(e2e.ContainMatch, tt.errorContains))
}

c.env.RunSingularity(
t,
e2e.AsSubtest(tt.name),
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("exec"),
e2e.WithDir("/tmp"),
e2e.WithArgs(tt.argv...),
e2e.ExpectExit(tt.exit),
e2e.ExpectExit(tt.exit, resultOps...),
)
}
}
Expand Down
9 changes: 8 additions & 1 deletion internal/pkg/util/fs/files/action_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ sylog debug "Running action command ${__singularity_cmd__}"

case "${__singularity_cmd__}" in
exec)
exec "$@" ;;
# This uses the limited type -p behavior of mvdan.cc/sh and is *not* POSIX.
execbin=$(type -p "$1")
if test $? -ne 0 || test -z "${execbin}" ; then
sylog error "$1 is not an executable file in the container. Check it exists and has executable permissions."
exit 1
fi
exec "$@"
;;
shell)
if test -n "${SINGULARITY_SHELL:-}" -a -x "${SINGULARITY_SHELL:-}"; then
exec "${SINGULARITY_SHELL:-}" "$@"
Expand Down