Skip to content

Commit c690b66

Browse files
committed
int/linux: add/use Exec
Drop the libcontainer/system/exec, and use the linux.Exec instead. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 431b8bb commit c690b66

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

internal/linux/linux.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import (
66
"golang.org/x/sys/unix"
77
)
88

9+
// Exec wraps [unix.Exec].
10+
func Exec(cmd string, args []string, env []string) error {
11+
err := retryOnEINTR(func() error {
12+
return unix.Exec(cmd, args, env)
13+
})
14+
if err != nil {
15+
return &os.PathError{Op: "exec", Path: cmd, Err: err}
16+
}
17+
return nil
18+
}
19+
920
// Getwd wraps [unix.Getwd].
1021
func Getwd() (wd string, err error) {
1122
wd, err = retryOnEINTR2(unix.Getwd)

libcontainer/setns_init_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/sirupsen/logrus"
1111
"golang.org/x/sys/unix"
1212

13+
"github.com/opencontainers/runc/internal/linux"
1314
"github.com/opencontainers/runc/libcontainer/apparmor"
1415
"github.com/opencontainers/runc/libcontainer/keys"
1516
"github.com/opencontainers/runc/libcontainer/seccomp"
@@ -156,5 +157,5 @@ func (l *linuxSetnsInit) Init() error {
156157
if err := utils.UnsafeCloseFrom(l.config.PassedFilesCount + 3); err != nil {
157158
return err
158159
}
159-
return system.Exec(name, l.config.Args, l.config.Env)
160+
return linux.Exec(name, l.config.Args, l.config.Env)
160161
}

libcontainer/standard_init_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/sirupsen/logrus"
1212
"golang.org/x/sys/unix"
1313

14+
"github.com/opencontainers/runc/internal/linux"
1415
"github.com/opencontainers/runc/libcontainer/apparmor"
1516
"github.com/opencontainers/runc/libcontainer/configs"
1617
"github.com/opencontainers/runc/libcontainer/keys"
@@ -298,5 +299,5 @@ func (l *linuxStandardInit) Init() error {
298299
if err := utils.UnsafeCloseFrom(l.config.PassedFilesCount + 3); err != nil {
299300
return err
300301
}
301-
return system.Exec(name, l.config.Args, l.config.Env)
302+
return linux.Exec(name, l.config.Args, l.config.Env)
302303
}

libcontainer/system/linux.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ func (p ParentDeathSignal) Set() error {
3232
return SetParentDeathSignal(uintptr(p))
3333
}
3434

35-
func Exec(cmd string, args []string, env []string) error {
36-
for {
37-
err := unix.Exec(cmd, args, env)
38-
if err != unix.EINTR {
39-
return &os.PathError{Op: "exec", Path: cmd, Err: err}
40-
}
41-
}
42-
}
43-
4435
func SetParentDeathSignal(sig uintptr) error {
4536
if err := unix.Prctl(unix.PR_SET_PDEATHSIG, sig, 0, 0, 0); err != nil {
4637
return err

0 commit comments

Comments
 (0)