aboutsummaryrefslogtreecommitdiffstats
path: root/logind.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2019-04-08 09:59:15 +0200
committerGerd Hoffmann <kraxel@redhat.com>2019-04-08 09:59:15 +0200
commit6ae8ad4acf9252df2b7b043c78af401973c9bd6f (patch)
treec15f5ad563d66e300e9bebe268f413457678b652 /logind.c
parentb896696f8a2cbc7960cd5da59c917bb03d4e73af (diff)
downloaddrminfo-6ae8ad4acf9252df2b7b043c78af401973c9bd6f.tar.gz
add device_open helper
Diffstat (limited to 'logind.c')
-rw-r--r--logind.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/logind.c b/logind.c
index 9d80255..f6b4bc8 100644
--- a/logind.c
+++ b/logind.c
@@ -200,9 +200,34 @@ void logind_fini(void)
int logind_open(const char *path)
{
+ const char *session_id, *seat;
+
+ seat = getenv("XDG_SEAT");
+ session_id = getenv("XDG_SESSION_ID");
+ if (!seat || !session_id)
+ return -1;
+
fprintf(stderr, "%s(%s): compiled without logind support.\n",
__func__, path);
return -1;
}
#endif
+
+/* ---------------------------------------------------------------------- */
+
+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);
+ if (fd < 0) {
+ fprintf(stderr,"open %s: %s\n", device, strerror(saved_errno));
+ exit(1);
+ }
+ }
+ return fd;
+}