Skip to content

Commit 69f7a51

Browse files
committed
exec:support to set custom log path
Signed-off-by: ningmingxiao <[email protected]>
1 parent 4a6db15 commit 69f7a51

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
path: src/github.com/containerd/go-runc
3535
fetch-depth: 25
3636

37-
- uses: containerd/project-checks@v1.1.0
37+
- uses: containerd/project-checks@d7751f3c375b8fe4a84c02a068184ee4c1f59bc4 # v1.2.2
3838
with:
3939
working-directory: src/github.com/containerd/go-runc
4040

command_linux.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ import (
2525
)
2626

2727
func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
28+
return r.commandWithCustomLogPath(context, "", args...)
29+
}
30+
31+
func (r *Runc) commandWithCustomLogPath(context context.Context, logPath string, args ...string) *exec.Cmd {
2832
command := r.Command
2933
if command == "" {
3034
command = DefaultCommand
3135
}
32-
cmd := exec.CommandContext(context, command, append(r.args(), args...)...)
36+
cmd := exec.CommandContext(context, command, append(r.args(logPath), args...)...)
3337
cmd.SysProcAttr = &syscall.SysProcAttr{
3438
Setpgid: r.Setpgid,
3539
}

command_other.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ import (
2525
)
2626

2727
func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
28+
return r.commandWithCustomLogPath(context, "", args...)
29+
}
30+
31+
func (r *Runc) commandWithCustomLogPath(context context.Context, logPath string, args ...string) *exec.Cmd {
2832
command := r.Command
2933
if command == "" {
3034
command = DefaultCommand
3135
}
32-
cmd := exec.CommandContext(context, command, append(r.args(), args...)...)
36+
cmd := exec.CommandContext(context, command, append(r.args(logPath), args...)...)
3337
cmd.Env = os.Environ()
3438
return cmd
3539
}

runc.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func (r *Runc) Start(context context.Context, id string) error {
228228
// ExecOpts holds optional settings when starting an exec process with runc
229229
type ExecOpts struct {
230230
IO
231+
LogPath string
231232
PidFile string
232233
ConsoleSocket ConsoleSocket
233234
Detach bool
@@ -280,7 +281,7 @@ func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts
280281
return err
281282
}
282283
args = append(args, oargs...)
283-
cmd := r.command(context, append(args, id)...)
284+
cmd := r.commandWithCustomLogPath(context, opts.LogPath, append(args, id)...)
284285
if opts.IO != nil {
285286
opts.Set(cmd)
286287
}
@@ -765,15 +766,24 @@ func (r *Runc) Features(context context.Context) (*features.Features, error) {
765766
return &feat, nil
766767
}
767768

768-
func (r *Runc) args() (out []string) {
769+
func (r *Runc) args(logPath string) (out []string) {
769770
if r.Root != "" {
770771
out = append(out, "--root", r.Root)
771772
}
772773
if r.Debug {
773774
out = append(out, "--debug")
774775
}
776+
775777
if r.Log != "" {
776-
out = append(out, "--log", r.Log)
778+
if logPath != "" {
779+
out = append(out, "--log", logPath)
780+
} else {
781+
out = append(out, "--log", r.Log)
782+
}
783+
}
784+
785+
if r.Log == "" && logPath != "" {
786+
out = append(out, "--log", logPath)
777787
}
778788
if r.LogFormat != none {
779789
out = append(out, "--log-format", string(r.LogFormat))

0 commit comments

Comments
 (0)