Source
80
80
if (ret == -1)
81
81
err(1, "failed to send event %d", event);
82
82
}
83
83
84
84
static void
85
85
client_auth(int drmfd)
86
86
{
87
87
struct drm_auth auth;
88
88
int ret;
89
89
90
-
wait_event(0, SERVER_READY);
91
-
92
90
/* Get a client magic number and pass it to the master for auth. */
93
91
ret = ioctl(drmfd, DRM_IOCTL_GET_MAGIC, &auth);
94
92
if (ret == -1)
95
93
err(1, "Couldn't get client magic");
96
94
send_event(0, CLIENT_MAGIC);
97
95
ret = write(commfd[0], &auth.magic, sizeof(auth.magic));
98
96
if (ret == -1)
99
97
err(1, "Couldn't write auth data");
100
98
}
101
99
165
163
int ret, tempfd;
166
164
167
165
ret = drmGetLock(drmfd, lock1, 0);
168
166
assert(ret == 0);
169
167
/* XXX: Need to make sure that this is the same device as drmfd */
170
168
tempfd = drm_open_any();
171
169
close(tempfd);
172
170
ret = drmUnlock(drmfd, lock1);
173
171
if (ret != 0)
174
172
errx(1, "lock lost during open/close by same pid");
175
-
176
-
close(drmfd);
177
173
}
178
174
179
175
static void client()
180
176
{
181
177
int drmfd, ret;
182
178
unsigned int time;
183
179
180
+
wait_event(0, SERVER_READY);
181
+
184
182
/* XXX: Should make sure we open the same DRM as the master */
185
183
drmfd = drm_open_any();
186
184
187
185
client_auth(drmfd);
188
186
189
187
/* Wait for the server to grab the lock, then grab it ourselves (to
190
188
* contest it). Hopefully we hit it within the window of when the
191
189
* server locks.
192
190
*/
193
191
wait_event(0, SERVER_LOCKED);
194
192
ret = drmGetLock(drmfd, lock2, 0);
195
193
time = get_millis();
196
194
if (ret != 0)
197
195
err(1, "Failed to get lock on client\n");
198
196
drmUnlock(drmfd, lock2);
199
197
200
198
/* Tell the server that our locking completed, and when it did */
201
199
send_event(0, CLIENT_LOCKED);
202
200
ret = write(commfd[0], &time, sizeof(time));
203
201
202
+
close(drmfd);
204
203
exit(0);
205
204
}
206
205
207
206
static void server()
208
207
{
209
208
int drmfd, tempfd, ret;
210
209
unsigned int client_time, unlock_time;
211
210
212
211
drmfd = drm_open_any_master();
213
212
231
230
assert(ret == 0);
232
231
unlock_time = get_millis();
233
232
234
233
wait_event(1, CLIENT_LOCKED);
235
234
ret = read(commfd[1], &client_time, sizeof(client_time));
236
235
if (ret == -1)
237
236
err(1, "Failure to read client magic");
238
237
239
238
if (client_time < unlock_time)
240
239
errx(1, "Client took lock before server released it");
240
+
241
+
close(drmfd);
241
242
}
242
243
243
244
int main(int argc, char **argv)
244
245
{
245
246
int ret;
246
247
247
248
248
249
ret = pipe(commfd);
249
250
if (ret == -1)
250
251
err(1, "Couldn't create pipe");