Skip to content

Commit b0732fd

Browse files
committed
Allow running exec with no attach streams requested
This is a small Docker compat fix with the API exec endpoints. With Docker, sending a bare Exec Create (command only, nothing else set) and then an Exec Start without Detach set performs a detached exec. With Podman, we threw an error that at least one stream must be attached to. Fix is trivial; look up the session before start, check the config for attach streams, and force detach on if none are set. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
1 parent 369b4f2 commit b0732fd

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

pkg/api/handlers/compat/exec.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ func ExecStartHandler(w http.ResponseWriter, r *http.Request) {
167167
return
168168
}
169169

170+
// If no streams were requested for attach, detach is implied
171+
if !bodyParams.Detach {
172+
execSession, err := sessionCtr.ExecSession(sessionID)
173+
if err != nil {
174+
utils.InternalServerError(w, err)
175+
return
176+
}
177+
178+
if !execSession.Config.AttachStderr && !execSession.Config.AttachStdout && !execSession.Config.AttachStdin {
179+
bodyParams.Detach = true
180+
}
181+
}
182+
170183
if bodyParams.Detach {
171184
// If we are detaching, we do NOT want to hijack.
172185
// Instead, we perform a detached start, and return 200 if

test/apiv2/20-containers.at

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,17 @@ t POST libpod/containers/$cid/update \
916916

917917
t DELETE containers/$cid 204
918918

919+
# Verify that exec session with no attach streams specified can be started
920+
CTRNAME=exectest
921+
podman run -d --name $CTRNAME $IMAGE top
922+
echo '{ "Cmd":["sh", "-c", "cat hello > /tmp/testfile"]}' >${TMPD}/exec_empty.json
923+
t POST "containers/$CTRNAME/exec" ${TMPD}/exec_empty.json 201 .Id~[0-9a-f]\\{64\\}
924+
eid=$(jq -r '.Id' <<<"$output")
925+
t POST exec/$eid/start 200
926+
podman exec $CTRNAME cat /tmp/testfile
927+
is "$output" "hello"
928+
podman rm -f $CTRNAME
929+
919930
rm -rf $TMPD
920931

921932
podman container rm -fa

0 commit comments

Comments
 (0)