Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions monitor/commands/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (cm *AttachCmd) Info() types.CommandInfo {

func (cm *AttachCmd) Exec(ctx context.Context, args []string) error {
if len(args) < 2 {
return errors.Errorf("server name must be passed")
return errors.Errorf("ID of session or process must be passed")
}
ref := args[1]
var id string
Expand Down Expand Up @@ -58,7 +58,11 @@ func (cm *AttachCmd) Exec(ctx context.Context, args []string) error {
}

func isProcessID(ctx context.Context, c types.Monitor, ref string) (bool, error) {
infos, err := c.ListProcesses(ctx, c.AttachedSessionID())
sid := c.AttachedSessionID()
if sid == "" {
return false, errors.Errorf("no attaching session")
}
infos, err := c.ListProcesses(ctx, sid)
if err != nil {
return false, err
}
Expand Down
8 changes: 7 additions & 1 deletion monitor/commands/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ func (cm *DisconnectCmd) Exec(ctx context.Context, args []string) error {
target := cm.m.AttachedSessionID()
if len(args) >= 2 {
target = args[1]
} else if target == "" {
return errors.Errorf("no attaching session")
}
isProcess, err := isProcessID(ctx, cm.m, target)
if err == nil && isProcess {
if err := cm.m.DisconnectProcess(ctx, cm.m.AttachedSessionID(), target); err != nil {
sid := cm.m.AttachedSessionID()
if sid == "" {
return errors.Errorf("no attaching session")
}
if err := cm.m.DisconnectProcess(ctx, sid, target); err != nil {
return errors.Errorf("disconnecting from process failed %v", target)
}
return nil
Expand Down
4 changes: 4 additions & 0 deletions monitor/commands/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"text/tabwriter"

"github.com/docker/buildx/monitor/types"
"github.com/pkg/errors"
)

type PsCmd struct {
Expand All @@ -24,6 +25,9 @@ func (cm *PsCmd) Info() types.CommandInfo {

func (cm *PsCmd) Exec(ctx context.Context, args []string) error {
ref := cm.m.AttachedSessionID()
if ref == "" {
return errors.Errorf("no attaching session")
}
plist, err := cm.m.ListProcesses(ctx, ref)
if err != nil {
return err
Expand Down