9p: route all agent operations through .Agent()
Interrupt, Queue, Detach, ListDetached, SignalDetached, GetDetachedOutput, DismissDetached, InjectSystemEvent now go through sess.Core.Agent() directly. Session only provides: Agent(), Bus(), Close(), SetEnv(), CWD(), SetCWD(), SetSessionID(), WaitChange(), SaveSession().
This commit is contained in:
parent
5ecbd481ed
commit
aeef7ff718
14
dbus.go
14
dbus.go
|
|
@ -199,7 +199,7 @@ func (a *DBusAdapter) startWatcher(id string, sess *mgr.Session) {
|
|||
return
|
||||
case <-time.After(1 * time.Second):
|
||||
}
|
||||
infos := sess.Core.ListDetached()
|
||||
infos := sess.Core.Agent().ListDetached()
|
||||
// Clean up stale entries from exitedPIDs
|
||||
activePIDs := make(map[int]bool, len(infos))
|
||||
for _, info := range infos {
|
||||
|
|
@ -325,7 +325,7 @@ func (a *DBusAdapter) Interrupt(sessionID string) (bool, *dbus.Error) {
|
|||
if sess == nil {
|
||||
return false, nil
|
||||
}
|
||||
sess.Core.Interrupt(agent.ErrInterrupted)
|
||||
sess.Core.Agent().Interrupt(agent.ErrInterrupted)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
@ -514,7 +514,7 @@ func (a *DBusAdapter) DetachProcess(sessionID string) (bool, *dbus.Error) {
|
|||
if sess == nil {
|
||||
return false, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
|
||||
}
|
||||
if !sess.Core.Detach() {
|
||||
if !sess.Core.Agent().Detach() {
|
||||
return false, dbus.MakeFailedError(fmt.Errorf("no running process to detach"))
|
||||
}
|
||||
a.conn.Emit(busPath, busIface+".ProcessDetached", sessionID)
|
||||
|
|
@ -526,7 +526,7 @@ func (a *DBusAdapter) ListDetached(sessionID string) ([]string, *dbus.Error) {
|
|||
if sess == nil {
|
||||
return nil, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
|
||||
}
|
||||
infos := sess.Core.ListDetached()
|
||||
infos := sess.Core.Agent().ListDetached()
|
||||
out := make([]string, len(infos))
|
||||
for i, info := range infos {
|
||||
status := "running"
|
||||
|
|
@ -552,7 +552,7 @@ func (a *DBusAdapter) SignalDetached(sessionID string, pid int32, signal string)
|
|||
default:
|
||||
return false, dbus.MakeFailedError(fmt.Errorf("unsupported signal: %s", signal))
|
||||
}
|
||||
if err := sess.Core.SignalDetached(int(pid), sig); err != nil {
|
||||
if err := sess.Core.Agent().SignalDetached(int(pid), sig); err != nil {
|
||||
return false, dbus.MakeFailedError(err)
|
||||
}
|
||||
return true, nil
|
||||
|
|
@ -563,7 +563,7 @@ func (a *DBusAdapter) GetDetachedOutput(sessionID string, pid int32) (string, *d
|
|||
if sess == nil {
|
||||
return "", dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
|
||||
}
|
||||
output, err := sess.Core.GetDetachedOutput(int(pid))
|
||||
output, err := sess.Core.Agent().GetDetachedOutput(int(pid))
|
||||
if err != nil {
|
||||
return "", dbus.MakeFailedError(err)
|
||||
}
|
||||
|
|
@ -575,7 +575,7 @@ func (a *DBusAdapter) DismissDetached(sessionID string, pid int32) (bool, *dbus.
|
|||
if sess == nil {
|
||||
return false, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
|
||||
}
|
||||
return sess.Core.DismissDetached(int(pid)), nil
|
||||
return sess.Core.Agent().DismissDetached(int(pid)), nil
|
||||
}
|
||||
|
||||
// --- Generate / Route ---
|
||||
|
|
|
|||
|
|
@ -533,7 +533,7 @@ func TestSessionFileStoreContentAllFields(t *testing.T) {
|
|||
func TestSessionFileStoreReadFifoOut(t *testing.T) {
|
||||
sess := testSession("s1")
|
||||
defer sess.Cancel()
|
||||
sess.Core.Queue("queued-item")
|
||||
sess.Core.Agent().Queue("queued-item")
|
||||
sf := newTestSessionFileStore(t, sess)
|
||||
|
||||
data := testStoreRead(t, sf, "fifo.out")
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ func (s *Manager) Readdir(name string) ([]os.DirEntry, error) {
|
|||
}
|
||||
// {id}/agent/{aid}/proc — list detached process PIDs
|
||||
if len(parts) == 4 && parts[3] == "proc" {
|
||||
procs := sess.Core.ListDetached()
|
||||
procs := sess.Core.Agent().ListDetached()
|
||||
entries := make([]os.DirEntry, len(procs))
|
||||
for i, p := range procs {
|
||||
entries[i] = fs.FileEntry(fmt.Sprintf("%d", p.PID), 0666)
|
||||
|
|
@ -374,7 +374,7 @@ func (s *Manager) openEntry(name string) (fs.File, error) {
|
|||
return &fs.SyntheticFileInfo{Name_: pidStr, Mode_: 0444}, nil
|
||||
},
|
||||
ReadFn: func() ([]byte, error) {
|
||||
output, err := sess.Core.GetDetachedOutput(pid)
|
||||
output, err := sess.Core.Agent().GetDetachedOutput(pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -514,7 +514,7 @@ func (s *Manager) del(name string) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("invalid pid: %s", parts[2])
|
||||
}
|
||||
if !sess.Core.DismissDetached(pid) {
|
||||
if !sess.Core.Agent().DismissDetached(pid) {
|
||||
return fmt.Errorf("process %d not found or still running", pid)
|
||||
}
|
||||
return nil
|
||||
|
|
@ -589,7 +589,7 @@ func (s *Manager) InterruptAll() {
|
|||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
for _, sess := range s.sessions {
|
||||
sess.Core.Interrupt(agent.ErrInterrupted)
|
||||
sess.Core.Agent().Interrupt(agent.ErrInterrupted)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func (sess *Session) Cancel() {
|
|||
}
|
||||
|
||||
func (sess *Session) Interrupt() {
|
||||
sess.Core.Interrupt(agent.ErrInterrupted)
|
||||
sess.Core.Agent().Interrupt(agent.ErrInterrupted)
|
||||
}
|
||||
|
||||
// AppendLog appends data to the session's log and bumps the version.
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ func (h *sessionHelper) fileSpec(name string, mode os.FileMode) fs.FileSpec {
|
|||
if input == "" {
|
||||
return nil
|
||||
}
|
||||
h.sess.Core.Queue(input)
|
||||
h.sess.Core.Agent().Queue(input)
|
||||
return nil
|
||||
}
|
||||
case "ctl":
|
||||
|
|
@ -637,7 +637,7 @@ func (h *sessionHelper) handleCtl(input string) error {
|
|||
}
|
||||
switch cmd[0] {
|
||||
case "stop":
|
||||
h.sess.Core.Interrupt(agent.ErrInterrupted)
|
||||
h.sess.Core.Agent().Interrupt(agent.ErrInterrupted)
|
||||
case "kill":
|
||||
h.kill()
|
||||
case "rn":
|
||||
|
|
@ -653,7 +653,7 @@ func (h *sessionHelper) handleCtl(input string) error {
|
|||
h.sess.mu.RUnlock()
|
||||
return h.saveTranscript(data)
|
||||
case "detach":
|
||||
if !h.sess.Core.Detach() {
|
||||
if !h.sess.Core.Agent().Detach() {
|
||||
return fmt.Errorf("no running process to detach")
|
||||
}
|
||||
case "signal":
|
||||
|
|
@ -668,7 +668,7 @@ func (h *sessionHelper) handleCtl(input string) error {
|
|||
if len(cmd) >= 3 && strings.ToUpper(cmd[2]) == "KILL" {
|
||||
sig = 9
|
||||
}
|
||||
if err := h.sess.Core.SignalDetached(pid, sig); err != nil {
|
||||
if err := h.sess.Core.Agent().SignalDetached(pid, sig); err != nil {
|
||||
return err
|
||||
}
|
||||
case "invalidate":
|
||||
|
|
|
|||
|
|
@ -553,7 +553,7 @@ func (s *Server) pathType(path string) string {
|
|||
if sess == nil {
|
||||
return ""
|
||||
}
|
||||
for _, p := range sess.Core.ListDetached() {
|
||||
for _, p := range sess.Core.Agent().ListDetached() {
|
||||
if fmt.Sprintf("%d", p.PID) == parts[2] {
|
||||
return "file"
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue