Skip to content

Commit

Permalink
surfman/drm: Let surfman trigger monitor rescan.
Browse files Browse the repository at this point in the history
drm-plugin uses libevent to watch for udev event and handle monitor
hotplug. Rescanning for monitors in the event handler may change the
monitors list at an inappropriate moment while Surfman still uses
pointers to objects in that list.

Let surfman trigger 'get_monitor' and handle the event on its own terms.

Signed-off-by: Eric Chanudet <[email protected]>

OXT-1653

(cherry picked from commit 12f8d21)
Signed-off-by: Eric Chanudet <[email protected]>
  • Loading branch information
Eric Chanudet committed Jul 25, 2019
1 parent 2684b2e commit 8f36aa7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
8 changes: 8 additions & 0 deletions plugins/drm/src/drm-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,18 @@ INTERNAL int drmp_get_monitors(surfman_plugin_t *plugin, surfman_monitor_t *moni
(void) plugin;
struct drm_device *d, *dd;
unsigned int j = 0;
int rc;

list_for_each_entry_safe(d, dd, &devices, l) {
struct drm_monitor *m, *mm;

rc = drm_monitors_scan(d);
if (rc < 0) {
DRM_WRN("Failed to scan for monitors on device %s (%s).",
d->devnode, strerror(-rc));
continue;
}

DRM_DBG("Device %s monitors:", d->devnode);
list_for_each_entry_safe(m, mm, &(d->monitors), l_dev) {
if (j >= size) {
Expand Down
19 changes: 6 additions & 13 deletions plugins/drm/src/hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,26 @@ static void hotplug_event_handler(int fd, short event, void *priv)
{
struct hotplug *hotplug = priv;
struct udev_device *dev;
struct drm_device *d, *dd;
const char *devnode;

(void) fd;
(void) event;

/* Notify surfman to rescan monitors.
* This will trigger a callback to the plugin on Surfman's terms. */
surfman_plugin.notify |= SURFMAN_NOTIFY_MONITOR_RESCAN;

dev = udev_monitor_receive_device(hotplug->monitor);
if (!dev) {
DRM_WRN("Could not recover the device which triggered this udev event (%s).",
strerror(errno));
return;
}

devnode = udev_device_get_devnode(dev);
DRM_DBG("%s: %s (%s) triggred `%s' event.", udev_device_get_subsystem(dev),
udev_device_get_sysname(dev), devnode, udev_device_get_action(dev));

/* TODO: Who knows... some cardX might appear, but we'll see that later. */
if (devnode) {
/* TODO: Those lists will require some sync mecanisms someday... */
list_for_each_entry_safe(d, dd, &devices, l) {
if (!strcmp(d->devnode, devnode)) {
drm_monitors_scan(d);
break;
}
}
}
udev_device_unref(dev);
surfman_plugin.notify |= SURFMAN_NOTIFY_MONITOR_RESCAN;
return;
}

Expand Down

0 comments on commit 8f36aa7

Please sign in to comment.