fortify/dbus/run.go
Ophestra Umiker a8b4b3634b
dbus: use generalised helper.Helper for xdg-dbus-proxy
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
2024-09-25 01:17:38 +09:00

54 lines
1.0 KiB
Go

package dbus
import (
"errors"
"os"
"git.ophivana.moe/cat/fortify/helper"
)
// Start launches the D-Bus proxy and sets up the Wait method.
// ready should be buffered and should only be received from once.
func (p *Proxy) Start(ready chan error) error {
p.lock.Lock()
defer p.lock.Unlock()
if p.seal == nil {
return errors.New("proxy not sealed")
}
h := helper.New(p.seal, p.path,
// Helper: Args is always 3 and status if set is always 4.
"--args=3",
"--fd=4",
)
// xdg-dbus-proxy does not need to inherit the environment
h.Env = []string{}
h.Stdout = os.Stdout
h.Stderr = os.Stderr
if err := h.StartNotify(ready); err != nil {
return err
}
p.helper = h
return nil
}
// Wait waits for xdg-dbus-proxy to exit or fault.
func (p *Proxy) Wait() error {
p.lock.RLock()
defer p.lock.RUnlock()
if p.helper == nil {
return errors.New("proxy not started")
}
return p.helper.Wait()
}
// Close closes the status file descriptor passed to xdg-dbus-proxy, causing it to stop.
func (p *Proxy) Close() error {
return p.helper.Close()
}