forked from linuxdeepin/dde-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (44 loc) · 966 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"flag"
"time"
"pkg.deepin.io/lib/dbusutil"
"pkg.deepin.io/lib/log"
)
var noQuitFlag bool
var logger = log.NewLogger("dde-authority")
func init() {
flag.BoolVar(&noQuitFlag, "no-quit", false, "do not auto quit")
}
const (
dbusInterface = "com.deepin.daemon.Authority"
dbusServiceName = dbusInterface
dbusPath = "/com/deepin/daemon/Authority"
dbusAgentInterface = dbusInterface + ".Agent"
)
func main() {
flag.Parse()
service, err := dbusutil.NewSystemService()
if err != nil {
logger.Fatal(err)
}
auth := newAuthority(service)
err = service.Export(dbusPath, auth)
if err != nil {
logger.Fatal(err)
}
err = service.RequestName(dbusServiceName)
if err != nil {
logger.Fatal(err)
}
logger.Debug("start service")
if !noQuitFlag {
service.SetAutoQuitHandler(3*time.Minute, func() bool {
auth.mu.Lock()
canQuit := len(auth.txs) == 0
auth.mu.Unlock()
return canQuit
})
}
service.Wait()
}