toolsrv: proc/list now rdwr with agent filtering
Write agent ID to filter, or empty for all. Returns pid\tstate\ttool. Added ListProcsForAgent to State.
This commit is contained in:
parent
48add8f7bb
commit
de33f954e2
|
|
@ -405,11 +405,22 @@ func (st *State) ListProcs() []int {
|
|||
// ListProcsWithState returns a formatted list of all processes with their state.
|
||||
// Format: "pid\tstate\ttool\n" where state is "running" or "exited (code)".
|
||||
func (st *State) ListProcsWithState() string {
|
||||
return st.ListProcsForAgent("")
|
||||
}
|
||||
|
||||
// ListProcsForAgent returns a formatted list of processes for the given agent.
|
||||
// If agentID is empty, returns all processes.
|
||||
// Format: "pid\tstate\ttool\n"
|
||||
func (st *State) ListProcsForAgent(agentID string) string {
|
||||
st.procMu.Lock()
|
||||
defer st.procMu.Unlock()
|
||||
var buf bytes.Buffer
|
||||
for pid, p := range st.procs {
|
||||
p.mu.Lock()
|
||||
if agentID != "" && p.AgentID != agentID {
|
||||
p.mu.Unlock()
|
||||
continue
|
||||
}
|
||||
var state string
|
||||
if p.Exited {
|
||||
state = fmt.Sprintf("exited (%d)", p.ExitCode)
|
||||
|
|
|
|||
|
|
@ -177,10 +177,11 @@ func Spec(srv *Server) virtfs.FsNodeDecl {
|
|||
),
|
||||
),
|
||||
virtfs.DirNode("proc",
|
||||
virtfs.FileNode("list", 0444,
|
||||
virtfs.Doc("List all processes: pid, state (running/exited (code)), tool"),
|
||||
virtfs.Read(func() ([]byte, error) {
|
||||
return []byte(srv.Fs.ListProcsWithState()), nil
|
||||
virtfs.FileNode("list", 0666,
|
||||
virtfs.Doc("List processes: write agent ID (or empty for all), read pid\\tstate\\ttool"),
|
||||
virtfs.Request(func(_ context.Context, data []byte) ([]byte, error) {
|
||||
agentID := strings.TrimSpace(string(data))
|
||||
return []byte(srv.Fs.ListProcsForAgent(agentID)), nil
|
||||
}),
|
||||
),
|
||||
virtfs.FileNode("new", 0666,
|
||||
|
|
|
|||
Loading…
Reference in New Issue