Audit of 57324fe
This commit is contained in:
+25
-29
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user