Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion dbus/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func (c *Conn) jobComplete(signal *dbus.Signal) {
c.jobListener.Lock()
out, ok := c.jobListener.jobs[job]
if ok {
out <- result
select {
case out <- result:
default:
}
delete(c.jobListener.jobs, job)
}
c.jobListener.Unlock()
Expand All @@ -67,12 +70,27 @@ func (c *Conn) startJob(ctx context.Context, ch chan<- string, job string, args
c.jobListener.jobs[p] = ch
}

go c.observeContextCancellation(ctx, p)

// ignore error since 0 is fine if conversion fails
jobID, _ := strconv.Atoi(path.Base(string(p)))

return jobID, nil
}

func (c *Conn) observeContextCancellation(ctx context.Context, jobId dbus.ObjectPath) {
<-ctx.Done()

// remove job listener if one exists
c.jobListener.Lock()
defer c.jobListener.Unlock()

_, ok := c.jobListener.jobs[jobId]
if ok {
delete(c.jobListener.jobs, jobId)
}
}

// Deprecated: use StartUnitContext instead.
func (c *Conn) StartUnit(name string, mode string, ch chan<- string) (int, error) {
return c.StartUnitContext(context.Background(), name, mode, ch)
Expand Down