All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm] xf86drm: Add drmIsMaster()
@ 2018-11-20  3:36 Christopher James Halse Rogers
  2018-12-17 17:35 ` Emil Velikov
  2019-01-23  4:38 ` [PATCH v2] " Christopher James Halse Rogers
  0 siblings, 2 replies; 12+ messages in thread
From: Christopher James Halse Rogers @ 2018-11-20  3:36 UTC (permalink / raw)
  To: dri-devel; +Cc: Christopher James Halse Rogers

We can't use drmSetMaster to query whether or not a drm fd is master
because it requires CAP_SYS_ADMIN, even if the fd *is* a master fd.

Pick DRM_IOCTL_MODE_ATTACHMODE as a long-deprecated ioctl that is
DRM_MASTER but not DRM_ROOT_ONLY as the probe by which we can detect
whether or not the fd is master.

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
---
 xf86drm.c | 20 ++++++++++++++++++++
 xf86drm.h |  2 ++
 2 files changed, 22 insertions(+)

diff --git a/xf86drm.c b/xf86drm.c
index 10df682b..bdb0439d 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2741,6 +2741,26 @@ drm_public int drmDropMaster(int fd)
         return drmIoctl(fd, DRM_IOCTL_DROP_MASTER, NULL);
 }
 
+drm_public bool drmIsMaster(int fd)
+{
+    struct drm_mode_mode_cmd cmd;
+
+    memclear(cmd);
+    /* Set an invalid connector_id to ensure that ATTACHMODE errors with
+     * EINVAL in the unlikely event someone feels like calling this on a
+     * kernel prior to 3.9. */
+    cmd.connector_id = -1;
+
+    if (drmIoctl(fd, DRM_IOCTL_MODE_ATTACHMODE, &cmd) != -1)
+    {
+        /* On 3.9 ATTACHMODE was changed to drm_noop, and so will succeed
+	 * iff we've got a master fd */
+        return true;
+    }
+
+    return errno == EINVAL;
+}
+
 drm_public char *drmGetDeviceNameFromFd(int fd)
 {
     char name[128];
diff --git a/xf86drm.h b/xf86drm.h
index 7773d71a..9e920db9 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -37,6 +37,7 @@
 #include <stdarg.h>
 #include <sys/types.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <drm.h>
 
 #if defined(__cplusplus)
@@ -733,6 +734,7 @@ extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
 
 extern int drmSetMaster(int fd);
 extern int drmDropMaster(int fd);
+extern bool drmIsMaster(int fd);
 
 #define DRM_EVENT_CONTEXT_VERSION 4
 
-- 
2.19.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-02-19 20:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-20  3:36 [PATCH libdrm] xf86drm: Add drmIsMaster() Christopher James Halse Rogers
2018-12-17 17:35 ` Emil Velikov
2018-12-17 17:59   ` Daniel Vetter
2018-12-18  6:07   ` Christopher James Halse Rogers
2019-01-22  2:26     ` Christopher James Halse Rogers
2019-01-22  7:55       ` Daniel Vetter
2019-01-23  4:38 ` [PATCH v2] " Christopher James Halse Rogers
2019-01-23 11:00   ` Daniel Vetter
2019-01-23 17:18   ` Emil Velikov
2019-01-23 20:56     ` Christopher James Halse Rogers
2019-01-24  9:45       ` Daniel Vetter
2019-02-19 20:40         ` Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.