@@ -106,7 +106,7 @@ static int session_device_notify(SessionDevice *sd, enum SessionDeviceNotificati
106106 return sd_bus_send (sd -> session -> manager -> bus , m , NULL );
107107}
108108
109- static int sd_eviocrevoke (int fd ) {
109+ static void sd_eviocrevoke (int fd ) {
110110 static bool warned = false;
111111
112112 assert (fd >= 0 );
@@ -118,8 +118,6 @@ static int sd_eviocrevoke(int fd) {
118118 warned = true;
119119 }
120120 }
121-
122- return 0 ;
123121}
124122
125123static int sd_drmsetmaster (int fd ) {
@@ -166,7 +164,7 @@ static int session_device_open(SessionDevice *sd, bool active) {
166164 } else
167165 /* DRM-Master is granted to the first user who opens a device automatically (ughh,
168166 * racy!). Hence, we just drop DRM-Master in case we were the first. */
169- sd_drmdropmaster (fd );
167+ ( void ) sd_drmdropmaster (fd );
170168 break ;
171169
172170 case DEVICE_TYPE_EVDEV :
@@ -195,11 +193,19 @@ static int session_device_start(SessionDevice *sd) {
195193 switch (sd -> type ) {
196194
197195 case DEVICE_TYPE_DRM :
198- /* Device is kept open. Simply call drmSetMaster() and hope there is no-one else. In case it fails, we
199- * keep the device paused. Maybe at some point we have a drmStealMaster(). */
200- r = sd_drmsetmaster (sd -> fd );
201- if (r < 0 )
202- return r ;
196+
197+ if (sd -> fd < 0 ) {
198+ /* Open device if it isn't open yet */
199+ sd -> fd = session_device_open (sd , true);
200+ if (sd -> fd < 0 )
201+ return sd -> fd ;
202+ } else {
203+ /* Device is kept open. Simply call drmSetMaster() and hope there is no-one else. In case it fails, we
204+ * keep the device paused. Maybe at some point we have a drmStealMaster(). */
205+ r = sd_drmsetmaster (sd -> fd );
206+ if (r < 0 )
207+ return r ;
208+ }
203209 break ;
204210
205211 case DEVICE_TYPE_EVDEV :
@@ -216,7 +222,7 @@ static int session_device_start(SessionDevice *sd) {
216222
217223 case DEVICE_TYPE_UNKNOWN :
218224 default :
219- /* fallback for devices wihout synchronizations */
225+ /* fallback for devices without synchronizations */
220226 break ;
221227 }
222228
@@ -231,20 +237,23 @@ static void session_device_stop(SessionDevice *sd) {
231237 return ;
232238
233239 switch (sd -> type ) {
240+
234241 case DEVICE_TYPE_DRM :
235242 /* On DRM devices we simply drop DRM-Master but keep it open.
236243 * This allows the user to keep resources allocated. The
237244 * CAP_SYS_ADMIN restriction to DRM-Master prevents users from
238245 * circumventing this. */
239246 sd_drmdropmaster (sd -> fd );
240247 break ;
248+
241249 case DEVICE_TYPE_EVDEV :
242250 /* Revoke access on evdev file-descriptors during deactivation.
243251 * This will basically prevent any operations on the fd and
244252 * cannot be undone. Good side is: it needs no CAP_SYS_ADMIN
245253 * protection this way. */
246254 sd_eviocrevoke (sd -> fd );
247255 break ;
256+
248257 case DEVICE_TYPE_UNKNOWN :
249258 default :
250259 /* fallback for devices without synchronization */
@@ -462,6 +471,7 @@ void session_device_resume_all(Session *s) {
462471 continue ;
463472 if (session_device_save (sd ) < 0 )
464473 continue ;
474+
465475 session_device_notify (sd , SESSION_DEVICE_RESUME );
466476 }
467477}
0 commit comments