aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drmtools.c7
-rw-r--r--fbtools.c3
-rw-r--r--logind.c24
-rw-r--r--logind.h2
4 files changed, 32 insertions, 4 deletions
diff --git a/drmtools.c b/drmtools.c
index 84dbbeb..8fab4b5 100644
--- a/drmtools.c
+++ b/drmtools.c
@@ -14,6 +14,7 @@
#include "gfx.h"
#include "drmtools.h"
+#include "logind.h"
/* ------------------------------------------------------------------ */
@@ -88,7 +89,7 @@ int drm_init_dev(const char *dev, const char *output, const char *mode)
int i, rc;
/* open device */
- drm_fd = open(dev, O_RDWR | O_CLOEXEC);
+ drm_fd = device_open(dev);
if (drm_fd < 0) {
fprintf(stderr, "drm: open %s: %s\n", dev, strerror(errno));
return -1;
@@ -247,7 +248,7 @@ static void drm_suspend_display(void)
static void drm_resume_display(void)
{
- drm_fd = open(drm_dev, O_RDWR | O_CLOEXEC);
+ drm_fd = device_open(drm_dev);
drm_init_fb(&fb1, drm_fmt, false);
if (fb2.mem)
drm_init_fb(&fb2, drm_fmt, false);
@@ -333,7 +334,7 @@ void drm_info(const char *device)
} else {
snprintf(dev, sizeof(dev), DRM_DEV_NAME, DRM_DIR_NAME, 0);
}
- drm_fd = open(dev, O_RDWR | O_CLOEXEC);
+ drm_fd = device_open(dev);
if (drm_fd < 0) {
fprintf(stderr, "drm: open %s: %s\n", dev, strerror(errno));
return;
diff --git a/fbtools.c b/fbtools.c
index 3158d2e..6c2d52b 100644
--- a/fbtools.c
+++ b/fbtools.c
@@ -24,6 +24,7 @@
#include "vt.h"
#include "fbtools.h"
+#include "logind.h"
/* -------------------------------------------------------------------- */
/* internal variables */
@@ -225,7 +226,7 @@ gfxstate* fb_init(const char *device, char *mode)
fprintf(stderr, "trying fbdev: %s ...\n", device);
/* get current settings (which we have to restore) */
- if (-1 == (fb = open(device,O_RDWR | O_CLOEXEC))) {
+ if (-1 == (fb = device_open(device))) {
fprintf(stderr,"open %s: %s\n",device,strerror(errno));
exit(1);
}
diff --git a/logind.c b/logind.c
index 506da59..e3bef64 100644
--- a/logind.c
+++ b/logind.c
@@ -340,6 +340,9 @@ int logind_open(const char *path, int flags, void *user_data)
int inactive;
int handle, fd, r;
+ if (!logind_dbus)
+ return -1;
+
r = stat(path, &st);
if (r < 0) {
fprintf(stderr, "stat %s failed: %s\n", path, strerror(errno));
@@ -396,6 +399,9 @@ void logind_close(int fd, void *user_data)
unsigned int maj, min;
int r;
+ if (!logind_dbus)
+ return;
+
r = fstat(fd, &st);
if (r < 0) {
fprintf(stderr, "fstat failed: %s\n", strerror(errno));
@@ -482,3 +488,21 @@ const struct libinput_interface libinput_if_logind = {
.open_restricted = logind_open,
.close_restricted = logind_close,
};
+
+int device_open(const char *device)
+{
+ int saved_errno, fd;
+
+ fd = open(device, O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ saved_errno = errno;
+ fd = logind_open(device, 0, NULL);
+ if (fd < 0) {
+ errno = saved_errno;
+ return -1;
+ } else {
+ fprintf(stderr, "%s: got handle from logind\n", device);
+ }
+ }
+ return fd;
+}
diff --git a/logind.h b/logind.h
index d7300da..5c97702 100644
--- a/logind.h
+++ b/logind.h
@@ -16,3 +16,5 @@ int logind_take_control(void);
int logind_release_control(void);
int logind_open(const char *path, int flags, void *user_data);
void logind_close(int fd, void *user_data);
+
+int device_open(const char *device);