Merge lp:~zhangew401/usensord/bug-1620553 into lp:usensord

Proposed by Zhang Enwei
Status: Merged
Approved by: Ken VanDine
Approved revision: 30
Merged at revision: 28
Proposed branch: lp:~zhangew401/usensord/bug-1620553
Merge into: lp:usensord
Diff against target: 166 lines (+28/-28)
2 files modified
debian/changelog (+7/-0)
haptic/haptic.go (+21/-28)
To merge this branch: bzr merge lp:~zhangew401/usensord/bug-1620553
Reviewer Review Type Date Requested Status
Pat McGowan (community) Approve
Jonas G. Drange (community) Approve
James Henstridge Pending
Samuele Pedroni Pending
Andrea Bernabei Pending
Review via email: mp+305351@code.launchpad.net

Description of the change

fix lp:1620553,
Use another dbus connection to query senders' credentials. We cannot do writing and reading simultaneously on the same connection.

To post a comment you must log in.
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

Please add a commit message, and maybe fix that spaces diff (see comment).

Otherwise, this allows me to run the "kill_usensord" script without usensord deadlocking.

Thanks!

review: Approve
lp:~zhangew401/usensord/bug-1620553 updated
30. By Zhang Enwei

Update changelog

Revision history for this message
Pat McGowan (pat-mcgowan) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2016-08-23 01:33:42 +0000
3+++ debian/changelog 2016-09-09 15:26:24 +0000
4@@ -1,3 +1,10 @@
5+usensord (1.1+16.10.20160823-0ubuntu2) vivid; urgency=medium
6+
7+ * Fix lp:1620553, Use another dbus connection to query senders' credentials.
8+ We cannot do writing and reading simultaneously on the same connection.
9+
10+ -- enwei <enwei.zhang@canonical.com> Fri, 09 Sep 2016 23:19:29 +0800
11+
12 usensord (1.1+16.10.20160823-0ubuntu1) yakkety; urgency=medium
13
14 [ enwei ]
15
16=== modified file 'haptic/haptic.go'
17--- haptic/haptic.go 2016-08-23 01:29:52 +0000
18+++ haptic/haptic.go 2016-09-09 15:26:24 +0000
19@@ -53,15 +53,17 @@
20 }
21
22 var (
23- conn *dbus.Connection
24- sysbus *dbus.Connection
25- logger *log.Logger
26- wg sync.WaitGroup
27- powerd *dbus.ObjectProxy
28- mutex *sync.Mutex
29- cookie string
30- timer *time.Timer
31- pvalue uint32
32+ conn *dbus.Connection
33+ sesconn *dbus.Connection
34+ sysbus *dbus.Connection
35+ messageBus *dbus.ObjectProxy
36+ logger *log.Logger
37+ wg sync.WaitGroup
38+ powerd *dbus.ObjectProxy
39+ mutex *sync.Mutex
40+ cookie string
41+ timer *time.Timer
42+ pvalue uint32
43 configFile string
44 )
45
46@@ -75,14 +77,13 @@
47
48 func watchDBusMethodCalls(msgChan <-chan *dbus.Message) {
49 for msg := range msgChan {
50- logger.Println("msg sender", msg.Sender)
51 var reply *dbus.Message
52
53 if msg.Interface == HAPTIC_DBUS_IFACE {
54 reply = handleHapticInterface(msg)
55- } else if msg.Interface == PROP_DBUS_IFACE {
56- reply = handlePropInterface(msg)
57- } else {
58+ } else if msg.Interface == PROP_DBUS_IFACE {
59+ reply = handlePropInterface(msg)
60+ } else {
61 reply = dbus.NewErrorMessage(
62 msg,
63 "org.freedesktop.DBus.Error.UnknownInterface",
64@@ -127,10 +128,8 @@
65 logger.Println("WriteFile error:", errwrite)
66 }
67
68- //reply = dbus.NewSignalMessage("/com/canonical/usensord/haptic", HAPTIC_DBUS_IFACE, "Set")
69 reply = dbus.NewMethodReturnMessage(msg)
70 reply.AppendArgs(dbus.Variant{uint32(pvalue)})
71- logger.Println("Set property to be ", pvalue)
72 } else {
73 reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", "interface or property not correct")
74 }
75@@ -142,7 +141,6 @@
76 }
77
78 func handleHapticInterface(msg *dbus.Message) (reply *dbus.Message) {
79- messageBus := conn.Object("org.freedesktop.DBus", "/org/freedesktop/DBus")
80 processreply, err := messageBus.Call("org.freedesktop.DBus", "GetConnectionCredentials", msg.Sender)
81 if err != nil {
82 reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
83@@ -154,11 +152,9 @@
84 return reply
85 }
86 pid := credentials["ProcessID"].Value.(uint32)
87- logger.Printf("caller process id: %d", pid)
88 var profile string
89 ret, error := C.aa_is_enabled()
90 if ret == 1 {
91- logger.Println("aa_is_enabled")
92 label := credentials["LinuxSecurityLabel"].Value.([]interface{})
93 var bb []uint8
94 for _, f := range label {
95@@ -167,7 +163,6 @@
96 profile = strings.TrimSpace(string(bb))
97 //LinuxSecurityLabel ends with null
98 profile = profile[:len(profile)-1]
99- logger.Println("caller process label:", profile)
100 } else {
101 logger.Println("aa_is_enabled failed:", error)
102 profile = UNCONFINED_PROFILE
103@@ -184,10 +179,8 @@
104 logger.Printf("fail to read %s with error:", file, erreadexe.Error())
105 } else {
106 pname := strings.TrimSpace(string(exe))
107- logger.Println("process name:", pname)
108 if pname == OSK_PROCESS_NAME {
109 isOSK = true
110- logger.Println("OSK calling")
111 }
112 }
113 }
114@@ -200,7 +193,6 @@
115 case "Vibrate":
116 var duration uint32
117 msg.Args(&duration)
118- logger.Printf("Received Vibrate() method call %d", duration)
119 if err := Vibrate(duration); err != nil {
120 reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
121 } else {
122@@ -210,7 +202,6 @@
123 var pattern []uint32
124 var repeat uint32
125 msg.Args(&pattern, &repeat)
126- logger.Print("Received VibratePattern() method call ", pattern, " ", repeat)
127 if err := VibratePattern(pattern, repeat); err != nil {
128 reply = dbus.NewErrorMessage(msg, "com.canonical.usensord.Error", err.Error())
129 } else {
130@@ -259,11 +250,9 @@
131 logger.Println("Cannot request Powerd system power state: ", err)
132 } else {
133 if err := reply.Args(&cookie); err == nil {
134- logger.Println("Suspend blocker cookie: ", cookie)
135 timer = time.NewTimer(time.Duration(t + 1500) * time.Millisecond)
136 go func() {
137 <-timer.C
138- logger.Println("Clearing suspend blocker")
139 if cookie != "" {
140 powerd.Call("com.canonical.powerd", "clearSysState", string(cookie))
141 cookie = ""
142@@ -303,17 +292,21 @@
143 logger.Fatal("Connection error:", err)
144 return err
145 }
146-
147+ if sesconn, err = dbus.Connect(dbus.SessionBus); err != nil {
148+ logger.Fatal("Connection error:", err)
149+ return err
150+ }
151 name := conn.RequestName("com.canonical.usensord", dbus.NameFlagDoNotQueue)
152- logger.Printf("Successfully registered %s on the bus", name.Name)
153+ logger.Printf("Successfully registered %s on the bus", name.Name)
154
155 powerd = sysbus.Object("com.canonical.powerd", "/com/canonical/powerd")
156+ messageBus = sesconn.Object("org.freedesktop.DBus", "/org/freedesktop/DBus")
157 mutex = &sync.Mutex{}
158+
159 //save and load the property value
160 u, err := user.Current()
161 configPath := path.Join(u.HomeDir, ".config", "usensord")
162 configFile = path.Join(u.HomeDir, ".config", "usensord", "prop.json")
163- log.Println("configFile:", configFile)
164 os.MkdirAll(configPath, 0755)
165 b, errread := ioutil.ReadFile(configFile)
166 if errread != nil {

Subscribers

People subscribed via source and target branches