diff options
-rw-r--r-- | drmtools.c | 7 | ||||
-rw-r--r-- | fbtools.c | 3 | ||||
-rw-r--r-- | logind.c | 24 | ||||
-rw-r--r-- | logind.h | 2 |
4 files changed, 32 insertions, 4 deletions
@@ -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; @@ -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); } @@ -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; +} @@ -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); |