Skip to content

Commit a3fe5c8

Browse files
Merge pull request #5383 from wzshiming/clean/process-io
move common code to pkg/process from runtime
2 parents c3f5a6a + 7966a66 commit a3fe5c8

5 files changed

Lines changed: 11 additions & 25 deletions

File tree

pkg/process/io.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,6 @@ func NewBinaryIO(ctx context.Context, id string, uri *url.URL) (_ runc.IO, err e
251251
return nil, err
252252
}
253253

254-
var args []string
255-
for k, vs := range uri.Query() {
256-
args = append(args, k)
257-
if len(vs) > 0 {
258-
args = append(args, vs[0])
259-
}
260-
}
261-
262254
var closers []func() error
263255
defer func() {
264256
if err == nil {
@@ -289,12 +281,7 @@ func NewBinaryIO(ctx context.Context, id string, uri *url.URL) (_ runc.IO, err e
289281
}
290282
closers = append(closers, r.Close, w.Close)
291283

292-
cmd := exec.Command(uri.Path, args...)
293-
cmd.Env = append(cmd.Env,
294-
"CONTAINER_ID="+id,
295-
"CONTAINER_NAMESPACE="+ns,
296-
)
297-
284+
cmd := NewBinaryCmd(uri, id, ns)
298285
cmd.ExtraFiles = append(cmd.ExtraFiles, out.r, serr.r, w)
299286
// don't need to register this with the reaper or wait when
300287
// running inside a shim

runtime/io.go renamed to pkg/process/io_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package runtime
17+
package process
1818

1919
import (
2020
"net/url"

runtime/v1/shim/service_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
"github.com/containerd/console"
2828
"github.com/containerd/containerd/namespaces"
29-
"github.com/containerd/containerd/runtime"
29+
"github.com/containerd/containerd/pkg/process"
3030
"github.com/containerd/fifo"
3131
"github.com/pkg/errors"
3232
)
@@ -75,14 +75,14 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
7575
return nil, err
7676
}
7777

78-
cmd := runtime.NewBinaryCmd(uri, id, ns)
78+
cmd := process.NewBinaryCmd(uri, id, ns)
7979

8080
// In case of unexpected errors during logging binary start, close open pipes
8181
var filesToClose []*os.File
8282

8383
defer func() {
8484
if retErr != nil {
85-
runtime.CloseFiles(filesToClose...)
85+
process.CloseFiles(filesToClose...)
8686
}
8787
}()
8888

runtime/v1/shim/service_unix.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
"github.com/containerd/console"
3030
"github.com/containerd/containerd/namespaces"
31-
"github.com/containerd/containerd/runtime"
31+
"github.com/containerd/containerd/pkg/process"
3232
"github.com/containerd/fifo"
3333
"github.com/pkg/errors"
3434
)
@@ -63,15 +63,14 @@ func (p *unixPlatform) CopyConsole(ctx context.Context, console console.Console,
6363
if err != nil {
6464
return nil, err
6565
}
66-
67-
cmd := runtime.NewBinaryCmd(uri, id, ns)
66+
cmd := process.NewBinaryCmd(uri, id, ns)
6867

6968
// In case of unexpected errors during logging binary start, close open pipes
7069
var filesToClose []*os.File
7170

7271
defer func() {
7372
if retErr != nil {
74-
runtime.CloseFiles(filesToClose...)
73+
process.CloseFiles(filesToClose...)
7574
}
7675
}()
7776

runtime/v2/runc/platform.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828

2929
"github.com/containerd/console"
3030
"github.com/containerd/containerd/namespaces"
31+
"github.com/containerd/containerd/pkg/process"
3132
"github.com/containerd/containerd/pkg/stdio"
32-
"github.com/containerd/containerd/runtime"
3333
"github.com/containerd/fifo"
3434
"github.com/pkg/errors"
3535
)
@@ -99,14 +99,14 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
9999
return nil, err
100100
}
101101

102-
cmd := runtime.NewBinaryCmd(uri, id, ns)
102+
cmd := process.NewBinaryCmd(uri, id, ns)
103103

104104
// In case of unexpected errors during logging binary start, close open pipes
105105
var filesToClose []*os.File
106106

107107
defer func() {
108108
if retErr != nil {
109-
runtime.CloseFiles(filesToClose...)
109+
process.CloseFiles(filesToClose...)
110110
}
111111
}()
112112

0 commit comments

Comments
 (0)