diff --git a/pkg/inject/inject.go b/pkg/inject/inject.go index 7d1cb9c75..43575ef0a 100644 --- a/pkg/inject/inject.go +++ b/pkg/inject/inject.go @@ -142,12 +142,19 @@ func Inject(opts InjectOptions) (bool, error) { } log.Debugf("injection: payload delivered elapsed=%s", time.Since(start)) - // prefer result error if result.err != nil { return result.wasExecuted, result.err - } else if err != nil { + } + + // Exec EOF during binary injection is expected: the container entrypoint + // may exec the daemon (killing the docker exec process) before inject.sh + // prints its final response. Only surface exec errors when a command was + // actually executed through the script. + if err != nil && result.wasExecuted { return result.wasExecuted, err - } else if result.wasExecuted || opts.ScriptParams.Command == "" { + } + + if result.wasExecuted || opts.ScriptParams.Command == "" { return result.wasExecuted, nil } diff --git a/pkg/inject/inject.sh b/pkg/inject/inject.sh index c888b3dd1..8326efe14 100644 --- a/pkg/inject/inject.sh +++ b/pkg/inject/inject.sh @@ -47,6 +47,14 @@ inject_binary() { return 1 fi + if [ "$CHMOD_PATH" = "true" ]; then + $sh_c "chmod +x \"$temp_file\"" || { + >&2 echo "Error: Failed to make $temp_file executable" + $sh_c "rm -f \"$temp_file\"" 2>/dev/null || true + return 1 + } + fi + if ! $sh_c "mv \"$temp_file\" \"$INSTALL_PATH\""; then >&2 echo "Error: Failed to move binary to $INSTALL_PATH" $sh_c "rm -f \"$temp_file\"" 2>/dev/null || true @@ -97,6 +105,14 @@ download_binary() { return 1 fi + if [ "$CHMOD_PATH" = "true" ]; then + $sh_c "chmod +x \"$temp_file\"" || { + >&2 echo "Error: Failed to make $temp_file executable" + $sh_c "rm -f \"$temp_file\"" 2>/dev/null || true + return 1 + } + fi + if ! $sh_c "mv \"$temp_file\" \"$INSTALL_PATH\""; then >&2 echo "Error: Failed to move downloaded binary to $INSTALL_PATH" $sh_c "rm -f \"$temp_file\"" 2>/dev/null || true @@ -147,13 +163,6 @@ install_agent() { } fi fi - - if [ "$CHMOD_PATH" = "true" ]; then - $sh_c "chmod +x \"$INSTALL_PATH\"" || { - >&2 echo "Error: Failed to make $INSTALL_PATH executable" - exit 1 - } - fi } execute_command() {