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