35 lines
843 B
Go
35 lines
843 B
Go
package fs
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"ollie/agent"
|
|
)
|
|
|
|
// ── Process handlers ─────────────────────────────────────────────
|
|
|
|
func listProcesses(ctx HandlerCtx, s *Session, a *agent.Agent) ([]FsNodeDecl, error) {
|
|
procs := a.ListDetached()
|
|
out := make([]FsNodeDecl, len(procs))
|
|
for i, p := range procs {
|
|
pid := p.PID
|
|
pidStr := strconv.Itoa(pid)
|
|
out[i] = Leaf(pidStr, 0444,
|
|
Read(func(_ HandlerCtx) ([]byte, error) {
|
|
output, err := a.GetDetachedOutput(pid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return []byte(output), nil
|
|
}),
|
|
Remove(func(_ HandlerCtx) error {
|
|
if !a.DismissDetached(pid) {
|
|
return fmt.Errorf("process %d not found or still running", pid)
|
|
}
|
|
return nil
|
|
}),
|
|
)
|
|
}
|
|
return out, nil
|
|
} |