This commit is contained in:
Ian Gulliver
2026-10-20 22:05:33 -07:00
parent 0877cecab0
commit 5eab2597e4
2 changed files with 27 additions and 29 deletions
+25 -29
View File
@@ -277,21 +277,15 @@ func (m *Manager) clientBash(ctx context.Context, raw json.RawMessage) (string,
return "", fmt.Errorf("timeout_ms must be between 1 and %d", maxBashTimeout.Milliseconds())
}
ms := int(timeout.Milliseconds())
cctx, cancel := context.WithTimeout(ctx, timeout+replyGrace)
defer cancel()
reply, err := m.clients.Call(cctx, args.Client, api.ClientRequest{Op: api.Bash, Command: &args.Command, TimeoutMs: &ms})
exitCode, output, err := m.runClientBash(ctx, args.Client, args.Command, timeout)
if err != nil {
return "", err
}
if reply.ExitCode == nil || reply.Output == nil {
return "", fmt.Errorf("%s's reply has no exit_code or output", args.Client)
}
status := fmt.Sprintf("exit status %d", *reply.ExitCode)
if *reply.ExitCode == -1 {
status := fmt.Sprintf("exit status %d", exitCode)
if exitCode == -1 {
status = fmt.Sprintf("killed after %s", timeout)
}
return status + "\n" + *reply.Output, nil
return status + "\n" + output, nil
}
type clientTransferArgs struct {
@@ -371,19 +365,13 @@ func (m *Manager) clientOpen(ctx context.Context, l *live, raw json.RawMessage)
return "", err
}
command := "open " + dir + "/'" + strings.ReplaceAll(name, "'", `'\''`) + "'"
ms := int(fileTimeout.Milliseconds())
cctx, cancel := context.WithTimeout(ctx, fileTimeout+replyGrace)
defer cancel()
reply, err := m.clients.Call(cctx, args.Client, api.ClientRequest{Op: api.Bash, Command: &command, TimeoutMs: &ms})
command := "open " + dir + "/" + shellQuote(name)
exitCode, output, err := m.runClientBash(ctx, args.Client, command, fileTimeout)
if err != nil {
return "", err
}
if reply.ExitCode == nil || reply.Output == nil {
return "", fmt.Errorf("%s's reply has no exit_code or output", args.Client)
}
if *reply.ExitCode != 0 {
return "", fmt.Errorf("copied %s to %s on %s, but open exited %d: %s", clean, dest, args.Client, *reply.ExitCode, *reply.Output)
if exitCode != 0 {
return "", fmt.Errorf("copied %s to %s on %s, but open exited %d: %s", clean, dest, args.Client, exitCode, output)
}
return fmt.Sprintf("Opened %s on %s, copied to %s.", clean, args.Client, dest), nil
}
@@ -616,20 +604,28 @@ func clientShellPath(p string) (string, error) {
func (m *Manager) runClientByre(ctx context.Context, client, sub, args string) (string, error) {
command := clientByre + " " + sub + args
ms := int(fileTimeout.Milliseconds())
cctx, cancel := context.WithTimeout(ctx, fileTimeout+replyGrace)
defer cancel()
reply, err := m.clients.Call(cctx, client, api.ClientRequest{Op: api.Bash, Command: &command, TimeoutMs: &ms})
exitCode, output, err := m.runClientBash(ctx, client, command, fileTimeout)
if err != nil {
return "", err
}
if exitCode != 0 {
return "", fmt.Errorf("byre %s on %s exited %d: %s", sub, client, exitCode, output)
}
return output, nil
}
func (m *Manager) runClientBash(ctx context.Context, client, command string, timeout time.Duration) (int, string, error) {
ms := int(timeout.Milliseconds())
cctx, cancel := context.WithTimeout(ctx, timeout+replyGrace)
defer cancel()
reply, err := m.clients.Call(cctx, client, api.ClientRequest{Op: api.Bash, Command: &command, TimeoutMs: &ms})
if err != nil {
return 0, "", err
}
if reply.ExitCode == nil || reply.Output == nil {
return "", fmt.Errorf("%s's reply has no exit_code or output", client)
return 0, "", fmt.Errorf("%s's reply has no exit_code or output", client)
}
if *reply.ExitCode != 0 {
return "", fmt.Errorf("byre %s on %s exited %d: %s", sub, client, *reply.ExitCode, *reply.Output)
}
return *reply.Output, nil
return *reply.ExitCode, *reply.Output, nil
}
type clientHandsArgs struct {