Use system bus

pull/16/head
brl 9 years ago
parent 35f3735a40
commit 028e88e628

@ -3,10 +3,7 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"runtime"
"strings" "strings"
"syscall"
"github.com/godbus/dbus" "github.com/godbus/dbus"
"github.com/godbus/dbus/introspect" "github.com/godbus/dbus/introspect"
@ -31,26 +28,12 @@ type dbusServer struct {
prompter *prompter prompter *prompter
} }
func dbusConnect() (*dbus.Conn, error) { func newDbusServer() (*dbusServer, error) {
// https://github.com/golang/go/issues/1435 conn, err := dbus.SystemBus()
runtime.LockOSThread()
syscall.Setresuid(-1, 1000, 0)
conn, err := dbus.SessionBus()
if err != nil { if err != nil {
return nil, err return nil, err
} }
syscall.Setresuid(0, 0, -1)
runtime.UnlockOSThread()
if os.Geteuid() != 0 || os.Getuid() != 0 {
log.Warning("Not root as expected")
os.Exit(0)
}
return conn, nil
}
func newDbusServer(conn *dbus.Conn) (*dbusServer, error) {
reply, err := conn.RequestName(busName, dbus.NameFlagDoNotQueue) reply, err := conn.RequestName(busName, dbus.NameFlagDoNotQueue)
if err != nil { if err != nil {
return nil, err return nil, err

@ -64,12 +64,7 @@ func main() {
setupIPTables() setupIPTables()
dbus, err := dbusConnect() ds, err := newDbusServer()
if err != nil {
log.Error(err.Error())
os.Exit(1)
}
ds, err := newDbusServer(dbus)
if err != nil { if err != nil {
log.Error(err.Error()) log.Error(err.Error())
os.Exit(1) os.Exit(1)

Loading…
Cancel
Save